]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.13.0-201401272348.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.0-201401272348.patch
CommitLineData
107d09e2
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..31509cb 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+randstruct.seed
177+randstruct.hashed_seed
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 b9e9bd8..bf49b92 100644
239--- a/Documentation/kernel-parameters.txt
240+++ b/Documentation/kernel-parameters.txt
241@@ -1033,6 +1033,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@@ -2018,6 +2022,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@@ -2285,6 +2293,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 b8b7f74..1f3d7c8 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 -fno-delete-null-pointer-checks
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305@@ -417,8 +418,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@@ -579,6 +580,76 @@ 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+GRKERNSEC_RANDSTRUCT_SEED := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gen-random-seed.sh)
344+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
345+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-seed=$(GRKERNSEC_RANDSTRUCT_SEED)
346+RANDSTRUCT_HASHED_SEED := $(shell cat "$(srctree)/tools/gcc/randstruct.hashed_seed")
347+RANDSTRUCT_PLUGIN_CFLAGS += -DRANDSTRUCT_HASHED_SEED="\"$(RANDSTRUCT_HASHED_SEED)\""
348+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
349+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
350+endif
351+endif
352+ifdef CONFIG_CHECKER_PLUGIN
353+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
354+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
355+endif
356+endif
357+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
358+ifdef CONFIG_PAX_SIZE_OVERFLOW
359+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
360+endif
361+ifdef CONFIG_PAX_LATENT_ENTROPY
362+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
363+endif
364+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
365+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
366+endif
367+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
368+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
369+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
370+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
371+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
372+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
373+ifeq ($(KBUILD_EXTMOD),)
374+gcc-plugins:
375+ $(Q)$(MAKE) $(build)=tools/gcc
376+else
377+gcc-plugins: ;
378+endif
379+else
380+gcc-plugins:
381+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
382+ $(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.))
383+else
384+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
385+endif
386+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
387+endif
388+endif
389+
390 include $(srctree)/arch/$(SRCARCH)/Makefile
391
392 ifdef CONFIG_READABLE_ASM
393@@ -754,7 +825,7 @@ export mod_sign_cmd
394
395
396 ifeq ($(KBUILD_EXTMOD),)
397-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
398+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
399
400 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
401 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
402@@ -803,6 +874,8 @@ endif
403
404 # The actual objects are generated when descending,
405 # make sure no implicit rule kicks in
406+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
407+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
408 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
409
410 # Handle descending into subdirectories listed in $(vmlinux-dirs)
411@@ -812,7 +885,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
412 # Error messages still appears in the original language
413
414 PHONY += $(vmlinux-dirs)
415-$(vmlinux-dirs): prepare scripts
416+$(vmlinux-dirs): gcc-plugins prepare scripts
417 $(Q)$(MAKE) $(build)=$@
418
419 define filechk_kernel.release
420@@ -855,10 +928,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
421
422 archprepare: archheaders archscripts prepare1 scripts_basic
423
424+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
425+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
426 prepare0: archprepare FORCE
427 $(Q)$(MAKE) $(build)=.
428
429 # All the preparing..
430+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
431 prepare: prepare0
432
433 # Generate some files
434@@ -966,6 +1042,8 @@ all: modules
435 # using awk while concatenating to the final file.
436
437 PHONY += modules
438+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
439+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
440 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
441 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
442 @$(kecho) ' Building modules, stage 2.';
443@@ -981,7 +1059,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
444
445 # Target to prepare building external modules
446 PHONY += modules_prepare
447-modules_prepare: prepare scripts
448+modules_prepare: gcc-plugins prepare scripts
449
450 # Target to install modules
451 PHONY += modules_install
452@@ -1047,7 +1125,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
453 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
454 signing_key.priv signing_key.x509 x509.genkey \
455 extra_certificates signing_key.x509.keyid \
456- signing_key.x509.signer
457+ signing_key.x509.signer tools/gcc/size_overflow_hash.h \
458+ tools/gcc/randstruct.seed tools/gcc/randstruct.hashed_seed
459
460 # clean - Delete most, but leave enough to build external modules
461 #
462@@ -1087,6 +1166,7 @@ distclean: mrproper
463 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
464 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
465 -o -name '.*.rej' \
466+ -o -name '.*.rej' -o -name '*.so' \
467 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
468 -type f -print | xargs rm -f
469
470@@ -1248,6 +1328,8 @@ PHONY += $(module-dirs) modules
471 $(module-dirs): crmodverdir $(objtree)/Module.symvers
472 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
473
474+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
475+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
476 modules: $(module-dirs)
477 @$(kecho) ' Building modules, stage 2.';
478 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
479@@ -1387,17 +1469,21 @@ else
480 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
481 endif
482
483-%.s: %.c prepare scripts FORCE
484+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
485+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
486+%.s: %.c gcc-plugins prepare scripts FORCE
487 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
488 %.i: %.c prepare scripts FORCE
489 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
490-%.o: %.c prepare scripts FORCE
491+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
492+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
493+%.o: %.c gcc-plugins prepare scripts FORCE
494 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
495 %.lst: %.c prepare scripts FORCE
496 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
497-%.s: %.S prepare scripts FORCE
498+%.s: %.S gcc-plugins prepare scripts FORCE
499 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
500-%.o: %.S prepare scripts FORCE
501+%.o: %.S gcc-plugins prepare scripts FORCE
502 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
503 %.symtypes: %.c prepare scripts FORCE
504 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
505@@ -1407,11 +1493,15 @@ endif
506 $(cmd_crmodverdir)
507 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
508 $(build)=$(build-dir)
509-%/: prepare scripts FORCE
510+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
511+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
512+%/: gcc-plugins prepare scripts FORCE
513 $(cmd_crmodverdir)
514 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
515 $(build)=$(build-dir)
516-%.ko: prepare scripts FORCE
517+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
518+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
519+%.ko: gcc-plugins prepare scripts FORCE
520 $(cmd_crmodverdir)
521 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
522 $(build)=$(build-dir) $(@:.ko=.o)
523diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
524index 78b03ef..da28a51 100644
525--- a/arch/alpha/include/asm/atomic.h
526+++ b/arch/alpha/include/asm/atomic.h
527@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
528 #define atomic_dec(v) atomic_sub(1,(v))
529 #define atomic64_dec(v) atomic64_sub(1,(v))
530
531+#define atomic64_read_unchecked(v) atomic64_read(v)
532+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
533+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
534+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
535+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
536+#define atomic64_inc_unchecked(v) atomic64_inc(v)
537+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
538+#define atomic64_dec_unchecked(v) atomic64_dec(v)
539+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
540+
541 #define smp_mb__before_atomic_dec() smp_mb()
542 #define smp_mb__after_atomic_dec() smp_mb()
543 #define smp_mb__before_atomic_inc() smp_mb()
544diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
545index ad368a9..fbe0f25 100644
546--- a/arch/alpha/include/asm/cache.h
547+++ b/arch/alpha/include/asm/cache.h
548@@ -4,19 +4,19 @@
549 #ifndef __ARCH_ALPHA_CACHE_H
550 #define __ARCH_ALPHA_CACHE_H
551
552+#include <linux/const.h>
553
554 /* Bytes per L1 (data) cache line. */
555 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
556-# define L1_CACHE_BYTES 64
557 # define L1_CACHE_SHIFT 6
558 #else
559 /* Both EV4 and EV5 are write-through, read-allocate,
560 direct-mapped, physical.
561 */
562-# define L1_CACHE_BYTES 32
563 # define L1_CACHE_SHIFT 5
564 #endif
565
566+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
567 #define SMP_CACHE_BYTES L1_CACHE_BYTES
568
569 #endif
570diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
571index 968d999..d36b2df 100644
572--- a/arch/alpha/include/asm/elf.h
573+++ b/arch/alpha/include/asm/elf.h
574@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
575
576 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
577
578+#ifdef CONFIG_PAX_ASLR
579+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
580+
581+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
582+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
583+#endif
584+
585 /* $0 is set by ld.so to a pointer to a function which might be
586 registered using atexit. This provides a mean for the dynamic
587 linker to call DT_FINI functions for shared libraries that have
588diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
589index aab14a0..b4fa3e7 100644
590--- a/arch/alpha/include/asm/pgalloc.h
591+++ b/arch/alpha/include/asm/pgalloc.h
592@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
593 pgd_set(pgd, pmd);
594 }
595
596+static inline void
597+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
598+{
599+ pgd_populate(mm, pgd, pmd);
600+}
601+
602 extern pgd_t *pgd_alloc(struct mm_struct *mm);
603
604 static inline void
605diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
606index d8f9b7e..f6222fa 100644
607--- a/arch/alpha/include/asm/pgtable.h
608+++ b/arch/alpha/include/asm/pgtable.h
609@@ -102,6 +102,17 @@ struct vm_area_struct;
610 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
611 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
612 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
613+
614+#ifdef CONFIG_PAX_PAGEEXEC
615+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
616+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
617+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
618+#else
619+# define PAGE_SHARED_NOEXEC PAGE_SHARED
620+# define PAGE_COPY_NOEXEC PAGE_COPY
621+# define PAGE_READONLY_NOEXEC PAGE_READONLY
622+#endif
623+
624 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
625
626 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
627diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
628index 2fd00b7..cfd5069 100644
629--- a/arch/alpha/kernel/module.c
630+++ b/arch/alpha/kernel/module.c
631@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
632
633 /* The small sections were sorted to the end of the segment.
634 The following should definitely cover them. */
635- gp = (u64)me->module_core + me->core_size - 0x8000;
636+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
637 got = sechdrs[me->arch.gotsecindex].sh_addr;
638
639 for (i = 0; i < n; i++) {
640diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
641index 1402fcc..0b1abd2 100644
642--- a/arch/alpha/kernel/osf_sys.c
643+++ b/arch/alpha/kernel/osf_sys.c
644@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
645 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
646
647 static unsigned long
648-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
649- unsigned long limit)
650+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
651+ unsigned long limit, unsigned long flags)
652 {
653 struct vm_unmapped_area_info info;
654+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
655
656 info.flags = 0;
657 info.length = len;
658@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
659 info.high_limit = limit;
660 info.align_mask = 0;
661 info.align_offset = 0;
662+ info.threadstack_offset = offset;
663 return vm_unmapped_area(&info);
664 }
665
666@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
667 merely specific addresses, but regions of memory -- perhaps
668 this feature should be incorporated into all ports? */
669
670+#ifdef CONFIG_PAX_RANDMMAP
671+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
672+#endif
673+
674 if (addr) {
675- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
676+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
677 if (addr != (unsigned long) -ENOMEM)
678 return addr;
679 }
680
681 /* Next, try allocating at TASK_UNMAPPED_BASE. */
682- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
683- len, limit);
684+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
685+
686 if (addr != (unsigned long) -ENOMEM)
687 return addr;
688
689 /* Finally, try allocating in low memory. */
690- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
691+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
692
693 return addr;
694 }
695diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
696index 98838a0..b304fb4 100644
697--- a/arch/alpha/mm/fault.c
698+++ b/arch/alpha/mm/fault.c
699@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
700 __reload_thread(pcb);
701 }
702
703+#ifdef CONFIG_PAX_PAGEEXEC
704+/*
705+ * PaX: decide what to do with offenders (regs->pc = fault address)
706+ *
707+ * returns 1 when task should be killed
708+ * 2 when patched PLT trampoline was detected
709+ * 3 when unpatched PLT trampoline was detected
710+ */
711+static int pax_handle_fetch_fault(struct pt_regs *regs)
712+{
713+
714+#ifdef CONFIG_PAX_EMUPLT
715+ int err;
716+
717+ do { /* PaX: patched PLT emulation #1 */
718+ unsigned int ldah, ldq, jmp;
719+
720+ err = get_user(ldah, (unsigned int *)regs->pc);
721+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
722+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
723+
724+ if (err)
725+ break;
726+
727+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
728+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
729+ jmp == 0x6BFB0000U)
730+ {
731+ unsigned long r27, addr;
732+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
733+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
734+
735+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
736+ err = get_user(r27, (unsigned long *)addr);
737+ if (err)
738+ break;
739+
740+ regs->r27 = r27;
741+ regs->pc = r27;
742+ return 2;
743+ }
744+ } while (0);
745+
746+ do { /* PaX: patched PLT emulation #2 */
747+ unsigned int ldah, lda, br;
748+
749+ err = get_user(ldah, (unsigned int *)regs->pc);
750+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
751+ err |= get_user(br, (unsigned int *)(regs->pc+8));
752+
753+ if (err)
754+ break;
755+
756+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
757+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
758+ (br & 0xFFE00000U) == 0xC3E00000U)
759+ {
760+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
761+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
762+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
763+
764+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
765+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
766+ return 2;
767+ }
768+ } while (0);
769+
770+ do { /* PaX: unpatched PLT emulation */
771+ unsigned int br;
772+
773+ err = get_user(br, (unsigned int *)regs->pc);
774+
775+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
776+ unsigned int br2, ldq, nop, jmp;
777+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
778+
779+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
780+ err = get_user(br2, (unsigned int *)addr);
781+ err |= get_user(ldq, (unsigned int *)(addr+4));
782+ err |= get_user(nop, (unsigned int *)(addr+8));
783+ err |= get_user(jmp, (unsigned int *)(addr+12));
784+ err |= get_user(resolver, (unsigned long *)(addr+16));
785+
786+ if (err)
787+ break;
788+
789+ if (br2 == 0xC3600000U &&
790+ ldq == 0xA77B000CU &&
791+ nop == 0x47FF041FU &&
792+ jmp == 0x6B7B0000U)
793+ {
794+ regs->r28 = regs->pc+4;
795+ regs->r27 = addr+16;
796+ regs->pc = resolver;
797+ return 3;
798+ }
799+ }
800+ } while (0);
801+#endif
802+
803+ return 1;
804+}
805+
806+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
807+{
808+ unsigned long i;
809+
810+ printk(KERN_ERR "PAX: bytes at PC: ");
811+ for (i = 0; i < 5; i++) {
812+ unsigned int c;
813+ if (get_user(c, (unsigned int *)pc+i))
814+ printk(KERN_CONT "???????? ");
815+ else
816+ printk(KERN_CONT "%08x ", c);
817+ }
818+ printk("\n");
819+}
820+#endif
821
822 /*
823 * This routine handles page faults. It determines the address,
824@@ -133,8 +251,29 @@ retry:
825 good_area:
826 si_code = SEGV_ACCERR;
827 if (cause < 0) {
828- if (!(vma->vm_flags & VM_EXEC))
829+ if (!(vma->vm_flags & VM_EXEC)) {
830+
831+#ifdef CONFIG_PAX_PAGEEXEC
832+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
833+ goto bad_area;
834+
835+ up_read(&mm->mmap_sem);
836+ switch (pax_handle_fetch_fault(regs)) {
837+
838+#ifdef CONFIG_PAX_EMUPLT
839+ case 2:
840+ case 3:
841+ return;
842+#endif
843+
844+ }
845+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
846+ do_group_exit(SIGKILL);
847+#else
848 goto bad_area;
849+#endif
850+
851+ }
852 } else if (!cause) {
853 /* Allow reads even for write-only mappings */
854 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
855diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
856index c1f1a7e..554b0cd 100644
857--- a/arch/arm/Kconfig
858+++ b/arch/arm/Kconfig
859@@ -1828,7 +1828,7 @@ config ALIGNMENT_TRAP
860
861 config UACCESS_WITH_MEMCPY
862 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
863- depends on MMU
864+ depends on MMU && !PAX_MEMORY_UDEREF
865 default y if CPU_FEROCEON
866 help
867 Implement faster copy_to_user and clear_user methods for CPU
868@@ -2100,6 +2100,7 @@ config XIP_PHYS_ADDR
869 config KEXEC
870 bool "Kexec system call (EXPERIMENTAL)"
871 depends on (!SMP || PM_SLEEP_SMP)
872+ depends on !GRKERNSEC_KMEM
873 help
874 kexec is a system call that implements the ability to shutdown your
875 current kernel, and to start another kernel. It is like a reboot
876diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
877index 62d2cb5..7a13651 100644
878--- a/arch/arm/include/asm/atomic.h
879+++ b/arch/arm/include/asm/atomic.h
880@@ -18,17 +18,35 @@
881 #include <asm/barrier.h>
882 #include <asm/cmpxchg.h>
883
884+#ifdef CONFIG_GENERIC_ATOMIC64
885+#include <asm-generic/atomic64.h>
886+#endif
887+
888 #define ATOMIC_INIT(i) { (i) }
889
890 #ifdef __KERNEL__
891
892+#define _ASM_EXTABLE(from, to) \
893+" .pushsection __ex_table,\"a\"\n"\
894+" .align 3\n" \
895+" .long " #from ", " #to"\n" \
896+" .popsection"
897+
898 /*
899 * On ARM, ordinary assignment (str instruction) doesn't clear the local
900 * strex/ldrex monitor on some implementations. The reason we can use it for
901 * atomic_set() is the clrex or dummy strex done on every exception return.
902 */
903 #define atomic_read(v) (*(volatile int *)&(v)->counter)
904+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
905+{
906+ return v->counter;
907+}
908 #define atomic_set(v,i) (((v)->counter) = (i))
909+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
910+{
911+ v->counter = i;
912+}
913
914 #if __LINUX_ARM_ARCH__ >= 6
915
916@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
917
918 prefetchw(&v->counter);
919 __asm__ __volatile__("@ atomic_add\n"
920+"1: ldrex %1, [%3]\n"
921+" adds %0, %1, %4\n"
922+
923+#ifdef CONFIG_PAX_REFCOUNT
924+" bvc 3f\n"
925+"2: bkpt 0xf103\n"
926+"3:\n"
927+#endif
928+
929+" strex %1, %0, [%3]\n"
930+" teq %1, #0\n"
931+" bne 1b"
932+
933+#ifdef CONFIG_PAX_REFCOUNT
934+"\n4:\n"
935+ _ASM_EXTABLE(2b, 4b)
936+#endif
937+
938+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
939+ : "r" (&v->counter), "Ir" (i)
940+ : "cc");
941+}
942+
943+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
944+{
945+ unsigned long tmp;
946+ int result;
947+
948+ prefetchw(&v->counter);
949+ __asm__ __volatile__("@ atomic_add_unchecked\n"
950 "1: ldrex %0, [%3]\n"
951 " add %0, %0, %4\n"
952 " strex %1, %0, [%3]\n"
953@@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
954 smp_mb();
955
956 __asm__ __volatile__("@ atomic_add_return\n"
957+"1: ldrex %1, [%3]\n"
958+" adds %0, %1, %4\n"
959+
960+#ifdef CONFIG_PAX_REFCOUNT
961+" bvc 3f\n"
962+" mov %0, %1\n"
963+"2: bkpt 0xf103\n"
964+"3:\n"
965+#endif
966+
967+" strex %1, %0, [%3]\n"
968+" teq %1, #0\n"
969+" bne 1b"
970+
971+#ifdef CONFIG_PAX_REFCOUNT
972+"\n4:\n"
973+ _ASM_EXTABLE(2b, 4b)
974+#endif
975+
976+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
977+ : "r" (&v->counter), "Ir" (i)
978+ : "cc");
979+
980+ smp_mb();
981+
982+ return result;
983+}
984+
985+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
986+{
987+ unsigned long tmp;
988+ int result;
989+
990+ smp_mb();
991+
992+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
993 "1: ldrex %0, [%3]\n"
994 " add %0, %0, %4\n"
995 " strex %1, %0, [%3]\n"
996@@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
997
998 prefetchw(&v->counter);
999 __asm__ __volatile__("@ atomic_sub\n"
1000+"1: ldrex %1, [%3]\n"
1001+" subs %0, %1, %4\n"
1002+
1003+#ifdef CONFIG_PAX_REFCOUNT
1004+" bvc 3f\n"
1005+"2: bkpt 0xf103\n"
1006+"3:\n"
1007+#endif
1008+
1009+" strex %1, %0, [%3]\n"
1010+" teq %1, #0\n"
1011+" bne 1b"
1012+
1013+#ifdef CONFIG_PAX_REFCOUNT
1014+"\n4:\n"
1015+ _ASM_EXTABLE(2b, 4b)
1016+#endif
1017+
1018+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1019+ : "r" (&v->counter), "Ir" (i)
1020+ : "cc");
1021+}
1022+
1023+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1024+{
1025+ unsigned long tmp;
1026+ int result;
1027+
1028+ prefetchw(&v->counter);
1029+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1030 "1: ldrex %0, [%3]\n"
1031 " sub %0, %0, %4\n"
1032 " strex %1, %0, [%3]\n"
1033@@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1034 smp_mb();
1035
1036 __asm__ __volatile__("@ atomic_sub_return\n"
1037-"1: ldrex %0, [%3]\n"
1038-" sub %0, %0, %4\n"
1039+"1: ldrex %1, [%3]\n"
1040+" subs %0, %1, %4\n"
1041+
1042+#ifdef CONFIG_PAX_REFCOUNT
1043+" bvc 3f\n"
1044+" mov %0, %1\n"
1045+"2: bkpt 0xf103\n"
1046+"3:\n"
1047+#endif
1048+
1049 " strex %1, %0, [%3]\n"
1050 " teq %1, #0\n"
1051 " bne 1b"
1052+
1053+#ifdef CONFIG_PAX_REFCOUNT
1054+"\n4:\n"
1055+ _ASM_EXTABLE(2b, 4b)
1056+#endif
1057+
1058 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1059 : "r" (&v->counter), "Ir" (i)
1060 : "cc");
1061@@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1062 return oldval;
1063 }
1064
1065+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1066+{
1067+ unsigned long oldval, res;
1068+
1069+ smp_mb();
1070+
1071+ do {
1072+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1073+ "ldrex %1, [%3]\n"
1074+ "mov %0, #0\n"
1075+ "teq %1, %4\n"
1076+ "strexeq %0, %5, [%3]\n"
1077+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1078+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1079+ : "cc");
1080+ } while (res);
1081+
1082+ smp_mb();
1083+
1084+ return oldval;
1085+}
1086+
1087 #else /* ARM_ARCH_6 */
1088
1089 #ifdef CONFIG_SMP
1090@@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1091
1092 return val;
1093 }
1094+
1095+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1096+{
1097+ return atomic_add_return(i, v);
1098+}
1099+
1100 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1101+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1102+{
1103+ (void) atomic_add_return(i, v);
1104+}
1105
1106 static inline int atomic_sub_return(int i, atomic_t *v)
1107 {
1108@@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1109 return val;
1110 }
1111 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1112+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1113+{
1114+ (void) atomic_sub_return(i, v);
1115+}
1116
1117 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1118 {
1119@@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1120 return ret;
1121 }
1122
1123+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1124+{
1125+ return atomic_cmpxchg(v, old, new);
1126+}
1127+
1128 #endif /* __LINUX_ARM_ARCH__ */
1129
1130 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1131+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1132+{
1133+ return xchg(&v->counter, new);
1134+}
1135
1136 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1137 {
1138@@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1139 }
1140
1141 #define atomic_inc(v) atomic_add(1, v)
1142+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1143+{
1144+ atomic_add_unchecked(1, v);
1145+}
1146 #define atomic_dec(v) atomic_sub(1, v)
1147+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1148+{
1149+ atomic_sub_unchecked(1, v);
1150+}
1151
1152 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1153+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1154+{
1155+ return atomic_add_return_unchecked(1, v) == 0;
1156+}
1157 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1158 #define atomic_inc_return(v) (atomic_add_return(1, v))
1159+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1160+{
1161+ return atomic_add_return_unchecked(1, v);
1162+}
1163 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1164 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1165
1166@@ -221,6 +410,14 @@ typedef struct {
1167 long long counter;
1168 } atomic64_t;
1169
1170+#ifdef CONFIG_PAX_REFCOUNT
1171+typedef struct {
1172+ long long counter;
1173+} atomic64_unchecked_t;
1174+#else
1175+typedef atomic64_t atomic64_unchecked_t;
1176+#endif
1177+
1178 #define ATOMIC64_INIT(i) { (i) }
1179
1180 #ifdef CONFIG_ARM_LPAE
1181@@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1182 return result;
1183 }
1184
1185+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1186+{
1187+ long long result;
1188+
1189+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1190+" ldrd %0, %H0, [%1]"
1191+ : "=&r" (result)
1192+ : "r" (&v->counter), "Qo" (v->counter)
1193+ );
1194+
1195+ return result;
1196+}
1197+
1198 static inline void atomic64_set(atomic64_t *v, long long i)
1199 {
1200 __asm__ __volatile__("@ atomic64_set\n"
1201@@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1202 : "r" (&v->counter), "r" (i)
1203 );
1204 }
1205+
1206+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1207+{
1208+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1209+" strd %2, %H2, [%1]"
1210+ : "=Qo" (v->counter)
1211+ : "r" (&v->counter), "r" (i)
1212+ );
1213+}
1214 #else
1215 static inline long long atomic64_read(const atomic64_t *v)
1216 {
1217@@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1218 return result;
1219 }
1220
1221+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1222+{
1223+ long long result;
1224+
1225+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1226+" ldrexd %0, %H0, [%1]"
1227+ : "=&r" (result)
1228+ : "r" (&v->counter), "Qo" (v->counter)
1229+ );
1230+
1231+ return result;
1232+}
1233+
1234 static inline void atomic64_set(atomic64_t *v, long long i)
1235 {
1236 long long tmp;
1237@@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1238 : "r" (&v->counter), "r" (i)
1239 : "cc");
1240 }
1241+
1242+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1243+{
1244+ long long tmp;
1245+
1246+ prefetchw(&v->counter);
1247+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1248+"1: ldrexd %0, %H0, [%2]\n"
1249+" strexd %0, %3, %H3, [%2]\n"
1250+" teq %0, #0\n"
1251+" bne 1b"
1252+ : "=&r" (tmp), "=Qo" (v->counter)
1253+ : "r" (&v->counter), "r" (i)
1254+ : "cc");
1255+}
1256 #endif
1257
1258 static inline void atomic64_add(long long i, atomic64_t *v)
1259@@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1260 __asm__ __volatile__("@ atomic64_add\n"
1261 "1: ldrexd %0, %H0, [%3]\n"
1262 " adds %Q0, %Q0, %Q4\n"
1263+" adcs %R0, %R0, %R4\n"
1264+
1265+#ifdef CONFIG_PAX_REFCOUNT
1266+" bvc 3f\n"
1267+"2: bkpt 0xf103\n"
1268+"3:\n"
1269+#endif
1270+
1271+" strexd %1, %0, %H0, [%3]\n"
1272+" teq %1, #0\n"
1273+" bne 1b"
1274+
1275+#ifdef CONFIG_PAX_REFCOUNT
1276+"\n4:\n"
1277+ _ASM_EXTABLE(2b, 4b)
1278+#endif
1279+
1280+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1281+ : "r" (&v->counter), "r" (i)
1282+ : "cc");
1283+}
1284+
1285+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1286+{
1287+ long long result;
1288+ unsigned long tmp;
1289+
1290+ prefetchw(&v->counter);
1291+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1292+"1: ldrexd %0, %H0, [%3]\n"
1293+" adds %Q0, %Q0, %Q4\n"
1294 " adc %R0, %R0, %R4\n"
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297@@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1298 __asm__ __volatile__("@ atomic64_add_return\n"
1299 "1: ldrexd %0, %H0, [%3]\n"
1300 " adds %Q0, %Q0, %Q4\n"
1301+" adcs %R0, %R0, %R4\n"
1302+
1303+#ifdef CONFIG_PAX_REFCOUNT
1304+" bvc 3f\n"
1305+" mov %0, %1\n"
1306+" mov %H0, %H1\n"
1307+"2: bkpt 0xf103\n"
1308+"3:\n"
1309+#endif
1310+
1311+" strexd %1, %0, %H0, [%3]\n"
1312+" teq %1, #0\n"
1313+" bne 1b"
1314+
1315+#ifdef CONFIG_PAX_REFCOUNT
1316+"\n4:\n"
1317+ _ASM_EXTABLE(2b, 4b)
1318+#endif
1319+
1320+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1321+ : "r" (&v->counter), "r" (i)
1322+ : "cc");
1323+
1324+ smp_mb();
1325+
1326+ return result;
1327+}
1328+
1329+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1330+{
1331+ long long result;
1332+ unsigned long tmp;
1333+
1334+ smp_mb();
1335+
1336+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1337+"1: ldrexd %0, %H0, [%3]\n"
1338+" adds %Q0, %Q0, %Q4\n"
1339 " adc %R0, %R0, %R4\n"
1340 " strexd %1, %0, %H0, [%3]\n"
1341 " teq %1, #0\n"
1342@@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1343 __asm__ __volatile__("@ atomic64_sub\n"
1344 "1: ldrexd %0, %H0, [%3]\n"
1345 " subs %Q0, %Q0, %Q4\n"
1346+" sbcs %R0, %R0, %R4\n"
1347+
1348+#ifdef CONFIG_PAX_REFCOUNT
1349+" bvc 3f\n"
1350+"2: bkpt 0xf103\n"
1351+"3:\n"
1352+#endif
1353+
1354+" strexd %1, %0, %H0, [%3]\n"
1355+" teq %1, #0\n"
1356+" bne 1b"
1357+
1358+#ifdef CONFIG_PAX_REFCOUNT
1359+"\n4:\n"
1360+ _ASM_EXTABLE(2b, 4b)
1361+#endif
1362+
1363+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1364+ : "r" (&v->counter), "r" (i)
1365+ : "cc");
1366+}
1367+
1368+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1369+{
1370+ long long result;
1371+ unsigned long tmp;
1372+
1373+ prefetchw(&v->counter);
1374+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1375+"1: ldrexd %0, %H0, [%3]\n"
1376+" subs %Q0, %Q0, %Q4\n"
1377 " sbc %R0, %R0, %R4\n"
1378 " strexd %1, %0, %H0, [%3]\n"
1379 " teq %1, #0\n"
1380@@ -344,17 +691,28 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1381 __asm__ __volatile__("@ atomic64_sub_return\n"
1382 "1: ldrexd %0, %H0, [%3]\n"
1383 " subs %Q0, %Q0, %Q4\n"
1384-" sbc %R0, %R0, %R4\n"
1385+" sbcs %R0, %R0, %R4\n"
1386+
1387+#ifdef CONFIG_PAX_REFCOUNT
1388+" bvc 3f\n"
1389+" mov %0, %1\n"
1390+" mov %H0, %H1\n"
1391+"2: bkpt 0xf103\n"
1392+"3:\n"
1393+#endif
1394+
1395 " strexd %1, %0, %H0, [%3]\n"
1396 " teq %1, #0\n"
1397 " bne 1b"
1398+
1399+#ifdef CONFIG_PAX_REFCOUNT
1400+"\n4:\n"
1401+ _ASM_EXTABLE(2b, 4b)
1402+#endif
1403+
1404 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1405 : "r" (&v->counter), "r" (i)
1406 : "cc");
1407-
1408- smp_mb();
1409-
1410- return result;
1411 }
1412
1413 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1414@@ -382,6 +740,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1415 return oldval;
1416 }
1417
1418+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1419+ long long new)
1420+{
1421+ long long oldval;
1422+ unsigned long res;
1423+
1424+ smp_mb();
1425+
1426+ do {
1427+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1428+ "ldrexd %1, %H1, [%3]\n"
1429+ "mov %0, #0\n"
1430+ "teq %1, %4\n"
1431+ "teqeq %H1, %H4\n"
1432+ "strexdeq %0, %5, %H5, [%3]"
1433+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1434+ : "r" (&ptr->counter), "r" (old), "r" (new)
1435+ : "cc");
1436+ } while (res);
1437+
1438+ smp_mb();
1439+
1440+ return oldval;
1441+}
1442+
1443 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1444 {
1445 long long result;
1446@@ -406,20 +789,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1447 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1448 {
1449 long long result;
1450- unsigned long tmp;
1451+ u64 tmp;
1452
1453 smp_mb();
1454
1455 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1456-"1: ldrexd %0, %H0, [%3]\n"
1457-" subs %Q0, %Q0, #1\n"
1458-" sbc %R0, %R0, #0\n"
1459+"1: ldrexd %1, %H1, [%3]\n"
1460+" subs %Q0, %Q1, #1\n"
1461+" sbcs %R0, %R1, #0\n"
1462+
1463+#ifdef CONFIG_PAX_REFCOUNT
1464+" bvc 3f\n"
1465+" mov %Q0, %Q1\n"
1466+" mov %R0, %R1\n"
1467+"2: bkpt 0xf103\n"
1468+"3:\n"
1469+#endif
1470+
1471 " teq %R0, #0\n"
1472-" bmi 2f\n"
1473+" bmi 4f\n"
1474 " strexd %1, %0, %H0, [%3]\n"
1475 " teq %1, #0\n"
1476 " bne 1b\n"
1477-"2:"
1478+"4:\n"
1479+
1480+#ifdef CONFIG_PAX_REFCOUNT
1481+ _ASM_EXTABLE(2b, 4b)
1482+#endif
1483+
1484 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1485 : "r" (&v->counter)
1486 : "cc");
1487@@ -442,13 +839,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1488 " teq %0, %5\n"
1489 " teqeq %H0, %H5\n"
1490 " moveq %1, #0\n"
1491-" beq 2f\n"
1492+" beq 4f\n"
1493 " adds %Q0, %Q0, %Q6\n"
1494-" adc %R0, %R0, %R6\n"
1495+" adcs %R0, %R0, %R6\n"
1496+
1497+#ifdef CONFIG_PAX_REFCOUNT
1498+" bvc 3f\n"
1499+"2: bkpt 0xf103\n"
1500+"3:\n"
1501+#endif
1502+
1503 " strexd %2, %0, %H0, [%4]\n"
1504 " teq %2, #0\n"
1505 " bne 1b\n"
1506-"2:"
1507+"4:\n"
1508+
1509+#ifdef CONFIG_PAX_REFCOUNT
1510+ _ASM_EXTABLE(2b, 4b)
1511+#endif
1512+
1513 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1514 : "r" (&v->counter), "r" (u), "r" (a)
1515 : "cc");
1516@@ -461,10 +870,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1517
1518 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1519 #define atomic64_inc(v) atomic64_add(1LL, (v))
1520+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1521 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1522+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1523 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1524 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1525 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1526+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1527 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1528 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1529 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1530diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1531index 75fe66b..ba3dee4 100644
1532--- a/arch/arm/include/asm/cache.h
1533+++ b/arch/arm/include/asm/cache.h
1534@@ -4,8 +4,10 @@
1535 #ifndef __ASMARM_CACHE_H
1536 #define __ASMARM_CACHE_H
1537
1538+#include <linux/const.h>
1539+
1540 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1541-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1543
1544 /*
1545 * Memory returned by kmalloc() may be used for DMA, so we must make
1546@@ -24,5 +26,6 @@
1547 #endif
1548
1549 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1550+#define __read_only __attribute__ ((__section__(".data..read_only")))
1551
1552 #endif
1553diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1554index ee753f1..c9c30a5 100644
1555--- a/arch/arm/include/asm/cacheflush.h
1556+++ b/arch/arm/include/asm/cacheflush.h
1557@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1558 void (*dma_unmap_area)(const void *, size_t, int);
1559
1560 void (*dma_flush_range)(const void *, const void *);
1561-};
1562+} __no_const;
1563
1564 /*
1565 * Select the calling method
1566diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1567index 6dcc164..b14d917 100644
1568--- a/arch/arm/include/asm/checksum.h
1569+++ b/arch/arm/include/asm/checksum.h
1570@@ -37,7 +37,19 @@ __wsum
1571 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1572
1573 __wsum
1574-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1575+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1576+
1577+static inline __wsum
1578+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1579+{
1580+ __wsum ret;
1581+ pax_open_userland();
1582+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1583+ pax_close_userland();
1584+ return ret;
1585+}
1586+
1587+
1588
1589 /*
1590 * Fold a partial checksum without adding pseudo headers
1591diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1592index df2fbba..63fe3e1 100644
1593--- a/arch/arm/include/asm/cmpxchg.h
1594+++ b/arch/arm/include/asm/cmpxchg.h
1595@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1596
1597 #define xchg(ptr,x) \
1598 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1599+#define xchg_unchecked(ptr,x) \
1600+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1601
1602 #include <asm-generic/cmpxchg-local.h>
1603
1604diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1605index 6ddbe44..b5e38b1 100644
1606--- a/arch/arm/include/asm/domain.h
1607+++ b/arch/arm/include/asm/domain.h
1608@@ -48,18 +48,37 @@
1609 * Domain types
1610 */
1611 #define DOMAIN_NOACCESS 0
1612-#define DOMAIN_CLIENT 1
1613 #ifdef CONFIG_CPU_USE_DOMAINS
1614+#define DOMAIN_USERCLIENT 1
1615+#define DOMAIN_KERNELCLIENT 1
1616 #define DOMAIN_MANAGER 3
1617+#define DOMAIN_VECTORS DOMAIN_USER
1618 #else
1619+
1620+#ifdef CONFIG_PAX_KERNEXEC
1621 #define DOMAIN_MANAGER 1
1622+#define DOMAIN_KERNEXEC 3
1623+#else
1624+#define DOMAIN_MANAGER 1
1625+#endif
1626+
1627+#ifdef CONFIG_PAX_MEMORY_UDEREF
1628+#define DOMAIN_USERCLIENT 0
1629+#define DOMAIN_UDEREF 1
1630+#define DOMAIN_VECTORS DOMAIN_KERNEL
1631+#else
1632+#define DOMAIN_USERCLIENT 1
1633+#define DOMAIN_VECTORS DOMAIN_USER
1634+#endif
1635+#define DOMAIN_KERNELCLIENT 1
1636+
1637 #endif
1638
1639 #define domain_val(dom,type) ((type) << (2*(dom)))
1640
1641 #ifndef __ASSEMBLY__
1642
1643-#ifdef CONFIG_CPU_USE_DOMAINS
1644+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1645 static inline void set_domain(unsigned val)
1646 {
1647 asm volatile(
1648@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1649 isb();
1650 }
1651
1652-#define modify_domain(dom,type) \
1653- do { \
1654- struct thread_info *thread = current_thread_info(); \
1655- unsigned int domain = thread->cpu_domain; \
1656- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1657- thread->cpu_domain = domain | domain_val(dom, type); \
1658- set_domain(thread->cpu_domain); \
1659- } while (0)
1660-
1661+extern void modify_domain(unsigned int dom, unsigned int type);
1662 #else
1663 static inline void set_domain(unsigned val) { }
1664 static inline void modify_domain(unsigned dom, unsigned type) { }
1665diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1666index f4b46d3..abc9b2b 100644
1667--- a/arch/arm/include/asm/elf.h
1668+++ b/arch/arm/include/asm/elf.h
1669@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1670 the loader. We need to make sure that it is out of the way of the program
1671 that it will "exec", and that there is sufficient room for the brk. */
1672
1673-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1674+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1675+
1676+#ifdef CONFIG_PAX_ASLR
1677+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1678+
1679+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1680+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1681+#endif
1682
1683 /* When the program starts, a1 contains a pointer to a function to be
1684 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1685@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1686 extern void elf_set_personality(const struct elf32_hdr *);
1687 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1688
1689-struct mm_struct;
1690-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1691-#define arch_randomize_brk arch_randomize_brk
1692-
1693 #ifdef CONFIG_MMU
1694 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1695 struct linux_binprm;
1696diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1697index de53547..52b9a28 100644
1698--- a/arch/arm/include/asm/fncpy.h
1699+++ b/arch/arm/include/asm/fncpy.h
1700@@ -81,7 +81,9 @@
1701 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1702 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1703 \
1704+ pax_open_kernel(); \
1705 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1706+ pax_close_kernel(); \
1707 flush_icache_range((unsigned long)(dest_buf), \
1708 (unsigned long)(dest_buf) + (size)); \
1709 \
1710diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1711index e42cf59..7b94b8f 100644
1712--- a/arch/arm/include/asm/futex.h
1713+++ b/arch/arm/include/asm/futex.h
1714@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1715 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1716 return -EFAULT;
1717
1718+ pax_open_userland();
1719+
1720 smp_mb();
1721 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1722 "1: ldrex %1, [%4]\n"
1723@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1724 : "cc", "memory");
1725 smp_mb();
1726
1727+ pax_close_userland();
1728+
1729 *uval = val;
1730 return ret;
1731 }
1732@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1733 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1734 return -EFAULT;
1735
1736+ pax_open_userland();
1737+
1738 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1739 "1: " TUSER(ldr) " %1, [%4]\n"
1740 " teq %1, %2\n"
1741@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1742 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1743 : "cc", "memory");
1744
1745+ pax_close_userland();
1746+
1747 *uval = val;
1748 return ret;
1749 }
1750@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1751 return -EFAULT;
1752
1753 pagefault_disable(); /* implies preempt_disable() */
1754+ pax_open_userland();
1755
1756 switch (op) {
1757 case FUTEX_OP_SET:
1758@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1759 ret = -ENOSYS;
1760 }
1761
1762+ pax_close_userland();
1763 pagefault_enable(); /* subsumes preempt_enable() */
1764
1765 if (!ret) {
1766diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1767index 83eb2f7..ed77159 100644
1768--- a/arch/arm/include/asm/kmap_types.h
1769+++ b/arch/arm/include/asm/kmap_types.h
1770@@ -4,6 +4,6 @@
1771 /*
1772 * This is the "bare minimum". AIO seems to require this.
1773 */
1774-#define KM_TYPE_NR 16
1775+#define KM_TYPE_NR 17
1776
1777 #endif
1778diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1779index 9e614a1..3302cca 100644
1780--- a/arch/arm/include/asm/mach/dma.h
1781+++ b/arch/arm/include/asm/mach/dma.h
1782@@ -22,7 +22,7 @@ struct dma_ops {
1783 int (*residue)(unsigned int, dma_t *); /* optional */
1784 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1785 const char *type;
1786-};
1787+} __do_const;
1788
1789 struct dma_struct {
1790 void *addr; /* single DMA address */
1791diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1792index 2fe141f..192dc01 100644
1793--- a/arch/arm/include/asm/mach/map.h
1794+++ b/arch/arm/include/asm/mach/map.h
1795@@ -27,13 +27,16 @@ struct map_desc {
1796 #define MT_MINICLEAN 6
1797 #define MT_LOW_VECTORS 7
1798 #define MT_HIGH_VECTORS 8
1799-#define MT_MEMORY 9
1800+#define MT_MEMORY_RWX 9
1801 #define MT_ROM 10
1802-#define MT_MEMORY_NONCACHED 11
1803+#define MT_MEMORY_NONCACHED_RX 11
1804 #define MT_MEMORY_DTCM 12
1805 #define MT_MEMORY_ITCM 13
1806 #define MT_MEMORY_SO 14
1807 #define MT_MEMORY_DMA_READY 15
1808+#define MT_MEMORY_RW 16
1809+#define MT_MEMORY_RX 17
1810+#define MT_MEMORY_NONCACHED_RW 18
1811
1812 #ifdef CONFIG_MMU
1813 extern void iotable_init(struct map_desc *, int);
1814diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1815index f94784f..9a09a4a 100644
1816--- a/arch/arm/include/asm/outercache.h
1817+++ b/arch/arm/include/asm/outercache.h
1818@@ -35,7 +35,7 @@ struct outer_cache_fns {
1819 #endif
1820 void (*set_debug)(unsigned long);
1821 void (*resume)(void);
1822-};
1823+} __no_const;
1824
1825 extern struct outer_cache_fns outer_cache;
1826
1827diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1828index 4355f0e..c229913 100644
1829--- a/arch/arm/include/asm/page.h
1830+++ b/arch/arm/include/asm/page.h
1831@@ -114,7 +114,7 @@ struct cpu_user_fns {
1832 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1833 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1834 unsigned long vaddr, struct vm_area_struct *vma);
1835-};
1836+} __no_const;
1837
1838 #ifdef MULTI_USER
1839 extern struct cpu_user_fns cpu_user;
1840diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1841index 78a7793..e3dc06c 100644
1842--- a/arch/arm/include/asm/pgalloc.h
1843+++ b/arch/arm/include/asm/pgalloc.h
1844@@ -17,6 +17,7 @@
1845 #include <asm/processor.h>
1846 #include <asm/cacheflush.h>
1847 #include <asm/tlbflush.h>
1848+#include <asm/system_info.h>
1849
1850 #define check_pgt_cache() do { } while (0)
1851
1852@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1853 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1854 }
1855
1856+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1857+{
1858+ pud_populate(mm, pud, pmd);
1859+}
1860+
1861 #else /* !CONFIG_ARM_LPAE */
1862
1863 /*
1864@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1865 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1866 #define pmd_free(mm, pmd) do { } while (0)
1867 #define pud_populate(mm,pmd,pte) BUG()
1868+#define pud_populate_kernel(mm,pmd,pte) BUG()
1869
1870 #endif /* CONFIG_ARM_LPAE */
1871
1872@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1873 __free_page(pte);
1874 }
1875
1876+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1877+{
1878+#ifdef CONFIG_ARM_LPAE
1879+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1880+#else
1881+ if (addr & SECTION_SIZE)
1882+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1883+ else
1884+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1885+#endif
1886+ flush_pmd_entry(pmdp);
1887+}
1888+
1889 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1890 pmdval_t prot)
1891 {
1892@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1893 static inline void
1894 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1895 {
1896- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1897+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1898 }
1899 #define pmd_pgtable(pmd) pmd_page(pmd)
1900
1901diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1902index 5cfba15..f415e1a 100644
1903--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1904+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1905@@ -20,12 +20,15 @@
1906 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1907 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1908 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1909+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1910 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1911 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1912 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1913+
1914 /*
1915 * - section
1916 */
1917+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1918 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1919 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1920 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1921@@ -37,6 +40,7 @@
1922 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1923 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1924 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1925+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1926
1927 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1928 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1929@@ -66,6 +70,7 @@
1930 * - extended small page/tiny page
1931 */
1932 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1933+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1934 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1935 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1936 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1937diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1938index 86a659a..70e0120 100644
1939--- a/arch/arm/include/asm/pgtable-2level.h
1940+++ b/arch/arm/include/asm/pgtable-2level.h
1941@@ -126,6 +126,9 @@
1942 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1943 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1944
1945+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1946+#define L_PTE_PXN (_AT(pteval_t, 0))
1947+
1948 /*
1949 * These are the memory types, defined to be compatible with
1950 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1951diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1952index 626989f..9d67a33 100644
1953--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1954+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1955@@ -75,6 +75,7 @@
1956 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1957 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1958 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1959+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1961
1962 /*
1963diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1964index 4f95039..b2dd513 100644
1965--- a/arch/arm/include/asm/pgtable-3level.h
1966+++ b/arch/arm/include/asm/pgtable-3level.h
1967@@ -82,6 +82,7 @@
1968 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1969 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1970 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1971+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1972 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1973 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1974 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1975@@ -95,6 +96,7 @@
1976 /*
1977 * To be used in assembly code with the upper page attributes.
1978 */
1979+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1980 #define L_PTE_XN_HIGH (1 << (54 - 32))
1981 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1982
1983diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1984index 1571d12..b8a9b43 100644
1985--- a/arch/arm/include/asm/pgtable.h
1986+++ b/arch/arm/include/asm/pgtable.h
1987@@ -33,6 +33,9 @@
1988 #include <asm/pgtable-2level.h>
1989 #endif
1990
1991+#define ktla_ktva(addr) (addr)
1992+#define ktva_ktla(addr) (addr)
1993+
1994 /*
1995 * Just any arbitrary offset to the start of the vmalloc VM area: the
1996 * current 8MB value just means that there will be a 8MB "hole" after the
1997@@ -48,6 +51,9 @@
1998 #define LIBRARY_TEXT_START 0x0c000000
1999
2000 #ifndef __ASSEMBLY__
2001+extern pteval_t __supported_pte_mask;
2002+extern pmdval_t __supported_pmd_mask;
2003+
2004 extern void __pte_error(const char *file, int line, pte_t);
2005 extern void __pmd_error(const char *file, int line, pmd_t);
2006 extern void __pgd_error(const char *file, int line, pgd_t);
2007@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2008 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2009 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2010
2011+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2012+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2013+
2014+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2015+#include <asm/domain.h>
2016+#include <linux/thread_info.h>
2017+#include <linux/preempt.h>
2018+
2019+static inline int test_domain(int domain, int domaintype)
2020+{
2021+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2022+}
2023+#endif
2024+
2025+#ifdef CONFIG_PAX_KERNEXEC
2026+static inline unsigned long pax_open_kernel(void) {
2027+#ifdef CONFIG_ARM_LPAE
2028+ /* TODO */
2029+#else
2030+ preempt_disable();
2031+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2032+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2033+#endif
2034+ return 0;
2035+}
2036+
2037+static inline unsigned long pax_close_kernel(void) {
2038+#ifdef CONFIG_ARM_LPAE
2039+ /* TODO */
2040+#else
2041+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2042+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2043+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2044+ preempt_enable_no_resched();
2045+#endif
2046+ return 0;
2047+}
2048+#else
2049+static inline unsigned long pax_open_kernel(void) { return 0; }
2050+static inline unsigned long pax_close_kernel(void) { return 0; }
2051+#endif
2052+
2053 /*
2054 * This is the lowest virtual address we can permit any user space
2055 * mapping to be mapped at. This is particularly important for
2056@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2057 /*
2058 * The pgprot_* and protection_map entries will be fixed up in runtime
2059 * to include the cachable and bufferable bits based on memory policy,
2060- * as well as any architecture dependent bits like global/ASID and SMP
2061- * shared mapping bits.
2062+ * as well as any architecture dependent bits like global/ASID, PXN,
2063+ * and SMP shared mapping bits.
2064 */
2065 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2066
2067@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2068 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2069 {
2070 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2071- L_PTE_NONE | L_PTE_VALID;
2072+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2073 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2074 return pte;
2075 }
2076diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2077index 5324c11..bcae5f0 100644
2078--- a/arch/arm/include/asm/proc-fns.h
2079+++ b/arch/arm/include/asm/proc-fns.h
2080@@ -75,7 +75,7 @@ extern struct processor {
2081 unsigned int suspend_size;
2082 void (*do_suspend)(void *);
2083 void (*do_resume)(void *);
2084-} processor;
2085+} __do_const processor;
2086
2087 #ifndef MULTI_CPU
2088 extern void cpu_proc_init(void);
2089diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2090index c4ae171..ea0c0c2 100644
2091--- a/arch/arm/include/asm/psci.h
2092+++ b/arch/arm/include/asm/psci.h
2093@@ -29,7 +29,7 @@ struct psci_operations {
2094 int (*cpu_off)(struct psci_power_state state);
2095 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2096 int (*migrate)(unsigned long cpuid);
2097-};
2098+} __no_const;
2099
2100 extern struct psci_operations psci_ops;
2101 extern struct smp_operations psci_smp_ops;
2102diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2103index 22a3b9b..7f214ee 100644
2104--- a/arch/arm/include/asm/smp.h
2105+++ b/arch/arm/include/asm/smp.h
2106@@ -112,7 +112,7 @@ struct smp_operations {
2107 int (*cpu_disable)(unsigned int cpu);
2108 #endif
2109 #endif
2110-};
2111+} __no_const;
2112
2113 /*
2114 * set platform specific SMP operations
2115diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2116index 71a06b2..8bb9ae1 100644
2117--- a/arch/arm/include/asm/thread_info.h
2118+++ b/arch/arm/include/asm/thread_info.h
2119@@ -88,9 +88,9 @@ struct thread_info {
2120 .flags = 0, \
2121 .preempt_count = INIT_PREEMPT_COUNT, \
2122 .addr_limit = KERNEL_DS, \
2123- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2124- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2125- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2126+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2127+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2128+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2129 .restart_block = { \
2130 .fn = do_no_restart_syscall, \
2131 }, \
2132@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2133 #define TIF_SYSCALL_AUDIT 9
2134 #define TIF_SYSCALL_TRACEPOINT 10
2135 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2136-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2137+/* within 8 bits of TIF_SYSCALL_TRACE
2138+ * to meet flexible second operand requirements
2139+ */
2140+#define TIF_GRSEC_SETXID 12
2141+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2142 #define TIF_USING_IWMMXT 17
2143 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2144 #define TIF_RESTORE_SIGMASK 20
2145@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2146 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2147 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2148 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2149+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2150
2151 /* Checks for any syscall work in entry-common.S */
2152 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2153- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2154+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2155
2156 /*
2157 * Change these and you break ASM code in entry-common.S
2158diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2159index 72abdc5..9eba222 100644
2160--- a/arch/arm/include/asm/uaccess.h
2161+++ b/arch/arm/include/asm/uaccess.h
2162@@ -18,6 +18,7 @@
2163 #include <asm/domain.h>
2164 #include <asm/unified.h>
2165 #include <asm/compiler.h>
2166+#include <asm/pgtable.h>
2167
2168 #if __LINUX_ARM_ARCH__ < 6
2169 #include <asm-generic/uaccess-unaligned.h>
2170@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2171 static inline void set_fs(mm_segment_t fs)
2172 {
2173 current_thread_info()->addr_limit = fs;
2174- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2175+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2176 }
2177
2178 #define segment_eq(a,b) ((a) == (b))
2179
2180+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2181+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2182+
2183+static inline void pax_open_userland(void)
2184+{
2185+
2186+#ifdef CONFIG_PAX_MEMORY_UDEREF
2187+ if (segment_eq(get_fs(), USER_DS)) {
2188+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2189+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2190+ }
2191+#endif
2192+
2193+}
2194+
2195+static inline void pax_close_userland(void)
2196+{
2197+
2198+#ifdef CONFIG_PAX_MEMORY_UDEREF
2199+ if (segment_eq(get_fs(), USER_DS)) {
2200+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2201+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2202+ }
2203+#endif
2204+
2205+}
2206+
2207 #define __addr_ok(addr) ({ \
2208 unsigned long flag; \
2209 __asm__("cmp %2, %0; movlo %0, #0" \
2210@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2211
2212 #define get_user(x,p) \
2213 ({ \
2214+ int __e; \
2215 might_fault(); \
2216- __get_user_check(x,p); \
2217+ pax_open_userland(); \
2218+ __e = __get_user_check(x,p); \
2219+ pax_close_userland(); \
2220+ __e; \
2221 })
2222
2223 extern int __put_user_1(void *, unsigned int);
2224@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2225
2226 #define put_user(x,p) \
2227 ({ \
2228+ int __e; \
2229 might_fault(); \
2230- __put_user_check(x,p); \
2231+ pax_open_userland(); \
2232+ __e = __put_user_check(x,p); \
2233+ pax_close_userland(); \
2234+ __e; \
2235 })
2236
2237 #else /* CONFIG_MMU */
2238@@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2239 #define __get_user(x,ptr) \
2240 ({ \
2241 long __gu_err = 0; \
2242+ pax_open_userland(); \
2243 __get_user_err((x),(ptr),__gu_err); \
2244+ pax_close_userland(); \
2245 __gu_err; \
2246 })
2247
2248 #define __get_user_error(x,ptr,err) \
2249 ({ \
2250+ pax_open_userland(); \
2251 __get_user_err((x),(ptr),err); \
2252+ pax_close_userland(); \
2253 (void) 0; \
2254 })
2255
2256@@ -319,13 +359,17 @@ do { \
2257 #define __put_user(x,ptr) \
2258 ({ \
2259 long __pu_err = 0; \
2260+ pax_open_userland(); \
2261 __put_user_err((x),(ptr),__pu_err); \
2262+ pax_close_userland(); \
2263 __pu_err; \
2264 })
2265
2266 #define __put_user_error(x,ptr,err) \
2267 ({ \
2268+ pax_open_userland(); \
2269 __put_user_err((x),(ptr),err); \
2270+ pax_close_userland(); \
2271 (void) 0; \
2272 })
2273
2274@@ -425,11 +469,44 @@ do { \
2275
2276
2277 #ifdef CONFIG_MMU
2278-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2279-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2280+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2281+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2282+
2283+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2284+{
2285+ unsigned long ret;
2286+
2287+ check_object_size(to, n, false);
2288+ pax_open_userland();
2289+ ret = ___copy_from_user(to, from, n);
2290+ pax_close_userland();
2291+ return ret;
2292+}
2293+
2294+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2295+{
2296+ unsigned long ret;
2297+
2298+ check_object_size(from, n, true);
2299+ pax_open_userland();
2300+ ret = ___copy_to_user(to, from, n);
2301+ pax_close_userland();
2302+ return ret;
2303+}
2304+
2305 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2306-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2307+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2308 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2309+
2310+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2311+{
2312+ unsigned long ret;
2313+ pax_open_userland();
2314+ ret = ___clear_user(addr, n);
2315+ pax_close_userland();
2316+ return ret;
2317+}
2318+
2319 #else
2320 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2321 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2322@@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2323
2324 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2325 {
2326+ if ((long)n < 0)
2327+ return n;
2328+
2329 if (access_ok(VERIFY_READ, from, n))
2330 n = __copy_from_user(to, from, n);
2331 else /* security hole - plug it */
2332@@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2333
2334 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2335 {
2336+ if ((long)n < 0)
2337+ return n;
2338+
2339 if (access_ok(VERIFY_WRITE, to, n))
2340 n = __copy_to_user(to, from, n);
2341 return n;
2342diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2343index 5af0ed1..cea83883 100644
2344--- a/arch/arm/include/uapi/asm/ptrace.h
2345+++ b/arch/arm/include/uapi/asm/ptrace.h
2346@@ -92,7 +92,7 @@
2347 * ARMv7 groups of PSR bits
2348 */
2349 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2350-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2351+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2352 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2353 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2354
2355diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2356index 1f031dd..d9b5e4a 100644
2357--- a/arch/arm/kernel/armksyms.c
2358+++ b/arch/arm/kernel/armksyms.c
2359@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2360
2361 /* networking */
2362 EXPORT_SYMBOL(csum_partial);
2363-EXPORT_SYMBOL(csum_partial_copy_from_user);
2364+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2365 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2366 EXPORT_SYMBOL(__csum_ipv6_magic);
2367
2368@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2369 #ifdef CONFIG_MMU
2370 EXPORT_SYMBOL(copy_page);
2371
2372-EXPORT_SYMBOL(__copy_from_user);
2373-EXPORT_SYMBOL(__copy_to_user);
2374-EXPORT_SYMBOL(__clear_user);
2375+EXPORT_SYMBOL(___copy_from_user);
2376+EXPORT_SYMBOL(___copy_to_user);
2377+EXPORT_SYMBOL(___clear_user);
2378
2379 EXPORT_SYMBOL(__get_user_1);
2380 EXPORT_SYMBOL(__get_user_2);
2381diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2382index b3fb8c9..59cfab2 100644
2383--- a/arch/arm/kernel/entry-armv.S
2384+++ b/arch/arm/kernel/entry-armv.S
2385@@ -47,6 +47,87 @@
2386 9997:
2387 .endm
2388
2389+ .macro pax_enter_kernel
2390+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2391+ @ make aligned space for saved DACR
2392+ sub sp, sp, #8
2393+ @ save regs
2394+ stmdb sp!, {r1, r2}
2395+ @ read DACR from cpu_domain into r1
2396+ mov r2, sp
2397+ @ assume 8K pages, since we have to split the immediate in two
2398+ bic r2, r2, #(0x1fc0)
2399+ bic r2, r2, #(0x3f)
2400+ ldr r1, [r2, #TI_CPU_DOMAIN]
2401+ @ store old DACR on stack
2402+ str r1, [sp, #8]
2403+#ifdef CONFIG_PAX_KERNEXEC
2404+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2405+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2406+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2407+#endif
2408+#ifdef CONFIG_PAX_MEMORY_UDEREF
2409+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2410+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2411+#endif
2412+ @ write r1 to current_thread_info()->cpu_domain
2413+ str r1, [r2, #TI_CPU_DOMAIN]
2414+ @ write r1 to DACR
2415+ mcr p15, 0, r1, c3, c0, 0
2416+ @ instruction sync
2417+ instr_sync
2418+ @ restore regs
2419+ ldmia sp!, {r1, r2}
2420+#endif
2421+ .endm
2422+
2423+ .macro pax_open_userland
2424+#ifdef CONFIG_PAX_MEMORY_UDEREF
2425+ @ save regs
2426+ stmdb sp!, {r0, r1}
2427+ @ read DACR from cpu_domain into r1
2428+ mov r0, sp
2429+ @ assume 8K pages, since we have to split the immediate in two
2430+ bic r0, r0, #(0x1fc0)
2431+ bic r0, r0, #(0x3f)
2432+ ldr r1, [r0, #TI_CPU_DOMAIN]
2433+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2434+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2435+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2436+ @ write r1 to current_thread_info()->cpu_domain
2437+ str r1, [r0, #TI_CPU_DOMAIN]
2438+ @ write r1 to DACR
2439+ mcr p15, 0, r1, c3, c0, 0
2440+ @ instruction sync
2441+ instr_sync
2442+ @ restore regs
2443+ ldmia sp!, {r0, r1}
2444+#endif
2445+ .endm
2446+
2447+ .macro pax_close_userland
2448+#ifdef CONFIG_PAX_MEMORY_UDEREF
2449+ @ save regs
2450+ stmdb sp!, {r0, r1}
2451+ @ read DACR from cpu_domain into r1
2452+ mov r0, sp
2453+ @ assume 8K pages, since we have to split the immediate in two
2454+ bic r0, r0, #(0x1fc0)
2455+ bic r0, r0, #(0x3f)
2456+ ldr r1, [r0, #TI_CPU_DOMAIN]
2457+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2458+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2459+ @ write r1 to current_thread_info()->cpu_domain
2460+ str r1, [r0, #TI_CPU_DOMAIN]
2461+ @ write r1 to DACR
2462+ mcr p15, 0, r1, c3, c0, 0
2463+ @ instruction sync
2464+ instr_sync
2465+ @ restore regs
2466+ ldmia sp!, {r0, r1}
2467+#endif
2468+ .endm
2469+
2470 .macro pabt_helper
2471 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2472 #ifdef MULTI_PABORT
2473@@ -89,11 +170,15 @@
2474 * Invalid mode handlers
2475 */
2476 .macro inv_entry, reason
2477+
2478+ pax_enter_kernel
2479+
2480 sub sp, sp, #S_FRAME_SIZE
2481 ARM( stmib sp, {r1 - lr} )
2482 THUMB( stmia sp, {r0 - r12} )
2483 THUMB( str sp, [sp, #S_SP] )
2484 THUMB( str lr, [sp, #S_LR] )
2485+
2486 mov r1, #\reason
2487 .endm
2488
2489@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2490 .macro svc_entry, stack_hole=0
2491 UNWIND(.fnstart )
2492 UNWIND(.save {r0 - pc} )
2493+
2494+ pax_enter_kernel
2495+
2496 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2497+
2498 #ifdef CONFIG_THUMB2_KERNEL
2499 SPFIX( str r0, [sp] ) @ temporarily saved
2500 SPFIX( mov r0, sp )
2501@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2502 ldmia r0, {r3 - r5}
2503 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2504 mov r6, #-1 @ "" "" "" ""
2505+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2506+ @ offset sp by 8 as done in pax_enter_kernel
2507+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2508+#else
2509 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2510+#endif
2511 SPFIX( addeq r2, r2, #4 )
2512 str r3, [sp, #-4]! @ save the "real" r0 copied
2513 @ from the exception stack
2514@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2515 .macro usr_entry
2516 UNWIND(.fnstart )
2517 UNWIND(.cantunwind ) @ don't unwind the user space
2518+
2519+ pax_enter_kernel_user
2520+
2521 sub sp, sp, #S_FRAME_SIZE
2522 ARM( stmib sp, {r1 - r12} )
2523 THUMB( stmia sp, {r0 - r12} )
2524@@ -416,7 +513,9 @@ __und_usr:
2525 tst r3, #PSR_T_BIT @ Thumb mode?
2526 bne __und_usr_thumb
2527 sub r4, r2, #4 @ ARM instr at LR - 4
2528+ pax_open_userland
2529 1: ldrt r0, [r4]
2530+ pax_close_userland
2531 ARM_BE8(rev r0, r0) @ little endian instruction
2532
2533 @ r0 = 32-bit ARM instruction which caused the exception
2534@@ -450,10 +549,14 @@ __und_usr_thumb:
2535 */
2536 .arch armv6t2
2537 #endif
2538+ pax_open_userland
2539 2: ldrht r5, [r4]
2540+ pax_close_userland
2541 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2542 blo __und_usr_fault_16 @ 16bit undefined instruction
2543+ pax_open_userland
2544 3: ldrht r0, [r2]
2545+ pax_close_userland
2546 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2547 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2548 orr r0, r0, r5, lsl #16
2549@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2550 */
2551 .pushsection .fixup, "ax"
2552 .align 2
2553-4: mov pc, r9
2554+4: pax_close_userland
2555+ mov pc, r9
2556 .popsection
2557 .pushsection __ex_table,"a"
2558 .long 1b, 4b
2559@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2560 THUMB( str lr, [ip], #4 )
2561 ldr r4, [r2, #TI_TP_VALUE]
2562 ldr r5, [r2, #TI_TP_VALUE + 4]
2563-#ifdef CONFIG_CPU_USE_DOMAINS
2564+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2565 ldr r6, [r2, #TI_CPU_DOMAIN]
2566 #endif
2567 switch_tls r1, r4, r5, r3, r7
2568@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2569 ldr r8, =__stack_chk_guard
2570 ldr r7, [r7, #TSK_STACK_CANARY]
2571 #endif
2572-#ifdef CONFIG_CPU_USE_DOMAINS
2573+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2575 #endif
2576 mov r5, r0
2577diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2578index a2dcafd..1048b5a 100644
2579--- a/arch/arm/kernel/entry-common.S
2580+++ b/arch/arm/kernel/entry-common.S
2581@@ -10,18 +10,46 @@
2582
2583 #include <asm/unistd.h>
2584 #include <asm/ftrace.h>
2585+#include <asm/domain.h>
2586 #include <asm/unwind.h>
2587
2588+#include "entry-header.S"
2589+
2590 #ifdef CONFIG_NEED_RET_TO_USER
2591 #include <mach/entry-macro.S>
2592 #else
2593 .macro arch_ret_to_user, tmp1, tmp2
2594+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595+ @ save regs
2596+ stmdb sp!, {r1, r2}
2597+ @ read DACR from cpu_domain into r1
2598+ mov r2, sp
2599+ @ assume 8K pages, since we have to split the immediate in two
2600+ bic r2, r2, #(0x1fc0)
2601+ bic r2, r2, #(0x3f)
2602+ ldr r1, [r2, #TI_CPU_DOMAIN]
2603+#ifdef CONFIG_PAX_KERNEXEC
2604+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2605+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2606+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2607+#endif
2608+#ifdef CONFIG_PAX_MEMORY_UDEREF
2609+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2610+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2611+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2612+#endif
2613+ @ write r1 to current_thread_info()->cpu_domain
2614+ str r1, [r2, #TI_CPU_DOMAIN]
2615+ @ write r1 to DACR
2616+ mcr p15, 0, r1, c3, c0, 0
2617+ @ instruction sync
2618+ instr_sync
2619+ @ restore regs
2620+ ldmia sp!, {r1, r2}
2621+#endif
2622 .endm
2623 #endif
2624
2625-#include "entry-header.S"
2626-
2627-
2628 .align 5
2629 /*
2630 * This is the fast syscall return path. We do as little as
2631@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2632 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2633 #endif
2634
2635+ /*
2636+ * do this here to avoid a performance hit of wrapping the code above
2637+ * that directly dereferences userland to parse the SWI instruction
2638+ */
2639+ pax_enter_kernel_user
2640+
2641 adr tbl, sys_call_table @ load syscall table pointer
2642
2643 #if defined(CONFIG_OABI_COMPAT)
2644diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2645index 39f89fb..d612bd9 100644
2646--- a/arch/arm/kernel/entry-header.S
2647+++ b/arch/arm/kernel/entry-header.S
2648@@ -184,6 +184,60 @@
2649 msr cpsr_c, \rtemp @ switch back to the SVC mode
2650 .endm
2651
2652+ .macro pax_enter_kernel_user
2653+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2654+ @ save regs
2655+ stmdb sp!, {r0, r1}
2656+ @ read DACR from cpu_domain into r1
2657+ mov r0, sp
2658+ @ assume 8K pages, since we have to split the immediate in two
2659+ bic r0, r0, #(0x1fc0)
2660+ bic r0, r0, #(0x3f)
2661+ ldr r1, [r0, #TI_CPU_DOMAIN]
2662+#ifdef CONFIG_PAX_MEMORY_UDEREF
2663+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2664+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2665+#endif
2666+#ifdef CONFIG_PAX_KERNEXEC
2667+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2668+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2669+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2670+#endif
2671+ @ write r1 to current_thread_info()->cpu_domain
2672+ str r1, [r0, #TI_CPU_DOMAIN]
2673+ @ write r1 to DACR
2674+ mcr p15, 0, r1, c3, c0, 0
2675+ @ instruction sync
2676+ instr_sync
2677+ @ restore regs
2678+ ldmia sp!, {r0, r1}
2679+#endif
2680+ .endm
2681+
2682+ .macro pax_exit_kernel
2683+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2684+ @ save regs
2685+ stmdb sp!, {r0, r1}
2686+ @ read old DACR from stack into r1
2687+ ldr r1, [sp, #(8 + S_SP)]
2688+ sub r1, r1, #8
2689+ ldr r1, [r1]
2690+
2691+ @ write r1 to current_thread_info()->cpu_domain
2692+ mov r0, sp
2693+ @ assume 8K pages, since we have to split the immediate in two
2694+ bic r0, r0, #(0x1fc0)
2695+ bic r0, r0, #(0x3f)
2696+ str r1, [r0, #TI_CPU_DOMAIN]
2697+ @ write r1 to DACR
2698+ mcr p15, 0, r1, c3, c0, 0
2699+ @ instruction sync
2700+ instr_sync
2701+ @ restore regs
2702+ ldmia sp!, {r0, r1}
2703+#endif
2704+ .endm
2705+
2706 #ifndef CONFIG_THUMB2_KERNEL
2707 .macro svc_exit, rpsr, irq = 0
2708 .if \irq != 0
2709@@ -203,6 +257,9 @@
2710 blne trace_hardirqs_off
2711 #endif
2712 .endif
2713+
2714+ pax_exit_kernel
2715+
2716 msr spsr_cxsf, \rpsr
2717 #if defined(CONFIG_CPU_V6)
2718 ldr r0, [sp]
2719@@ -266,6 +323,9 @@
2720 blne trace_hardirqs_off
2721 #endif
2722 .endif
2723+
2724+ pax_exit_kernel
2725+
2726 ldr lr, [sp, #S_SP] @ top of the stack
2727 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2728 clrex @ clear the exclusive monitor
2729diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2730index 918875d..cd5fa27 100644
2731--- a/arch/arm/kernel/fiq.c
2732+++ b/arch/arm/kernel/fiq.c
2733@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2734 void *base = vectors_page;
2735 unsigned offset = FIQ_OFFSET;
2736
2737+ pax_open_kernel();
2738 memcpy(base + offset, start, length);
2739+ pax_close_kernel();
2740+
2741 if (!cache_is_vipt_nonaliasing())
2742 flush_icache_range((unsigned long)base + offset, offset +
2743 length);
2744diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2745index 32f317e..710ae07 100644
2746--- a/arch/arm/kernel/head.S
2747+++ b/arch/arm/kernel/head.S
2748@@ -52,7 +52,9 @@
2749 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2750
2751 .macro pgtbl, rd, phys
2752- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2753+ mov \rd, #TEXT_OFFSET
2754+ sub \rd, #PG_DIR_SIZE
2755+ add \rd, \rd, \phys
2756 .endm
2757
2758 /*
2759@@ -436,7 +438,7 @@ __enable_mmu:
2760 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2761 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2762 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2763- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2764+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2765 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2766 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2767 #endif
2768diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2769index 45e4781..8eac93d 100644
2770--- a/arch/arm/kernel/module.c
2771+++ b/arch/arm/kernel/module.c
2772@@ -38,12 +38,39 @@
2773 #endif
2774
2775 #ifdef CONFIG_MMU
2776-void *module_alloc(unsigned long size)
2777+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2778 {
2779+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2780+ return NULL;
2781 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2782- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2783+ GFP_KERNEL, prot, NUMA_NO_NODE,
2784 __builtin_return_address(0));
2785 }
2786+
2787+void *module_alloc(unsigned long size)
2788+{
2789+
2790+#ifdef CONFIG_PAX_KERNEXEC
2791+ return __module_alloc(size, PAGE_KERNEL);
2792+#else
2793+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2794+#endif
2795+
2796+}
2797+
2798+#ifdef CONFIG_PAX_KERNEXEC
2799+void module_free_exec(struct module *mod, void *module_region)
2800+{
2801+ module_free(mod, module_region);
2802+}
2803+EXPORT_SYMBOL(module_free_exec);
2804+
2805+void *module_alloc_exec(unsigned long size)
2806+{
2807+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2808+}
2809+EXPORT_SYMBOL(module_alloc_exec);
2810+#endif
2811 #endif
2812
2813 int
2814diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2815index 07314af..c46655c 100644
2816--- a/arch/arm/kernel/patch.c
2817+++ b/arch/arm/kernel/patch.c
2818@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2819 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2820 int size;
2821
2822+ pax_open_kernel();
2823 if (thumb2 && __opcode_is_thumb16(insn)) {
2824 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2825 size = sizeof(u16);
2826@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2827 *(u32 *)addr = insn;
2828 size = sizeof(u32);
2829 }
2830+ pax_close_kernel();
2831
2832 flush_icache_range((uintptr_t)(addr),
2833 (uintptr_t)(addr) + size);
2834diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2835index 92f7b15..7048500 100644
2836--- a/arch/arm/kernel/process.c
2837+++ b/arch/arm/kernel/process.c
2838@@ -217,6 +217,7 @@ void machine_power_off(void)
2839
2840 if (pm_power_off)
2841 pm_power_off();
2842+ BUG();
2843 }
2844
2845 /*
2846@@ -230,7 +231,7 @@ void machine_power_off(void)
2847 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2848 * to use. Implementing such co-ordination would be essentially impossible.
2849 */
2850-void machine_restart(char *cmd)
2851+__noreturn void machine_restart(char *cmd)
2852 {
2853 local_irq_disable();
2854 smp_send_stop();
2855@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2856
2857 show_regs_print_info(KERN_DEFAULT);
2858
2859- print_symbol("PC is at %s\n", instruction_pointer(regs));
2860- print_symbol("LR is at %s\n", regs->ARM_lr);
2861+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2862+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2863 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2864 "sp : %08lx ip : %08lx fp : %08lx\n",
2865 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2866@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2867 return 0;
2868 }
2869
2870-unsigned long arch_randomize_brk(struct mm_struct *mm)
2871-{
2872- unsigned long range_end = mm->brk + 0x02000000;
2873- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2874-}
2875-
2876 #ifdef CONFIG_MMU
2877 #ifdef CONFIG_KUSER_HELPERS
2878 /*
2879@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2880
2881 static int __init gate_vma_init(void)
2882 {
2883- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2884+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2885 return 0;
2886 }
2887 arch_initcall(gate_vma_init);
2888@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2889
2890 const char *arch_vma_name(struct vm_area_struct *vma)
2891 {
2892- return is_gate_vma(vma) ? "[vectors]" :
2893- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2894- "[sigpage]" : NULL;
2895+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2896 }
2897
2898-static struct page *signal_page;
2899-extern struct page *get_signal_page(void);
2900-
2901 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2902 {
2903 struct mm_struct *mm = current->mm;
2904- unsigned long addr;
2905- int ret;
2906-
2907- if (!signal_page)
2908- signal_page = get_signal_page();
2909- if (!signal_page)
2910- return -ENOMEM;
2911
2912 down_write(&mm->mmap_sem);
2913- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2914- if (IS_ERR_VALUE(addr)) {
2915- ret = addr;
2916- goto up_fail;
2917- }
2918-
2919- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2920- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2921- &signal_page);
2922-
2923- if (ret == 0)
2924- mm->context.sigpage = addr;
2925-
2926- up_fail:
2927+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2928 up_write(&mm->mmap_sem);
2929- return ret;
2930+ return 0;
2931 }
2932 #endif
2933diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2934index 4693188..4596c5e 100644
2935--- a/arch/arm/kernel/psci.c
2936+++ b/arch/arm/kernel/psci.c
2937@@ -24,7 +24,7 @@
2938 #include <asm/opcodes-virt.h>
2939 #include <asm/psci.h>
2940
2941-struct psci_operations psci_ops;
2942+struct psci_operations psci_ops __read_only;
2943
2944 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2945
2946diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2947index 0dd3b79..e018f64 100644
2948--- a/arch/arm/kernel/ptrace.c
2949+++ b/arch/arm/kernel/ptrace.c
2950@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2951 return current_thread_info()->syscall;
2952 }
2953
2954+#ifdef CONFIG_GRKERNSEC_SETXID
2955+extern void gr_delayed_cred_worker(void);
2956+#endif
2957+
2958 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2959 {
2960 current_thread_info()->syscall = scno;
2961
2962+#ifdef CONFIG_GRKERNSEC_SETXID
2963+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2964+ gr_delayed_cred_worker();
2965+#endif
2966+
2967 /* Do the secure computing check first; failures should be fast. */
2968 if (secure_computing(scno) == -1)
2969 return -1;
2970diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2971index 987a7f5..d9d6071 100644
2972--- a/arch/arm/kernel/setup.c
2973+++ b/arch/arm/kernel/setup.c
2974@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2975 unsigned int elf_hwcap __read_mostly;
2976 EXPORT_SYMBOL(elf_hwcap);
2977
2978+pteval_t __supported_pte_mask __read_only;
2979+pmdval_t __supported_pmd_mask __read_only;
2980
2981 #ifdef MULTI_CPU
2982-struct processor processor __read_mostly;
2983+struct processor processor;
2984 #endif
2985 #ifdef MULTI_TLB
2986-struct cpu_tlb_fns cpu_tlb __read_mostly;
2987+struct cpu_tlb_fns cpu_tlb __read_only;
2988 #endif
2989 #ifdef MULTI_USER
2990-struct cpu_user_fns cpu_user __read_mostly;
2991+struct cpu_user_fns cpu_user __read_only;
2992 #endif
2993 #ifdef MULTI_CACHE
2994-struct cpu_cache_fns cpu_cache __read_mostly;
2995+struct cpu_cache_fns cpu_cache __read_only;
2996 #endif
2997 #ifdef CONFIG_OUTER_CACHE
2998-struct outer_cache_fns outer_cache __read_mostly;
2999+struct outer_cache_fns outer_cache __read_only;
3000 EXPORT_SYMBOL(outer_cache);
3001 #endif
3002
3003@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3004 asm("mrc p15, 0, %0, c0, c1, 4"
3005 : "=r" (mmfr0));
3006 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3007- (mmfr0 & 0x000000f0) >= 0x00000030)
3008+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3009 cpu_arch = CPU_ARCH_ARMv7;
3010- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3011+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3012+ __supported_pte_mask |= L_PTE_PXN;
3013+ __supported_pmd_mask |= PMD_PXNTABLE;
3014+ }
3015+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3016 (mmfr0 & 0x000000f0) == 0x00000020)
3017 cpu_arch = CPU_ARCH_ARMv6;
3018 else
3019@@ -573,7 +579,7 @@ static void __init setup_processor(void)
3020 __cpu_architecture = __get_cpu_architecture();
3021
3022 #ifdef MULTI_CPU
3023- processor = *list->proc;
3024+ memcpy((void *)&processor, list->proc, sizeof processor);
3025 #endif
3026 #ifdef MULTI_TLB
3027 cpu_tlb = *list->tlb;
3028diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3029index 04d6388..5115238 100644
3030--- a/arch/arm/kernel/signal.c
3031+++ b/arch/arm/kernel/signal.c
3032@@ -23,8 +23,6 @@
3033
3034 extern const unsigned long sigreturn_codes[7];
3035
3036-static unsigned long signal_return_offset;
3037-
3038 #ifdef CONFIG_CRUNCH
3039 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3040 {
3041@@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3042 * except when the MPU has protected the vectors
3043 * page from PL0
3044 */
3045- retcode = mm->context.sigpage + signal_return_offset +
3046- (idx << 2) + thumb;
3047+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3048 } else
3049 #endif
3050 {
3051@@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3052 } while (thread_flags & _TIF_WORK_MASK);
3053 return 0;
3054 }
3055-
3056-struct page *get_signal_page(void)
3057-{
3058- unsigned long ptr;
3059- unsigned offset;
3060- struct page *page;
3061- void *addr;
3062-
3063- page = alloc_pages(GFP_KERNEL, 0);
3064-
3065- if (!page)
3066- return NULL;
3067-
3068- addr = page_address(page);
3069-
3070- /* Give the signal return code some randomness */
3071- offset = 0x200 + (get_random_int() & 0x7fc);
3072- signal_return_offset = offset;
3073-
3074- /*
3075- * Copy signal return handlers into the vector page, and
3076- * set sigreturn to be a pointer to these.
3077- */
3078- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3079-
3080- ptr = (unsigned long)addr + offset;
3081- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3082-
3083- return page;
3084-}
3085diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3086index dc894ab..f929a0d 100644
3087--- a/arch/arm/kernel/smp.c
3088+++ b/arch/arm/kernel/smp.c
3089@@ -73,7 +73,7 @@ enum ipi_msg_type {
3090
3091 static DECLARE_COMPLETION(cpu_running);
3092
3093-static struct smp_operations smp_ops;
3094+static struct smp_operations smp_ops __read_only;
3095
3096 void __init smp_set_ops(struct smp_operations *ops)
3097 {
3098diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3099index 4636d56..ce4ec3d 100644
3100--- a/arch/arm/kernel/traps.c
3101+++ b/arch/arm/kernel/traps.c
3102@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3103 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3104 {
3105 #ifdef CONFIG_KALLSYMS
3106- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3107+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3108 #else
3109 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3110 #endif
3111@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3112 static int die_owner = -1;
3113 static unsigned int die_nest_count;
3114
3115+extern void gr_handle_kernel_exploit(void);
3116+
3117 static unsigned long oops_begin(void)
3118 {
3119 int cpu;
3120@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3121 panic("Fatal exception in interrupt");
3122 if (panic_on_oops)
3123 panic("Fatal exception");
3124+
3125+ gr_handle_kernel_exploit();
3126+
3127 if (signr)
3128 do_exit(signr);
3129 }
3130@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3131 * The user helper at 0xffff0fe0 must be used instead.
3132 * (see entry-armv.S for details)
3133 */
3134+ pax_open_kernel();
3135 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3136+ pax_close_kernel();
3137 }
3138 return 0;
3139
3140@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3141 kuser_init(vectors_base);
3142
3143 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3144- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3145+
3146+#ifndef CONFIG_PAX_MEMORY_UDEREF
3147+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3148+#endif
3149+
3150 #else /* ifndef CONFIG_CPU_V7M */
3151 /*
3152 * on V7-M there is no need to copy the vector table to a dedicated
3153diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3154index 7bcee5c..e2f3249 100644
3155--- a/arch/arm/kernel/vmlinux.lds.S
3156+++ b/arch/arm/kernel/vmlinux.lds.S
3157@@ -8,7 +8,11 @@
3158 #include <asm/thread_info.h>
3159 #include <asm/memory.h>
3160 #include <asm/page.h>
3161-
3162+
3163+#ifdef CONFIG_PAX_KERNEXEC
3164+#include <asm/pgtable.h>
3165+#endif
3166+
3167 #define PROC_INFO \
3168 . = ALIGN(4); \
3169 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3170@@ -34,7 +38,7 @@
3171 #endif
3172
3173 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3174- defined(CONFIG_GENERIC_BUG)
3175+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3176 #define ARM_EXIT_KEEP(x) x
3177 #define ARM_EXIT_DISCARD(x)
3178 #else
3179@@ -90,6 +94,11 @@ SECTIONS
3180 _text = .;
3181 HEAD_TEXT
3182 }
3183+
3184+#ifdef CONFIG_PAX_KERNEXEC
3185+ . = ALIGN(1<<SECTION_SHIFT);
3186+#endif
3187+
3188 .text : { /* Real text segment */
3189 _stext = .; /* Text and read-only data */
3190 __exception_text_start = .;
3191@@ -112,6 +121,8 @@ SECTIONS
3192 ARM_CPU_KEEP(PROC_INFO)
3193 }
3194
3195+ _etext = .; /* End of text section */
3196+
3197 RO_DATA(PAGE_SIZE)
3198
3199 . = ALIGN(4);
3200@@ -142,7 +153,9 @@ SECTIONS
3201
3202 NOTES
3203
3204- _etext = .; /* End of text and rodata section */
3205+#ifdef CONFIG_PAX_KERNEXEC
3206+ . = ALIGN(1<<SECTION_SHIFT);
3207+#endif
3208
3209 #ifndef CONFIG_XIP_KERNEL
3210 . = ALIGN(PAGE_SIZE);
3211@@ -220,6 +233,11 @@ SECTIONS
3212 . = PAGE_OFFSET + TEXT_OFFSET;
3213 #else
3214 __init_end = .;
3215+
3216+#ifdef CONFIG_PAX_KERNEXEC
3217+ . = ALIGN(1<<SECTION_SHIFT);
3218+#endif
3219+
3220 . = ALIGN(THREAD_SIZE);
3221 __data_loc = .;
3222 #endif
3223diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3224index 2a700e0..745b980 100644
3225--- a/arch/arm/kvm/arm.c
3226+++ b/arch/arm/kvm/arm.c
3227@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3228 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3229
3230 /* The VMID used in the VTTBR */
3231-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3232+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3233 static u8 kvm_next_vmid;
3234 static DEFINE_SPINLOCK(kvm_vmid_lock);
3235
3236@@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3237 */
3238 static bool need_new_vmid_gen(struct kvm *kvm)
3239 {
3240- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3241+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3242 }
3243
3244 /**
3245@@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3246
3247 /* First user of a new VMID generation? */
3248 if (unlikely(kvm_next_vmid == 0)) {
3249- atomic64_inc(&kvm_vmid_gen);
3250+ atomic64_inc_unchecked(&kvm_vmid_gen);
3251 kvm_next_vmid = 1;
3252
3253 /*
3254@@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3255 kvm_call_hyp(__kvm_flush_vm_context);
3256 }
3257
3258- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3259+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3260 kvm->arch.vmid = kvm_next_vmid;
3261 kvm_next_vmid++;
3262
3263diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3264index 14a0d98..7771a7d 100644
3265--- a/arch/arm/lib/clear_user.S
3266+++ b/arch/arm/lib/clear_user.S
3267@@ -12,14 +12,14 @@
3268
3269 .text
3270
3271-/* Prototype: int __clear_user(void *addr, size_t sz)
3272+/* Prototype: int ___clear_user(void *addr, size_t sz)
3273 * Purpose : clear some user memory
3274 * Params : addr - user memory address to clear
3275 * : sz - number of bytes to clear
3276 * Returns : number of bytes NOT cleared
3277 */
3278 ENTRY(__clear_user_std)
3279-WEAK(__clear_user)
3280+WEAK(___clear_user)
3281 stmfd sp!, {r1, lr}
3282 mov r2, #0
3283 cmp r1, #4
3284@@ -44,7 +44,7 @@ WEAK(__clear_user)
3285 USER( strnebt r2, [r0])
3286 mov r0, #0
3287 ldmfd sp!, {r1, pc}
3288-ENDPROC(__clear_user)
3289+ENDPROC(___clear_user)
3290 ENDPROC(__clear_user_std)
3291
3292 .pushsection .fixup,"ax"
3293diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3294index 66a477a..bee61d3 100644
3295--- a/arch/arm/lib/copy_from_user.S
3296+++ b/arch/arm/lib/copy_from_user.S
3297@@ -16,7 +16,7 @@
3298 /*
3299 * Prototype:
3300 *
3301- * size_t __copy_from_user(void *to, const void *from, size_t n)
3302+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3303 *
3304 * Purpose:
3305 *
3306@@ -84,11 +84,11 @@
3307
3308 .text
3309
3310-ENTRY(__copy_from_user)
3311+ENTRY(___copy_from_user)
3312
3313 #include "copy_template.S"
3314
3315-ENDPROC(__copy_from_user)
3316+ENDPROC(___copy_from_user)
3317
3318 .pushsection .fixup,"ax"
3319 .align 0
3320diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3321index 6ee2f67..d1cce76 100644
3322--- a/arch/arm/lib/copy_page.S
3323+++ b/arch/arm/lib/copy_page.S
3324@@ -10,6 +10,7 @@
3325 * ASM optimised string functions
3326 */
3327 #include <linux/linkage.h>
3328+#include <linux/const.h>
3329 #include <asm/assembler.h>
3330 #include <asm/asm-offsets.h>
3331 #include <asm/cache.h>
3332diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3333index d066df6..df28194 100644
3334--- a/arch/arm/lib/copy_to_user.S
3335+++ b/arch/arm/lib/copy_to_user.S
3336@@ -16,7 +16,7 @@
3337 /*
3338 * Prototype:
3339 *
3340- * size_t __copy_to_user(void *to, const void *from, size_t n)
3341+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3342 *
3343 * Purpose:
3344 *
3345@@ -88,11 +88,11 @@
3346 .text
3347
3348 ENTRY(__copy_to_user_std)
3349-WEAK(__copy_to_user)
3350+WEAK(___copy_to_user)
3351
3352 #include "copy_template.S"
3353
3354-ENDPROC(__copy_to_user)
3355+ENDPROC(___copy_to_user)
3356 ENDPROC(__copy_to_user_std)
3357
3358 .pushsection .fixup,"ax"
3359diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3360index 7d08b43..f7ca7ea 100644
3361--- a/arch/arm/lib/csumpartialcopyuser.S
3362+++ b/arch/arm/lib/csumpartialcopyuser.S
3363@@ -57,8 +57,8 @@
3364 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3365 */
3366
3367-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3368-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3369+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3370+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3371
3372 #include "csumpartialcopygeneric.S"
3373
3374diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3375index 5306de3..aed6d03 100644
3376--- a/arch/arm/lib/delay.c
3377+++ b/arch/arm/lib/delay.c
3378@@ -28,7 +28,7 @@
3379 /*
3380 * Default to the loop-based delay implementation.
3381 */
3382-struct arm_delay_ops arm_delay_ops = {
3383+struct arm_delay_ops arm_delay_ops __read_only = {
3384 .delay = __loop_delay,
3385 .const_udelay = __loop_const_udelay,
3386 .udelay = __loop_udelay,
3387diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3388index 3e58d71..029817c 100644
3389--- a/arch/arm/lib/uaccess_with_memcpy.c
3390+++ b/arch/arm/lib/uaccess_with_memcpy.c
3391@@ -136,7 +136,7 @@ out:
3392 }
3393
3394 unsigned long
3395-__copy_to_user(void __user *to, const void *from, unsigned long n)
3396+___copy_to_user(void __user *to, const void *from, unsigned long n)
3397 {
3398 /*
3399 * This test is stubbed out of the main function above to keep
3400@@ -190,7 +190,7 @@ out:
3401 return n;
3402 }
3403
3404-unsigned long __clear_user(void __user *addr, unsigned long n)
3405+unsigned long ___clear_user(void __user *addr, unsigned long n)
3406 {
3407 /* See rational for this in __copy_to_user() above. */
3408 if (n < 64)
3409diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3410index f3407a5..bd4256f 100644
3411--- a/arch/arm/mach-kirkwood/common.c
3412+++ b/arch/arm/mach-kirkwood/common.c
3413@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3414 clk_gate_ops.disable(hw);
3415 }
3416
3417-static struct clk_ops clk_gate_fn_ops;
3418+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3419+{
3420+ return clk_gate_ops.is_enabled(hw);
3421+}
3422+
3423+static struct clk_ops clk_gate_fn_ops = {
3424+ .enable = clk_gate_fn_enable,
3425+ .disable = clk_gate_fn_disable,
3426+ .is_enabled = clk_gate_fn_is_enabled,
3427+};
3428
3429 static struct clk __init *clk_register_gate_fn(struct device *dev,
3430 const char *name,
3431@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3432 gate_fn->fn_en = fn_en;
3433 gate_fn->fn_dis = fn_dis;
3434
3435- /* ops is the gate ops, but with our enable/disable functions */
3436- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3437- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3438- clk_gate_fn_ops = clk_gate_ops;
3439- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3440- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3441- }
3442-
3443 clk = clk_register(dev, &gate_fn->gate.hw);
3444
3445 if (IS_ERR(clk))
3446diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3447index 827d1500..2885dc6 100644
3448--- a/arch/arm/mach-omap2/board-n8x0.c
3449+++ b/arch/arm/mach-omap2/board-n8x0.c
3450@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3451 }
3452 #endif
3453
3454-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3455+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3456 .late_init = n8x0_menelaus_late_init,
3457 };
3458
3459diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3460index d24926e..a7645a6 100644
3461--- a/arch/arm/mach-omap2/gpmc.c
3462+++ b/arch/arm/mach-omap2/gpmc.c
3463@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3464 };
3465
3466 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3467-static struct irq_chip gpmc_irq_chip;
3468 static int gpmc_irq_start;
3469
3470 static struct resource gpmc_mem_root;
3471@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3472
3473 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3474
3475+static struct irq_chip gpmc_irq_chip = {
3476+ .name = "gpmc",
3477+ .irq_startup = gpmc_irq_noop_ret,
3478+ .irq_enable = gpmc_irq_enable,
3479+ .irq_disable = gpmc_irq_disable,
3480+ .irq_shutdown = gpmc_irq_noop,
3481+ .irq_ack = gpmc_irq_noop,
3482+ .irq_mask = gpmc_irq_noop,
3483+ .irq_unmask = gpmc_irq_noop,
3484+
3485+};
3486+
3487 static int gpmc_setup_irq(void)
3488 {
3489 int i;
3490@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3491 return gpmc_irq_start;
3492 }
3493
3494- gpmc_irq_chip.name = "gpmc";
3495- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3496- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3497- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3498- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3499- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3500- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3501- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3502-
3503 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3504 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3505
3506diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3507index f991016..145ebeb 100644
3508--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3509+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3510@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3511 int (*finish_suspend)(unsigned long cpu_state);
3512 void (*resume)(void);
3513 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3514-};
3515+} __no_const;
3516
3517 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3518 static struct powerdomain *mpuss_pd;
3519@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3520 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3521 {}
3522
3523-struct cpu_pm_ops omap_pm_ops = {
3524+static struct cpu_pm_ops omap_pm_ops __read_only = {
3525 .finish_suspend = default_finish_suspend,
3526 .resume = dummy_cpu_resume,
3527 .scu_prepare = dummy_scu_prepare,
3528diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3529index 3664562..72f85c6 100644
3530--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3531+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3532@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3533 return NOTIFY_OK;
3534 }
3535
3536-static struct notifier_block __refdata irq_hotplug_notifier = {
3537+static struct notifier_block irq_hotplug_notifier = {
3538 .notifier_call = irq_cpu_hotplug_notify,
3539 };
3540
3541diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3542index e0a398c..a470fa5 100644
3543--- a/arch/arm/mach-omap2/omap_device.c
3544+++ b/arch/arm/mach-omap2/omap_device.c
3545@@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3546 struct platform_device __init *omap_device_build(const char *pdev_name,
3547 int pdev_id,
3548 struct omap_hwmod *oh,
3549- void *pdata, int pdata_len)
3550+ const void *pdata, int pdata_len)
3551 {
3552 struct omap_hwmod *ohs[] = { oh };
3553
3554@@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3555 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3556 int pdev_id,
3557 struct omap_hwmod **ohs,
3558- int oh_cnt, void *pdata,
3559+ int oh_cnt, const void *pdata,
3560 int pdata_len)
3561 {
3562 int ret = -ENOMEM;
3563diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3564index 78c02b3..c94109a 100644
3565--- a/arch/arm/mach-omap2/omap_device.h
3566+++ b/arch/arm/mach-omap2/omap_device.h
3567@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3568 /* Core code interface */
3569
3570 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3571- struct omap_hwmod *oh, void *pdata,
3572+ struct omap_hwmod *oh, const void *pdata,
3573 int pdata_len);
3574
3575 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3576 struct omap_hwmod **oh, int oh_cnt,
3577- void *pdata, int pdata_len);
3578+ const void *pdata, int pdata_len);
3579
3580 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3581 struct omap_hwmod **ohs, int oh_cnt);
3582diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3583index 8a1b5e0..5f30074 100644
3584--- a/arch/arm/mach-omap2/omap_hwmod.c
3585+++ b/arch/arm/mach-omap2/omap_hwmod.c
3586@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3587 int (*init_clkdm)(struct omap_hwmod *oh);
3588 void (*update_context_lost)(struct omap_hwmod *oh);
3589 int (*get_context_lost)(struct omap_hwmod *oh);
3590-};
3591+} __no_const;
3592
3593 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3594-static struct omap_hwmod_soc_ops soc_ops;
3595+static struct omap_hwmod_soc_ops soc_ops __read_only;
3596
3597 /* omap_hwmod_list contains all registered struct omap_hwmods */
3598 static LIST_HEAD(omap_hwmod_list);
3599diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3600index d15c7bb..b2d1f0c 100644
3601--- a/arch/arm/mach-omap2/wd_timer.c
3602+++ b/arch/arm/mach-omap2/wd_timer.c
3603@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3604 struct omap_hwmod *oh;
3605 char *oh_name = "wd_timer2";
3606 char *dev_name = "omap_wdt";
3607- struct omap_wd_timer_platform_data pdata;
3608+ static struct omap_wd_timer_platform_data pdata = {
3609+ .read_reset_sources = prm_read_reset_sources
3610+ };
3611
3612 if (!cpu_class_is_omap2() || of_have_populated_dt())
3613 return 0;
3614@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3615 return -EINVAL;
3616 }
3617
3618- pdata.read_reset_sources = prm_read_reset_sources;
3619-
3620 pdev = omap_device_build(dev_name, id, oh, &pdata,
3621 sizeof(struct omap_wd_timer_platform_data));
3622 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3623diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3624index b82dcae..44ee5b6 100644
3625--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3626+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3627@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3628 bool entered_lp2 = false;
3629
3630 if (tegra_pending_sgi())
3631- ACCESS_ONCE(abort_flag) = true;
3632+ ACCESS_ONCE_RW(abort_flag) = true;
3633
3634 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3635
3636diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3637index bdb3564..cebb96f 100644
3638--- a/arch/arm/mach-ux500/setup.h
3639+++ b/arch/arm/mach-ux500/setup.h
3640@@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3641 .type = MT_DEVICE, \
3642 }
3643
3644-#define __MEM_DEV_DESC(x, sz) { \
3645- .virtual = IO_ADDRESS(x), \
3646- .pfn = __phys_to_pfn(x), \
3647- .length = sz, \
3648- .type = MT_MEMORY, \
3649-}
3650-
3651 extern struct smp_operations ux500_smp_ops;
3652 extern void ux500_cpu_die(unsigned int cpu);
3653
3654diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3655index 1f8fed9..14d7823 100644
3656--- a/arch/arm/mm/Kconfig
3657+++ b/arch/arm/mm/Kconfig
3658@@ -446,7 +446,7 @@ config CPU_32v5
3659
3660 config CPU_32v6
3661 bool
3662- select CPU_USE_DOMAINS if CPU_V6 && MMU
3663+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3664 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3665
3666 config CPU_32v6K
3667@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3668
3669 config CPU_USE_DOMAINS
3670 bool
3671+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3672 help
3673 This option enables or disables the use of domain switching
3674 via the set_fs() function.
3675@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3676 config KUSER_HELPERS
3677 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3678 default y
3679+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3680 help
3681 Warning: disabling this option may break user programs.
3682
3683@@ -812,7 +814,7 @@ config KUSER_HELPERS
3684 See Documentation/arm/kernel_user_helpers.txt for details.
3685
3686 However, the fixed address nature of these helpers can be used
3687- by ROP (return orientated programming) authors when creating
3688+ by ROP (Return Oriented Programming) authors when creating
3689 exploits.
3690
3691 If all of the binaries and libraries which run on your platform
3692diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3693index 9240364..a2b8cf3 100644
3694--- a/arch/arm/mm/alignment.c
3695+++ b/arch/arm/mm/alignment.c
3696@@ -212,10 +212,12 @@ union offset_union {
3697 #define __get16_unaligned_check(ins,val,addr) \
3698 do { \
3699 unsigned int err = 0, v, a = addr; \
3700+ pax_open_userland(); \
3701 __get8_unaligned_check(ins,v,a,err); \
3702 val = v << ((BE) ? 8 : 0); \
3703 __get8_unaligned_check(ins,v,a,err); \
3704 val |= v << ((BE) ? 0 : 8); \
3705+ pax_close_userland(); \
3706 if (err) \
3707 goto fault; \
3708 } while (0)
3709@@ -229,6 +231,7 @@ union offset_union {
3710 #define __get32_unaligned_check(ins,val,addr) \
3711 do { \
3712 unsigned int err = 0, v, a = addr; \
3713+ pax_open_userland(); \
3714 __get8_unaligned_check(ins,v,a,err); \
3715 val = v << ((BE) ? 24 : 0); \
3716 __get8_unaligned_check(ins,v,a,err); \
3717@@ -237,6 +240,7 @@ union offset_union {
3718 val |= v << ((BE) ? 8 : 16); \
3719 __get8_unaligned_check(ins,v,a,err); \
3720 val |= v << ((BE) ? 0 : 24); \
3721+ pax_close_userland(); \
3722 if (err) \
3723 goto fault; \
3724 } while (0)
3725@@ -250,6 +254,7 @@ union offset_union {
3726 #define __put16_unaligned_check(ins,val,addr) \
3727 do { \
3728 unsigned int err = 0, v = val, a = addr; \
3729+ pax_open_userland(); \
3730 __asm__( FIRST_BYTE_16 \
3731 ARM( "1: "ins" %1, [%2], #1\n" ) \
3732 THUMB( "1: "ins" %1, [%2]\n" ) \
3733@@ -269,6 +274,7 @@ union offset_union {
3734 " .popsection\n" \
3735 : "=r" (err), "=&r" (v), "=&r" (a) \
3736 : "0" (err), "1" (v), "2" (a)); \
3737+ pax_close_userland(); \
3738 if (err) \
3739 goto fault; \
3740 } while (0)
3741@@ -282,6 +288,7 @@ union offset_union {
3742 #define __put32_unaligned_check(ins,val,addr) \
3743 do { \
3744 unsigned int err = 0, v = val, a = addr; \
3745+ pax_open_userland(); \
3746 __asm__( FIRST_BYTE_32 \
3747 ARM( "1: "ins" %1, [%2], #1\n" ) \
3748 THUMB( "1: "ins" %1, [%2]\n" ) \
3749@@ -311,6 +318,7 @@ union offset_union {
3750 " .popsection\n" \
3751 : "=r" (err), "=&r" (v), "=&r" (a) \
3752 : "0" (err), "1" (v), "2" (a)); \
3753+ pax_close_userland(); \
3754 if (err) \
3755 goto fault; \
3756 } while (0)
3757diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3758index 447da6f..77a5057 100644
3759--- a/arch/arm/mm/cache-l2x0.c
3760+++ b/arch/arm/mm/cache-l2x0.c
3761@@ -45,7 +45,7 @@ struct l2x0_of_data {
3762 void (*setup)(const struct device_node *, u32 *, u32 *);
3763 void (*save)(void);
3764 struct outer_cache_fns outer_cache;
3765-};
3766+} __do_const;
3767
3768 static bool of_init = false;
3769
3770diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3771index 84e6f77..0b52f31 100644
3772--- a/arch/arm/mm/context.c
3773+++ b/arch/arm/mm/context.c
3774@@ -43,7 +43,7 @@
3775 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3776
3777 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3778-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3779+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3780 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3781
3782 static DEFINE_PER_CPU(atomic64_t, active_asids);
3783@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3784 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3785 {
3786 u64 asid = atomic64_read(&mm->context.id);
3787- u64 generation = atomic64_read(&asid_generation);
3788+ u64 generation = atomic64_read_unchecked(&asid_generation);
3789
3790 if (asid != 0 && is_reserved_asid(asid)) {
3791 /*
3792@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3793 */
3794 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3795 if (asid == NUM_USER_ASIDS) {
3796- generation = atomic64_add_return(ASID_FIRST_VERSION,
3797+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3798 &asid_generation);
3799 flush_context(cpu);
3800 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3801@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3802 cpu_set_reserved_ttbr0();
3803
3804 asid = atomic64_read(&mm->context.id);
3805- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3806+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3807 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3808 goto switch_mm_fastpath;
3809
3810 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3811 /* Check that our ASID belongs to the current generation. */
3812 asid = atomic64_read(&mm->context.id);
3813- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3814+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3815 asid = new_context(mm, cpu);
3816 atomic64_set(&mm->context.id, asid);
3817 }
3818diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3819index eb8830a..5360ce7 100644
3820--- a/arch/arm/mm/fault.c
3821+++ b/arch/arm/mm/fault.c
3822@@ -25,6 +25,7 @@
3823 #include <asm/system_misc.h>
3824 #include <asm/system_info.h>
3825 #include <asm/tlbflush.h>
3826+#include <asm/sections.h>
3827
3828 #include "fault.h"
3829
3830@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3831 if (fixup_exception(regs))
3832 return;
3833
3834+#ifdef CONFIG_PAX_MEMORY_UDEREF
3835+ if (addr < TASK_SIZE) {
3836+ if (current->signal->curr_ip)
3837+ 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),
3838+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3839+ else
3840+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3841+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3842+ }
3843+#endif
3844+
3845+#ifdef CONFIG_PAX_KERNEXEC
3846+ if ((fsr & FSR_WRITE) &&
3847+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3848+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3849+ {
3850+ if (current->signal->curr_ip)
3851+ 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),
3852+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3853+ else
3854+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3855+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3856+ }
3857+#endif
3858+
3859 /*
3860 * No handler, we'll have to terminate things with extreme prejudice.
3861 */
3862@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3863 }
3864 #endif
3865
3866+#ifdef CONFIG_PAX_PAGEEXEC
3867+ if (fsr & FSR_LNX_PF) {
3868+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3869+ do_group_exit(SIGKILL);
3870+ }
3871+#endif
3872+
3873 tsk->thread.address = addr;
3874 tsk->thread.error_code = fsr;
3875 tsk->thread.trap_no = 14;
3876@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3877 }
3878 #endif /* CONFIG_MMU */
3879
3880+#ifdef CONFIG_PAX_PAGEEXEC
3881+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3882+{
3883+ long i;
3884+
3885+ printk(KERN_ERR "PAX: bytes at PC: ");
3886+ for (i = 0; i < 20; i++) {
3887+ unsigned char c;
3888+ if (get_user(c, (__force unsigned char __user *)pc+i))
3889+ printk(KERN_CONT "?? ");
3890+ else
3891+ printk(KERN_CONT "%02x ", c);
3892+ }
3893+ printk("\n");
3894+
3895+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3896+ for (i = -1; i < 20; i++) {
3897+ unsigned long c;
3898+ if (get_user(c, (__force unsigned long __user *)sp+i))
3899+ printk(KERN_CONT "???????? ");
3900+ else
3901+ printk(KERN_CONT "%08lx ", c);
3902+ }
3903+ printk("\n");
3904+}
3905+#endif
3906+
3907 /*
3908 * First Level Translation Fault Handler
3909 *
3910@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3911 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3912 struct siginfo info;
3913
3914+#ifdef CONFIG_PAX_MEMORY_UDEREF
3915+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3916+ if (current->signal->curr_ip)
3917+ 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),
3918+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3919+ else
3920+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3921+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3922+ goto die;
3923+ }
3924+#endif
3925+
3926 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3927 return;
3928
3929+die:
3930 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3931 inf->name, fsr, addr);
3932
3933@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3934 ifsr_info[nr].name = name;
3935 }
3936
3937+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3938+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3939+
3940 asmlinkage void __exception
3941 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3942 {
3943 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3944 struct siginfo info;
3945+ unsigned long pc = instruction_pointer(regs);
3946+
3947+ if (user_mode(regs)) {
3948+ unsigned long sigpage = current->mm->context.sigpage;
3949+
3950+ if (sigpage <= pc && pc < sigpage + 7*4) {
3951+ if (pc < sigpage + 3*4)
3952+ sys_sigreturn(regs);
3953+ else
3954+ sys_rt_sigreturn(regs);
3955+ return;
3956+ }
3957+ if (pc == 0xffff0f60UL) {
3958+ /*
3959+ * PaX: __kuser_cmpxchg64 emulation
3960+ */
3961+ // TODO
3962+ //regs->ARM_pc = regs->ARM_lr;
3963+ //return;
3964+ }
3965+ if (pc == 0xffff0fa0UL) {
3966+ /*
3967+ * PaX: __kuser_memory_barrier emulation
3968+ */
3969+ // dmb(); implied by the exception
3970+ regs->ARM_pc = regs->ARM_lr;
3971+ return;
3972+ }
3973+ if (pc == 0xffff0fc0UL) {
3974+ /*
3975+ * PaX: __kuser_cmpxchg emulation
3976+ */
3977+ // TODO
3978+ //long new;
3979+ //int op;
3980+
3981+ //op = FUTEX_OP_SET << 28;
3982+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
3983+ //regs->ARM_r0 = old != new;
3984+ //regs->ARM_pc = regs->ARM_lr;
3985+ //return;
3986+ }
3987+ if (pc == 0xffff0fe0UL) {
3988+ /*
3989+ * PaX: __kuser_get_tls emulation
3990+ */
3991+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3992+ regs->ARM_pc = regs->ARM_lr;
3993+ return;
3994+ }
3995+ }
3996+
3997+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3998+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3999+ if (current->signal->curr_ip)
4000+ 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),
4001+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4002+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4003+ else
4004+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4005+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4006+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4007+ goto die;
4008+ }
4009+#endif
4010+
4011+#ifdef CONFIG_PAX_REFCOUNT
4012+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4013+ unsigned int bkpt;
4014+
4015+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4016+ current->thread.error_code = ifsr;
4017+ current->thread.trap_no = 0;
4018+ pax_report_refcount_overflow(regs);
4019+ fixup_exception(regs);
4020+ return;
4021+ }
4022+ }
4023+#endif
4024
4025 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4026 return;
4027
4028+die:
4029 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4030 inf->name, ifsr, addr);
4031
4032diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4033index cf08bdf..772656c 100644
4034--- a/arch/arm/mm/fault.h
4035+++ b/arch/arm/mm/fault.h
4036@@ -3,6 +3,7 @@
4037
4038 /*
4039 * Fault status register encodings. We steal bit 31 for our own purposes.
4040+ * Set when the FSR value is from an instruction fault.
4041 */
4042 #define FSR_LNX_PF (1 << 31)
4043 #define FSR_WRITE (1 << 11)
4044@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4045 }
4046 #endif
4047
4048+/* valid for LPAE and !LPAE */
4049+static inline int is_xn_fault(unsigned int fsr)
4050+{
4051+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4052+}
4053+
4054+static inline int is_domain_fault(unsigned int fsr)
4055+{
4056+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4057+}
4058+
4059 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4060 unsigned long search_exception_table(unsigned long addr);
4061
4062diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4063index 3e8f106..a0a1fe4 100644
4064--- a/arch/arm/mm/init.c
4065+++ b/arch/arm/mm/init.c
4066@@ -30,6 +30,8 @@
4067 #include <asm/setup.h>
4068 #include <asm/tlb.h>
4069 #include <asm/fixmap.h>
4070+#include <asm/system_info.h>
4071+#include <asm/cp15.h>
4072
4073 #include <asm/mach/arch.h>
4074 #include <asm/mach/map.h>
4075@@ -681,7 +683,46 @@ void free_initmem(void)
4076 {
4077 #ifdef CONFIG_HAVE_TCM
4078 extern char __tcm_start, __tcm_end;
4079+#endif
4080
4081+#ifdef CONFIG_PAX_KERNEXEC
4082+ unsigned long addr;
4083+ pgd_t *pgd;
4084+ pud_t *pud;
4085+ pmd_t *pmd;
4086+ int cpu_arch = cpu_architecture();
4087+ unsigned int cr = get_cr();
4088+
4089+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4090+ /* make pages tables, etc before .text NX */
4091+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4092+ pgd = pgd_offset_k(addr);
4093+ pud = pud_offset(pgd, addr);
4094+ pmd = pmd_offset(pud, addr);
4095+ __section_update(pmd, addr, PMD_SECT_XN);
4096+ }
4097+ /* make init NX */
4098+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4099+ pgd = pgd_offset_k(addr);
4100+ pud = pud_offset(pgd, addr);
4101+ pmd = pmd_offset(pud, addr);
4102+ __section_update(pmd, addr, PMD_SECT_XN);
4103+ }
4104+ /* make kernel code/rodata RX */
4105+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4106+ pgd = pgd_offset_k(addr);
4107+ pud = pud_offset(pgd, addr);
4108+ pmd = pmd_offset(pud, addr);
4109+#ifdef CONFIG_ARM_LPAE
4110+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4111+#else
4112+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4113+#endif
4114+ }
4115+ }
4116+#endif
4117+
4118+#ifdef CONFIG_HAVE_TCM
4119 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4120 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4121 #endif
4122diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4123index f123d6e..04bf569 100644
4124--- a/arch/arm/mm/ioremap.c
4125+++ b/arch/arm/mm/ioremap.c
4126@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4127 unsigned int mtype;
4128
4129 if (cached)
4130- mtype = MT_MEMORY;
4131+ mtype = MT_MEMORY_RX;
4132 else
4133- mtype = MT_MEMORY_NONCACHED;
4134+ mtype = MT_MEMORY_NONCACHED_RX;
4135
4136 return __arm_ioremap_caller(phys_addr, size, mtype,
4137 __builtin_return_address(0));
4138diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4139index 5e85ed3..b10a7ed 100644
4140--- a/arch/arm/mm/mmap.c
4141+++ b/arch/arm/mm/mmap.c
4142@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4143 struct vm_area_struct *vma;
4144 int do_align = 0;
4145 int aliasing = cache_is_vipt_aliasing();
4146+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4147 struct vm_unmapped_area_info info;
4148
4149 /*
4150@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4151 if (len > TASK_SIZE)
4152 return -ENOMEM;
4153
4154+#ifdef CONFIG_PAX_RANDMMAP
4155+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4156+#endif
4157+
4158 if (addr) {
4159 if (do_align)
4160 addr = COLOUR_ALIGN(addr, pgoff);
4161@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4162 addr = PAGE_ALIGN(addr);
4163
4164 vma = find_vma(mm, addr);
4165- if (TASK_SIZE - len >= addr &&
4166- (!vma || addr + len <= vma->vm_start))
4167+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4168 return addr;
4169 }
4170
4171@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4172 info.high_limit = TASK_SIZE;
4173 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4174 info.align_offset = pgoff << PAGE_SHIFT;
4175+ info.threadstack_offset = offset;
4176 return vm_unmapped_area(&info);
4177 }
4178
4179@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4180 unsigned long addr = addr0;
4181 int do_align = 0;
4182 int aliasing = cache_is_vipt_aliasing();
4183+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4184 struct vm_unmapped_area_info info;
4185
4186 /*
4187@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4188 return addr;
4189 }
4190
4191+#ifdef CONFIG_PAX_RANDMMAP
4192+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4193+#endif
4194+
4195 /* requesting a specific address */
4196 if (addr) {
4197 if (do_align)
4198@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4199 else
4200 addr = PAGE_ALIGN(addr);
4201 vma = find_vma(mm, addr);
4202- if (TASK_SIZE - len >= addr &&
4203- (!vma || addr + len <= vma->vm_start))
4204+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4205 return addr;
4206 }
4207
4208@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4209 info.high_limit = mm->mmap_base;
4210 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4211 info.align_offset = pgoff << PAGE_SHIFT;
4212+ info.threadstack_offset = offset;
4213 addr = vm_unmapped_area(&info);
4214
4215 /*
4216@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4217 {
4218 unsigned long random_factor = 0UL;
4219
4220+#ifdef CONFIG_PAX_RANDMMAP
4221+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4222+#endif
4223+
4224 /* 8 bits of randomness in 20 address space bits */
4225 if ((current->flags & PF_RANDOMIZE) &&
4226 !(current->personality & ADDR_NO_RANDOMIZE))
4227@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4228
4229 if (mmap_is_legacy()) {
4230 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4231+
4232+#ifdef CONFIG_PAX_RANDMMAP
4233+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4234+ mm->mmap_base += mm->delta_mmap;
4235+#endif
4236+
4237 mm->get_unmapped_area = arch_get_unmapped_area;
4238 } else {
4239 mm->mmap_base = mmap_base(random_factor);
4240+
4241+#ifdef CONFIG_PAX_RANDMMAP
4242+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4243+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4244+#endif
4245+
4246 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4247 }
4248 }
4249diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4250index 580ef2d..2da06ca 100644
4251--- a/arch/arm/mm/mmu.c
4252+++ b/arch/arm/mm/mmu.c
4253@@ -38,6 +38,22 @@
4254 #include "mm.h"
4255 #include "tcm.h"
4256
4257+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4258+void modify_domain(unsigned int dom, unsigned int type)
4259+{
4260+ struct thread_info *thread = current_thread_info();
4261+ unsigned int domain = thread->cpu_domain;
4262+ /*
4263+ * DOMAIN_MANAGER might be defined to some other value,
4264+ * use the arch-defined constant
4265+ */
4266+ domain &= ~domain_val(dom, 3);
4267+ thread->cpu_domain = domain | domain_val(dom, type);
4268+ set_domain(thread->cpu_domain);
4269+}
4270+EXPORT_SYMBOL(modify_domain);
4271+#endif
4272+
4273 /*
4274 * empty_zero_page is a special page that is used for
4275 * zero-initialized data and COW.
4276@@ -230,10 +246,18 @@ __setup("noalign", noalign_setup);
4277
4278 #endif /* ifdef CONFIG_CPU_CP15 / else */
4279
4280-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4281+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4282 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4283
4284-static struct mem_type mem_types[] = {
4285+#ifdef CONFIG_PAX_KERNEXEC
4286+#define L_PTE_KERNEXEC L_PTE_RDONLY
4287+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4288+#else
4289+#define L_PTE_KERNEXEC L_PTE_DIRTY
4290+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4291+#endif
4292+
4293+static struct mem_type mem_types[] __read_only = {
4294 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4295 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4296 L_PTE_SHARED,
4297@@ -262,16 +286,16 @@ static struct mem_type mem_types[] = {
4298 [MT_UNCACHED] = {
4299 .prot_pte = PROT_PTE_DEVICE,
4300 .prot_l1 = PMD_TYPE_TABLE,
4301- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4302+ .prot_sect = PROT_SECT_DEVICE,
4303 .domain = DOMAIN_IO,
4304 },
4305 [MT_CACHECLEAN] = {
4306- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4307+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4308 .domain = DOMAIN_KERNEL,
4309 },
4310 #ifndef CONFIG_ARM_LPAE
4311 [MT_MINICLEAN] = {
4312- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4313+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4314 .domain = DOMAIN_KERNEL,
4315 },
4316 #endif
4317@@ -279,36 +303,54 @@ static struct mem_type mem_types[] = {
4318 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4319 L_PTE_RDONLY,
4320 .prot_l1 = PMD_TYPE_TABLE,
4321- .domain = DOMAIN_USER,
4322+ .domain = DOMAIN_VECTORS,
4323 },
4324 [MT_HIGH_VECTORS] = {
4325 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4326 L_PTE_USER | L_PTE_RDONLY,
4327 .prot_l1 = PMD_TYPE_TABLE,
4328- .domain = DOMAIN_USER,
4329+ .domain = DOMAIN_VECTORS,
4330 },
4331- [MT_MEMORY] = {
4332+ [MT_MEMORY_RWX] = {
4333 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4334 .prot_l1 = PMD_TYPE_TABLE,
4335 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4336 .domain = DOMAIN_KERNEL,
4337 },
4338+ [MT_MEMORY_RW] = {
4339+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4340+ .prot_l1 = PMD_TYPE_TABLE,
4341+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4342+ .domain = DOMAIN_KERNEL,
4343+ },
4344+ [MT_MEMORY_RX] = {
4345+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4346+ .prot_l1 = PMD_TYPE_TABLE,
4347+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4348+ .domain = DOMAIN_KERNEL,
4349+ },
4350 [MT_ROM] = {
4351- .prot_sect = PMD_TYPE_SECT,
4352+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4353 .domain = DOMAIN_KERNEL,
4354 },
4355- [MT_MEMORY_NONCACHED] = {
4356+ [MT_MEMORY_NONCACHED_RW] = {
4357 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4358 L_PTE_MT_BUFFERABLE,
4359 .prot_l1 = PMD_TYPE_TABLE,
4360 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4361 .domain = DOMAIN_KERNEL,
4362 },
4363+ [MT_MEMORY_NONCACHED_RX] = {
4364+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4365+ L_PTE_MT_BUFFERABLE,
4366+ .prot_l1 = PMD_TYPE_TABLE,
4367+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4368+ .domain = DOMAIN_KERNEL,
4369+ },
4370 [MT_MEMORY_DTCM] = {
4371- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4372- L_PTE_XN,
4373+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4374 .prot_l1 = PMD_TYPE_TABLE,
4375- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4376+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4377 .domain = DOMAIN_KERNEL,
4378 },
4379 [MT_MEMORY_ITCM] = {
4380@@ -318,10 +360,10 @@ static struct mem_type mem_types[] = {
4381 },
4382 [MT_MEMORY_SO] = {
4383 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4384- L_PTE_MT_UNCACHED | L_PTE_XN,
4385+ L_PTE_MT_UNCACHED,
4386 .prot_l1 = PMD_TYPE_TABLE,
4387 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4388- PMD_SECT_UNCACHED | PMD_SECT_XN,
4389+ PMD_SECT_UNCACHED,
4390 .domain = DOMAIN_KERNEL,
4391 },
4392 [MT_MEMORY_DMA_READY] = {
4393@@ -407,9 +449,35 @@ static void __init build_mem_type_table(void)
4394 * to prevent speculative instruction fetches.
4395 */
4396 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4397+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4398 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4399+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4400 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4401+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4402 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4403+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4404+
4405+ /* Mark other regions on ARMv6+ as execute-never */
4406+
4407+#ifdef CONFIG_PAX_KERNEXEC
4408+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4409+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4410+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4411+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4412+#ifndef CONFIG_ARM_LPAE
4413+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4414+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4415+#endif
4416+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4417+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4418+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4419+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4420+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4421+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4422+#endif
4423+
4424+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4425+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4426 }
4427 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4428 /*
4429@@ -470,6 +538,9 @@ static void __init build_mem_type_table(void)
4430 * from SVC mode and no access from userspace.
4431 */
4432 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4433+#ifdef CONFIG_PAX_KERNEXEC
4434+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4435+#endif
4436 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4438 #endif
4439@@ -487,11 +558,17 @@ static void __init build_mem_type_table(void)
4440 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4441 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4442 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4443- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4444- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4445+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4446+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4447+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4448+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4449+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4450+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4451 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4452- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4453- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4454+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4455+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4456+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4457+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4458 }
4459 }
4460
4461@@ -502,15 +579,20 @@ static void __init build_mem_type_table(void)
4462 if (cpu_arch >= CPU_ARCH_ARMv6) {
4463 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4464 /* Non-cacheable Normal is XCB = 001 */
4465- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4466+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4467+ PMD_SECT_BUFFERED;
4468+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4469 PMD_SECT_BUFFERED;
4470 } else {
4471 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4472- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4473+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4474+ PMD_SECT_TEX(1);
4475+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4476 PMD_SECT_TEX(1);
4477 }
4478 } else {
4479- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4480+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4481+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4482 }
4483
4484 #ifdef CONFIG_ARM_LPAE
4485@@ -526,6 +608,8 @@ static void __init build_mem_type_table(void)
4486 vecs_pgprot |= PTE_EXT_AF;
4487 #endif
4488
4489+ user_pgprot |= __supported_pte_mask;
4490+
4491 for (i = 0; i < 16; i++) {
4492 pteval_t v = pgprot_val(protection_map[i]);
4493 protection_map[i] = __pgprot(v | user_pgprot);
4494@@ -543,10 +627,15 @@ static void __init build_mem_type_table(void)
4495
4496 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4497 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4498- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4499- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4500+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4501+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4502+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4503+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4504+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4505+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4506 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4507- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4508+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4509+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4510 mem_types[MT_ROM].prot_sect |= cp->pmd;
4511
4512 switch (cp->pmd) {
4513@@ -1188,18 +1277,15 @@ void __init arm_mm_memblock_reserve(void)
4514 * called function. This means you can't use any function or debugging
4515 * method which may touch any device, otherwise the kernel _will_ crash.
4516 */
4517+
4518+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4519+
4520 static void __init devicemaps_init(const struct machine_desc *mdesc)
4521 {
4522 struct map_desc map;
4523 unsigned long addr;
4524- void *vectors;
4525
4526- /*
4527- * Allocate the vector page early.
4528- */
4529- vectors = early_alloc(PAGE_SIZE * 2);
4530-
4531- early_trap_init(vectors);
4532+ early_trap_init(&vectors);
4533
4534 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4535 pmd_clear(pmd_off_k(addr));
4536@@ -1239,7 +1325,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4537 * location (0xffff0000). If we aren't using high-vectors, also
4538 * create a mapping at the low-vectors virtual address.
4539 */
4540- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4541+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4542 map.virtual = 0xffff0000;
4543 map.length = PAGE_SIZE;
4544 #ifdef CONFIG_KUSER_HELPERS
4545@@ -1311,8 +1397,39 @@ static void __init map_lowmem(void)
4546 map.pfn = __phys_to_pfn(start);
4547 map.virtual = __phys_to_virt(start);
4548 map.length = end - start;
4549- map.type = MT_MEMORY;
4550
4551+#ifdef CONFIG_PAX_KERNEXEC
4552+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4553+ struct map_desc kernel;
4554+ struct map_desc initmap;
4555+
4556+ /* when freeing initmem we will make this RW */
4557+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4558+ initmap.virtual = (unsigned long)__init_begin;
4559+ initmap.length = _sdata - __init_begin;
4560+ initmap.type = MT_MEMORY_RWX;
4561+ create_mapping(&initmap);
4562+
4563+ /* when freeing initmem we will make this RX */
4564+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4565+ kernel.virtual = (unsigned long)_stext;
4566+ kernel.length = __init_begin - _stext;
4567+ kernel.type = MT_MEMORY_RWX;
4568+ create_mapping(&kernel);
4569+
4570+ if (map.virtual < (unsigned long)_stext) {
4571+ map.length = (unsigned long)_stext - map.virtual;
4572+ map.type = MT_MEMORY_RWX;
4573+ create_mapping(&map);
4574+ }
4575+
4576+ map.pfn = __phys_to_pfn(__pa(_sdata));
4577+ map.virtual = (unsigned long)_sdata;
4578+ map.length = end - __pa(_sdata);
4579+ }
4580+#endif
4581+
4582+ map.type = MT_MEMORY_RW;
4583 create_mapping(&map);
4584 }
4585 }
4586diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4587index a5bc92d..0bb4730 100644
4588--- a/arch/arm/plat-omap/sram.c
4589+++ b/arch/arm/plat-omap/sram.c
4590@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4591 * Looks like we need to preserve some bootloader code at the
4592 * beginning of SRAM for jumping to flash for reboot to work...
4593 */
4594+ pax_open_kernel();
4595 memset_io(omap_sram_base + omap_sram_skip, 0,
4596 omap_sram_size - omap_sram_skip);
4597+ pax_close_kernel();
4598 }
4599diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4600index ce6d763..cfea917 100644
4601--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4602+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4603@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4604 int (*started)(unsigned ch);
4605 int (*flush)(unsigned ch);
4606 int (*stop)(unsigned ch);
4607-};
4608+} __no_const;
4609
4610 extern void *samsung_dmadev_get_ops(void);
4611 extern void *s3c_dma_get_ops(void);
4612diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4613index c3a58a1..78fbf54 100644
4614--- a/arch/avr32/include/asm/cache.h
4615+++ b/arch/avr32/include/asm/cache.h
4616@@ -1,8 +1,10 @@
4617 #ifndef __ASM_AVR32_CACHE_H
4618 #define __ASM_AVR32_CACHE_H
4619
4620+#include <linux/const.h>
4621+
4622 #define L1_CACHE_SHIFT 5
4623-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4624+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4625
4626 /*
4627 * Memory returned by kmalloc() may be used for DMA, so we must make
4628diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4629index d232888..87c8df1 100644
4630--- a/arch/avr32/include/asm/elf.h
4631+++ b/arch/avr32/include/asm/elf.h
4632@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4633 the loader. We need to make sure that it is out of the way of the program
4634 that it will "exec", and that there is sufficient room for the brk. */
4635
4636-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4637+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4638
4639+#ifdef CONFIG_PAX_ASLR
4640+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4641+
4642+#define PAX_DELTA_MMAP_LEN 15
4643+#define PAX_DELTA_STACK_LEN 15
4644+#endif
4645
4646 /* This yields a mask that user programs can use to figure out what
4647 instruction set this CPU supports. This could be done in user space,
4648diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4649index 479330b..53717a8 100644
4650--- a/arch/avr32/include/asm/kmap_types.h
4651+++ b/arch/avr32/include/asm/kmap_types.h
4652@@ -2,9 +2,9 @@
4653 #define __ASM_AVR32_KMAP_TYPES_H
4654
4655 #ifdef CONFIG_DEBUG_HIGHMEM
4656-# define KM_TYPE_NR 29
4657+# define KM_TYPE_NR 30
4658 #else
4659-# define KM_TYPE_NR 14
4660+# define KM_TYPE_NR 15
4661 #endif
4662
4663 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4664diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4665index 0eca933..eb78c7b 100644
4666--- a/arch/avr32/mm/fault.c
4667+++ b/arch/avr32/mm/fault.c
4668@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4669
4670 int exception_trace = 1;
4671
4672+#ifdef CONFIG_PAX_PAGEEXEC
4673+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4674+{
4675+ unsigned long i;
4676+
4677+ printk(KERN_ERR "PAX: bytes at PC: ");
4678+ for (i = 0; i < 20; i++) {
4679+ unsigned char c;
4680+ if (get_user(c, (unsigned char *)pc+i))
4681+ printk(KERN_CONT "???????? ");
4682+ else
4683+ printk(KERN_CONT "%02x ", c);
4684+ }
4685+ printk("\n");
4686+}
4687+#endif
4688+
4689 /*
4690 * This routine handles page faults. It determines the address and the
4691 * problem, and then passes it off to one of the appropriate routines.
4692@@ -176,6 +193,16 @@ bad_area:
4693 up_read(&mm->mmap_sem);
4694
4695 if (user_mode(regs)) {
4696+
4697+#ifdef CONFIG_PAX_PAGEEXEC
4698+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4699+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4700+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4701+ do_group_exit(SIGKILL);
4702+ }
4703+ }
4704+#endif
4705+
4706 if (exception_trace && printk_ratelimit())
4707 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4708 "sp %08lx ecr %lu\n",
4709diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4710index 568885a..f8008df 100644
4711--- a/arch/blackfin/include/asm/cache.h
4712+++ b/arch/blackfin/include/asm/cache.h
4713@@ -7,6 +7,7 @@
4714 #ifndef __ARCH_BLACKFIN_CACHE_H
4715 #define __ARCH_BLACKFIN_CACHE_H
4716
4717+#include <linux/const.h>
4718 #include <linux/linkage.h> /* for asmlinkage */
4719
4720 /*
4721@@ -14,7 +15,7 @@
4722 * Blackfin loads 32 bytes for cache
4723 */
4724 #define L1_CACHE_SHIFT 5
4725-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4726+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4727 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4728
4729 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4730diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4731index aea2718..3639a60 100644
4732--- a/arch/cris/include/arch-v10/arch/cache.h
4733+++ b/arch/cris/include/arch-v10/arch/cache.h
4734@@ -1,8 +1,9 @@
4735 #ifndef _ASM_ARCH_CACHE_H
4736 #define _ASM_ARCH_CACHE_H
4737
4738+#include <linux/const.h>
4739 /* Etrax 100LX have 32-byte cache-lines. */
4740-#define L1_CACHE_BYTES 32
4741 #define L1_CACHE_SHIFT 5
4742+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4743
4744 #endif /* _ASM_ARCH_CACHE_H */
4745diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4746index 7caf25d..ee65ac5 100644
4747--- a/arch/cris/include/arch-v32/arch/cache.h
4748+++ b/arch/cris/include/arch-v32/arch/cache.h
4749@@ -1,11 +1,12 @@
4750 #ifndef _ASM_CRIS_ARCH_CACHE_H
4751 #define _ASM_CRIS_ARCH_CACHE_H
4752
4753+#include <linux/const.h>
4754 #include <arch/hwregs/dma.h>
4755
4756 /* A cache-line is 32 bytes. */
4757-#define L1_CACHE_BYTES 32
4758 #define L1_CACHE_SHIFT 5
4759+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4760
4761 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4762
4763diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4764index b86329d..6709906 100644
4765--- a/arch/frv/include/asm/atomic.h
4766+++ b/arch/frv/include/asm/atomic.h
4767@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4768 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4769 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4770
4771+#define atomic64_read_unchecked(v) atomic64_read(v)
4772+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4773+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4774+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4775+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4776+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4777+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4778+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4779+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4780+
4781 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4782 {
4783 int c, old;
4784diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4785index 2797163..c2a401d 100644
4786--- a/arch/frv/include/asm/cache.h
4787+++ b/arch/frv/include/asm/cache.h
4788@@ -12,10 +12,11 @@
4789 #ifndef __ASM_CACHE_H
4790 #define __ASM_CACHE_H
4791
4792+#include <linux/const.h>
4793
4794 /* bytes per L1 cache line */
4795 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4796-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4797+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4798
4799 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4800 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4801diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4802index 43901f2..0d8b865 100644
4803--- a/arch/frv/include/asm/kmap_types.h
4804+++ b/arch/frv/include/asm/kmap_types.h
4805@@ -2,6 +2,6 @@
4806 #ifndef _ASM_KMAP_TYPES_H
4807 #define _ASM_KMAP_TYPES_H
4808
4809-#define KM_TYPE_NR 17
4810+#define KM_TYPE_NR 18
4811
4812 #endif
4813diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4814index 836f147..4cf23f5 100644
4815--- a/arch/frv/mm/elf-fdpic.c
4816+++ b/arch/frv/mm/elf-fdpic.c
4817@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4818 {
4819 struct vm_area_struct *vma;
4820 struct vm_unmapped_area_info info;
4821+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4822
4823 if (len > TASK_SIZE)
4824 return -ENOMEM;
4825@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4826 if (addr) {
4827 addr = PAGE_ALIGN(addr);
4828 vma = find_vma(current->mm, addr);
4829- if (TASK_SIZE - len >= addr &&
4830- (!vma || addr + len <= vma->vm_start))
4831+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4832 goto success;
4833 }
4834
4835@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4836 info.high_limit = (current->mm->start_stack - 0x00200000);
4837 info.align_mask = 0;
4838 info.align_offset = 0;
4839+ info.threadstack_offset = offset;
4840 addr = vm_unmapped_area(&info);
4841 if (!(addr & ~PAGE_MASK))
4842 goto success;
4843diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4844index f4ca594..adc72fd6 100644
4845--- a/arch/hexagon/include/asm/cache.h
4846+++ b/arch/hexagon/include/asm/cache.h
4847@@ -21,9 +21,11 @@
4848 #ifndef __ASM_CACHE_H
4849 #define __ASM_CACHE_H
4850
4851+#include <linux/const.h>
4852+
4853 /* Bytes per L1 cache line */
4854-#define L1_CACHE_SHIFT (5)
4855-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4856+#define L1_CACHE_SHIFT 5
4857+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4858
4859 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4860 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4861diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4862index 4e4119b..dd7de0a 100644
4863--- a/arch/ia64/Kconfig
4864+++ b/arch/ia64/Kconfig
4865@@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4866 config KEXEC
4867 bool "kexec system call"
4868 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4869+ depends on !GRKERNSEC_KMEM
4870 help
4871 kexec is a system call that implements the ability to shutdown your
4872 current kernel, and to start another kernel. It is like a reboot
4873diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4874index 6e6fe18..a6ae668 100644
4875--- a/arch/ia64/include/asm/atomic.h
4876+++ b/arch/ia64/include/asm/atomic.h
4877@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4878 #define atomic64_inc(v) atomic64_add(1, (v))
4879 #define atomic64_dec(v) atomic64_sub(1, (v))
4880
4881+#define atomic64_read_unchecked(v) atomic64_read(v)
4882+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4883+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4884+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4885+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4886+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4887+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4888+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4889+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4890+
4891 /* Atomic operations are already serializing */
4892 #define smp_mb__before_atomic_dec() barrier()
4893 #define smp_mb__after_atomic_dec() barrier()
4894diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4895index 988254a..e1ee885 100644
4896--- a/arch/ia64/include/asm/cache.h
4897+++ b/arch/ia64/include/asm/cache.h
4898@@ -1,6 +1,7 @@
4899 #ifndef _ASM_IA64_CACHE_H
4900 #define _ASM_IA64_CACHE_H
4901
4902+#include <linux/const.h>
4903
4904 /*
4905 * Copyright (C) 1998-2000 Hewlett-Packard Co
4906@@ -9,7 +10,7 @@
4907
4908 /* Bytes per L1 (data) cache line. */
4909 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4910-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4911+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4912
4913 #ifdef CONFIG_SMP
4914 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4915diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4916index 5a83c5c..4d7f553 100644
4917--- a/arch/ia64/include/asm/elf.h
4918+++ b/arch/ia64/include/asm/elf.h
4919@@ -42,6 +42,13 @@
4920 */
4921 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4922
4923+#ifdef CONFIG_PAX_ASLR
4924+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4925+
4926+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4927+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4928+#endif
4929+
4930 #define PT_IA_64_UNWIND 0x70000001
4931
4932 /* IA-64 relocations: */
4933diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4934index 5767cdf..7462574 100644
4935--- a/arch/ia64/include/asm/pgalloc.h
4936+++ b/arch/ia64/include/asm/pgalloc.h
4937@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4938 pgd_val(*pgd_entry) = __pa(pud);
4939 }
4940
4941+static inline void
4942+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4943+{
4944+ pgd_populate(mm, pgd_entry, pud);
4945+}
4946+
4947 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4948 {
4949 return quicklist_alloc(0, GFP_KERNEL, NULL);
4950@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4951 pud_val(*pud_entry) = __pa(pmd);
4952 }
4953
4954+static inline void
4955+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4956+{
4957+ pud_populate(mm, pud_entry, pmd);
4958+}
4959+
4960 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4961 {
4962 return quicklist_alloc(0, GFP_KERNEL, NULL);
4963diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4964index 7935115..c0eca6a 100644
4965--- a/arch/ia64/include/asm/pgtable.h
4966+++ b/arch/ia64/include/asm/pgtable.h
4967@@ -12,7 +12,7 @@
4968 * David Mosberger-Tang <davidm@hpl.hp.com>
4969 */
4970
4971-
4972+#include <linux/const.h>
4973 #include <asm/mman.h>
4974 #include <asm/page.h>
4975 #include <asm/processor.h>
4976@@ -142,6 +142,17 @@
4977 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4978 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4979 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4980+
4981+#ifdef CONFIG_PAX_PAGEEXEC
4982+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4983+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4984+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4985+#else
4986+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4987+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4988+# define PAGE_COPY_NOEXEC PAGE_COPY
4989+#endif
4990+
4991 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4992 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4993 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4994diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4995index 45698cd..e8e2dbc 100644
4996--- a/arch/ia64/include/asm/spinlock.h
4997+++ b/arch/ia64/include/asm/spinlock.h
4998@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4999 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5000
5001 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5002- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5003+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5004 }
5005
5006 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5007diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5008index 449c8c0..18965fb 100644
5009--- a/arch/ia64/include/asm/uaccess.h
5010+++ b/arch/ia64/include/asm/uaccess.h
5011@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5012 static inline unsigned long
5013 __copy_to_user (void __user *to, const void *from, unsigned long count)
5014 {
5015+ if (count > INT_MAX)
5016+ return count;
5017+
5018+ if (!__builtin_constant_p(count))
5019+ check_object_size(from, count, true);
5020+
5021 return __copy_user(to, (__force void __user *) from, count);
5022 }
5023
5024 static inline unsigned long
5025 __copy_from_user (void *to, const void __user *from, unsigned long count)
5026 {
5027+ if (count > INT_MAX)
5028+ return count;
5029+
5030+ if (!__builtin_constant_p(count))
5031+ check_object_size(to, count, false);
5032+
5033 return __copy_user((__force void __user *) to, from, count);
5034 }
5035
5036@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5037 ({ \
5038 void __user *__cu_to = (to); \
5039 const void *__cu_from = (from); \
5040- long __cu_len = (n); \
5041+ unsigned long __cu_len = (n); \
5042 \
5043- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5044+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5045+ if (!__builtin_constant_p(n)) \
5046+ check_object_size(__cu_from, __cu_len, true); \
5047 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5048+ } \
5049 __cu_len; \
5050 })
5051
5052@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5053 ({ \
5054 void *__cu_to = (to); \
5055 const void __user *__cu_from = (from); \
5056- long __cu_len = (n); \
5057+ unsigned long __cu_len = (n); \
5058 \
5059 __chk_user_ptr(__cu_from); \
5060- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5061+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5062+ if (!__builtin_constant_p(n)) \
5063+ check_object_size(__cu_to, __cu_len, false); \
5064 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5065+ } \
5066 __cu_len; \
5067 })
5068
5069diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5070index 24603be..948052d 100644
5071--- a/arch/ia64/kernel/module.c
5072+++ b/arch/ia64/kernel/module.c
5073@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5074 void
5075 module_free (struct module *mod, void *module_region)
5076 {
5077- if (mod && mod->arch.init_unw_table &&
5078- module_region == mod->module_init) {
5079+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5080 unw_remove_unwind_table(mod->arch.init_unw_table);
5081 mod->arch.init_unw_table = NULL;
5082 }
5083@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5084 }
5085
5086 static inline int
5087+in_init_rx (const struct module *mod, uint64_t addr)
5088+{
5089+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5090+}
5091+
5092+static inline int
5093+in_init_rw (const struct module *mod, uint64_t addr)
5094+{
5095+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5096+}
5097+
5098+static inline int
5099 in_init (const struct module *mod, uint64_t addr)
5100 {
5101- return addr - (uint64_t) mod->module_init < mod->init_size;
5102+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5103+}
5104+
5105+static inline int
5106+in_core_rx (const struct module *mod, uint64_t addr)
5107+{
5108+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5109+}
5110+
5111+static inline int
5112+in_core_rw (const struct module *mod, uint64_t addr)
5113+{
5114+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5115 }
5116
5117 static inline int
5118 in_core (const struct module *mod, uint64_t addr)
5119 {
5120- return addr - (uint64_t) mod->module_core < mod->core_size;
5121+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5122 }
5123
5124 static inline int
5125@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5126 break;
5127
5128 case RV_BDREL:
5129- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5130+ if (in_init_rx(mod, val))
5131+ val -= (uint64_t) mod->module_init_rx;
5132+ else if (in_init_rw(mod, val))
5133+ val -= (uint64_t) mod->module_init_rw;
5134+ else if (in_core_rx(mod, val))
5135+ val -= (uint64_t) mod->module_core_rx;
5136+ else if (in_core_rw(mod, val))
5137+ val -= (uint64_t) mod->module_core_rw;
5138 break;
5139
5140 case RV_LTV:
5141@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5142 * addresses have been selected...
5143 */
5144 uint64_t gp;
5145- if (mod->core_size > MAX_LTOFF)
5146+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5147 /*
5148 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5149 * at the end of the module.
5150 */
5151- gp = mod->core_size - MAX_LTOFF / 2;
5152+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5153 else
5154- gp = mod->core_size / 2;
5155- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5156+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5157+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5158 mod->arch.gp = gp;
5159 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5160 }
5161diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5162index ab33328..f39506c 100644
5163--- a/arch/ia64/kernel/palinfo.c
5164+++ b/arch/ia64/kernel/palinfo.c
5165@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5166 return NOTIFY_OK;
5167 }
5168
5169-static struct notifier_block __refdata palinfo_cpu_notifier =
5170+static struct notifier_block palinfo_cpu_notifier =
5171 {
5172 .notifier_call = palinfo_cpu_callback,
5173 .priority = 0,
5174diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5175index 41e33f8..65180b2a 100644
5176--- a/arch/ia64/kernel/sys_ia64.c
5177+++ b/arch/ia64/kernel/sys_ia64.c
5178@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5179 unsigned long align_mask = 0;
5180 struct mm_struct *mm = current->mm;
5181 struct vm_unmapped_area_info info;
5182+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5183
5184 if (len > RGN_MAP_LIMIT)
5185 return -ENOMEM;
5186@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5187 if (REGION_NUMBER(addr) == RGN_HPAGE)
5188 addr = 0;
5189 #endif
5190+
5191+#ifdef CONFIG_PAX_RANDMMAP
5192+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5193+ addr = mm->free_area_cache;
5194+ else
5195+#endif
5196+
5197 if (!addr)
5198 addr = TASK_UNMAPPED_BASE;
5199
5200@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5201 info.high_limit = TASK_SIZE;
5202 info.align_mask = align_mask;
5203 info.align_offset = 0;
5204+ info.threadstack_offset = offset;
5205 return vm_unmapped_area(&info);
5206 }
5207
5208diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5209index 0ccb28f..8992469 100644
5210--- a/arch/ia64/kernel/vmlinux.lds.S
5211+++ b/arch/ia64/kernel/vmlinux.lds.S
5212@@ -198,7 +198,7 @@ SECTIONS {
5213 /* Per-cpu data: */
5214 . = ALIGN(PERCPU_PAGE_SIZE);
5215 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5216- __phys_per_cpu_start = __per_cpu_load;
5217+ __phys_per_cpu_start = per_cpu_load;
5218 /*
5219 * ensure percpu data fits
5220 * into percpu page size
5221diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5222index 7225dad..2a7c8256 100644
5223--- a/arch/ia64/mm/fault.c
5224+++ b/arch/ia64/mm/fault.c
5225@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5226 return pte_present(pte);
5227 }
5228
5229+#ifdef CONFIG_PAX_PAGEEXEC
5230+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5231+{
5232+ unsigned long i;
5233+
5234+ printk(KERN_ERR "PAX: bytes at PC: ");
5235+ for (i = 0; i < 8; i++) {
5236+ unsigned int c;
5237+ if (get_user(c, (unsigned int *)pc+i))
5238+ printk(KERN_CONT "???????? ");
5239+ else
5240+ printk(KERN_CONT "%08x ", c);
5241+ }
5242+ printk("\n");
5243+}
5244+#endif
5245+
5246 # define VM_READ_BIT 0
5247 # define VM_WRITE_BIT 1
5248 # define VM_EXEC_BIT 2
5249@@ -151,8 +168,21 @@ retry:
5250 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5251 goto bad_area;
5252
5253- if ((vma->vm_flags & mask) != mask)
5254+ if ((vma->vm_flags & mask) != mask) {
5255+
5256+#ifdef CONFIG_PAX_PAGEEXEC
5257+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5258+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5259+ goto bad_area;
5260+
5261+ up_read(&mm->mmap_sem);
5262+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5263+ do_group_exit(SIGKILL);
5264+ }
5265+#endif
5266+
5267 goto bad_area;
5268+ }
5269
5270 /*
5271 * If for any reason at all we couldn't handle the fault, make
5272diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5273index 68232db..6ca80af 100644
5274--- a/arch/ia64/mm/hugetlbpage.c
5275+++ b/arch/ia64/mm/hugetlbpage.c
5276@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5277 unsigned long pgoff, unsigned long flags)
5278 {
5279 struct vm_unmapped_area_info info;
5280+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5281
5282 if (len > RGN_MAP_LIMIT)
5283 return -ENOMEM;
5284@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5285 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5286 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5287 info.align_offset = 0;
5288+ info.threadstack_offset = offset;
5289 return vm_unmapped_area(&info);
5290 }
5291
5292diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5293index 88504ab..cbb6c9f 100644
5294--- a/arch/ia64/mm/init.c
5295+++ b/arch/ia64/mm/init.c
5296@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5297 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5298 vma->vm_end = vma->vm_start + PAGE_SIZE;
5299 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5300+
5301+#ifdef CONFIG_PAX_PAGEEXEC
5302+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5303+ vma->vm_flags &= ~VM_EXEC;
5304+
5305+#ifdef CONFIG_PAX_MPROTECT
5306+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5307+ vma->vm_flags &= ~VM_MAYEXEC;
5308+#endif
5309+
5310+ }
5311+#endif
5312+
5313 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5314 down_write(&current->mm->mmap_sem);
5315 if (insert_vm_struct(current->mm, vma)) {
5316diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5317index 40b3ee9..8c2c112 100644
5318--- a/arch/m32r/include/asm/cache.h
5319+++ b/arch/m32r/include/asm/cache.h
5320@@ -1,8 +1,10 @@
5321 #ifndef _ASM_M32R_CACHE_H
5322 #define _ASM_M32R_CACHE_H
5323
5324+#include <linux/const.h>
5325+
5326 /* L1 cache line size */
5327 #define L1_CACHE_SHIFT 4
5328-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5329+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5330
5331 #endif /* _ASM_M32R_CACHE_H */
5332diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5333index 82abd15..d95ae5d 100644
5334--- a/arch/m32r/lib/usercopy.c
5335+++ b/arch/m32r/lib/usercopy.c
5336@@ -14,6 +14,9 @@
5337 unsigned long
5338 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5339 {
5340+ if ((long)n < 0)
5341+ return n;
5342+
5343 prefetch(from);
5344 if (access_ok(VERIFY_WRITE, to, n))
5345 __copy_user(to,from,n);
5346@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5347 unsigned long
5348 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5349 {
5350+ if ((long)n < 0)
5351+ return n;
5352+
5353 prefetchw(to);
5354 if (access_ok(VERIFY_READ, from, n))
5355 __copy_user_zeroing(to,from,n);
5356diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5357index 0395c51..5f26031 100644
5358--- a/arch/m68k/include/asm/cache.h
5359+++ b/arch/m68k/include/asm/cache.h
5360@@ -4,9 +4,11 @@
5361 #ifndef __ARCH_M68K_CACHE_H
5362 #define __ARCH_M68K_CACHE_H
5363
5364+#include <linux/const.h>
5365+
5366 /* bytes per L1 cache line */
5367 #define L1_CACHE_SHIFT 4
5368-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5369+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5370
5371 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5372
5373diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5374index 0424315..defcca9 100644
5375--- a/arch/metag/mm/hugetlbpage.c
5376+++ b/arch/metag/mm/hugetlbpage.c
5377@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5378 info.high_limit = TASK_SIZE;
5379 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5380 info.align_offset = 0;
5381+ info.threadstack_offset = 0;
5382 return vm_unmapped_area(&info);
5383 }
5384
5385diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5386index 4efe96a..60e8699 100644
5387--- a/arch/microblaze/include/asm/cache.h
5388+++ b/arch/microblaze/include/asm/cache.h
5389@@ -13,11 +13,12 @@
5390 #ifndef _ASM_MICROBLAZE_CACHE_H
5391 #define _ASM_MICROBLAZE_CACHE_H
5392
5393+#include <linux/const.h>
5394 #include <asm/registers.h>
5395
5396 #define L1_CACHE_SHIFT 5
5397 /* word-granular cache in microblaze */
5398-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5399+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5400
5401 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5402
5403diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5404index 650de39..6982b02 100644
5405--- a/arch/mips/Kconfig
5406+++ b/arch/mips/Kconfig
5407@@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5408
5409 config KEXEC
5410 bool "Kexec system call"
5411+ depends on !GRKERNSEC_KMEM
5412 help
5413 kexec is a system call that implements the ability to shutdown your
5414 current kernel, and to start another kernel. It is like a reboot
5415diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5416index 7eed2f2..c4e385d 100644
5417--- a/arch/mips/include/asm/atomic.h
5418+++ b/arch/mips/include/asm/atomic.h
5419@@ -21,15 +21,39 @@
5420 #include <asm/cmpxchg.h>
5421 #include <asm/war.h>
5422
5423+#ifdef CONFIG_GENERIC_ATOMIC64
5424+#include <asm-generic/atomic64.h>
5425+#endif
5426+
5427 #define ATOMIC_INIT(i) { (i) }
5428
5429+#ifdef CONFIG_64BIT
5430+#define _ASM_EXTABLE(from, to) \
5431+" .section __ex_table,\"a\"\n" \
5432+" .dword " #from ", " #to"\n" \
5433+" .previous\n"
5434+#else
5435+#define _ASM_EXTABLE(from, to) \
5436+" .section __ex_table,\"a\"\n" \
5437+" .word " #from ", " #to"\n" \
5438+" .previous\n"
5439+#endif
5440+
5441 /*
5442 * atomic_read - read atomic variable
5443 * @v: pointer of type atomic_t
5444 *
5445 * Atomically reads the value of @v.
5446 */
5447-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5448+static inline int atomic_read(const atomic_t *v)
5449+{
5450+ return (*(volatile const int *) &v->counter);
5451+}
5452+
5453+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5454+{
5455+ return (*(volatile const int *) &v->counter);
5456+}
5457
5458 /*
5459 * atomic_set - set atomic variable
5460@@ -38,7 +62,15 @@
5461 *
5462 * Atomically sets the value of @v to @i.
5463 */
5464-#define atomic_set(v, i) ((v)->counter = (i))
5465+static inline void atomic_set(atomic_t *v, int i)
5466+{
5467+ v->counter = i;
5468+}
5469+
5470+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5471+{
5472+ v->counter = i;
5473+}
5474
5475 /*
5476 * atomic_add - add integer to atomic variable
5477@@ -47,7 +79,67 @@
5478 *
5479 * Atomically adds @i to @v.
5480 */
5481-static __inline__ void atomic_add(int i, atomic_t * v)
5482+static __inline__ void atomic_add(int i, atomic_t *v)
5483+{
5484+ int temp;
5485+
5486+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5487+ __asm__ __volatile__(
5488+ " .set mips3 \n"
5489+ "1: ll %0, %1 # atomic_add \n"
5490+#ifdef CONFIG_PAX_REFCOUNT
5491+ /* Exception on overflow. */
5492+ "2: add %0, %2 \n"
5493+#else
5494+ " addu %0, %2 \n"
5495+#endif
5496+ " sc %0, %1 \n"
5497+ " beqzl %0, 1b \n"
5498+#ifdef CONFIG_PAX_REFCOUNT
5499+ "3: \n"
5500+ _ASM_EXTABLE(2b, 3b)
5501+#endif
5502+ " .set mips0 \n"
5503+ : "=&r" (temp), "+m" (v->counter)
5504+ : "Ir" (i));
5505+ } else if (kernel_uses_llsc) {
5506+ __asm__ __volatile__(
5507+ " .set mips3 \n"
5508+ "1: ll %0, %1 # atomic_add \n"
5509+#ifdef CONFIG_PAX_REFCOUNT
5510+ /* Exception on overflow. */
5511+ "2: add %0, %2 \n"
5512+#else
5513+ " addu %0, %2 \n"
5514+#endif
5515+ " sc %0, %1 \n"
5516+ " beqz %0, 1b \n"
5517+#ifdef CONFIG_PAX_REFCOUNT
5518+ "3: \n"
5519+ _ASM_EXTABLE(2b, 3b)
5520+#endif
5521+ " .set mips0 \n"
5522+ : "=&r" (temp), "+m" (v->counter)
5523+ : "Ir" (i));
5524+ } else {
5525+ unsigned long flags;
5526+
5527+ raw_local_irq_save(flags);
5528+ __asm__ __volatile__(
5529+#ifdef CONFIG_PAX_REFCOUNT
5530+ /* Exception on overflow. */
5531+ "1: add %0, %1 \n"
5532+ "2: \n"
5533+ _ASM_EXTABLE(1b, 2b)
5534+#else
5535+ " addu %0, %1 \n"
5536+#endif
5537+ : "+r" (v->counter) : "Ir" (i));
5538+ raw_local_irq_restore(flags);
5539+ }
5540+}
5541+
5542+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5543 {
5544 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5545 int temp;
5546@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5547 *
5548 * Atomically subtracts @i from @v.
5549 */
5550-static __inline__ void atomic_sub(int i, atomic_t * v)
5551+static __inline__ void atomic_sub(int i, atomic_t *v)
5552+{
5553+ int temp;
5554+
5555+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5556+ __asm__ __volatile__(
5557+ " .set mips3 \n"
5558+ "1: ll %0, %1 # atomic64_sub \n"
5559+#ifdef CONFIG_PAX_REFCOUNT
5560+ /* Exception on overflow. */
5561+ "2: sub %0, %2 \n"
5562+#else
5563+ " subu %0, %2 \n"
5564+#endif
5565+ " sc %0, %1 \n"
5566+ " beqzl %0, 1b \n"
5567+#ifdef CONFIG_PAX_REFCOUNT
5568+ "3: \n"
5569+ _ASM_EXTABLE(2b, 3b)
5570+#endif
5571+ " .set mips0 \n"
5572+ : "=&r" (temp), "+m" (v->counter)
5573+ : "Ir" (i));
5574+ } else if (kernel_uses_llsc) {
5575+ __asm__ __volatile__(
5576+ " .set mips3 \n"
5577+ "1: ll %0, %1 # atomic64_sub \n"
5578+#ifdef CONFIG_PAX_REFCOUNT
5579+ /* Exception on overflow. */
5580+ "2: sub %0, %2 \n"
5581+#else
5582+ " subu %0, %2 \n"
5583+#endif
5584+ " sc %0, %1 \n"
5585+ " beqz %0, 1b \n"
5586+#ifdef CONFIG_PAX_REFCOUNT
5587+ "3: \n"
5588+ _ASM_EXTABLE(2b, 3b)
5589+#endif
5590+ " .set mips0 \n"
5591+ : "=&r" (temp), "+m" (v->counter)
5592+ : "Ir" (i));
5593+ } else {
5594+ unsigned long flags;
5595+
5596+ raw_local_irq_save(flags);
5597+ __asm__ __volatile__(
5598+#ifdef CONFIG_PAX_REFCOUNT
5599+ /* Exception on overflow. */
5600+ "1: sub %0, %1 \n"
5601+ "2: \n"
5602+ _ASM_EXTABLE(1b, 2b)
5603+#else
5604+ " subu %0, %1 \n"
5605+#endif
5606+ : "+r" (v->counter) : "Ir" (i));
5607+ raw_local_irq_restore(flags);
5608+ }
5609+}
5610+
5611+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5612 {
5613 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5614 int temp;
5615@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5616 /*
5617 * Same as above, but return the result value
5618 */
5619-static __inline__ int atomic_add_return(int i, atomic_t * v)
5620+static __inline__ int atomic_add_return(int i, atomic_t *v)
5621+{
5622+ int result;
5623+ int temp;
5624+
5625+ smp_mb__before_llsc();
5626+
5627+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5628+ __asm__ __volatile__(
5629+ " .set mips3 \n"
5630+ "1: ll %1, %2 # atomic_add_return \n"
5631+#ifdef CONFIG_PAX_REFCOUNT
5632+ "2: add %0, %1, %3 \n"
5633+#else
5634+ " addu %0, %1, %3 \n"
5635+#endif
5636+ " sc %0, %2 \n"
5637+ " beqzl %0, 1b \n"
5638+#ifdef CONFIG_PAX_REFCOUNT
5639+ " b 4f \n"
5640+ " .set noreorder \n"
5641+ "3: b 5f \n"
5642+ " move %0, %1 \n"
5643+ " .set reorder \n"
5644+ _ASM_EXTABLE(2b, 3b)
5645+#endif
5646+ "4: addu %0, %1, %3 \n"
5647+#ifdef CONFIG_PAX_REFCOUNT
5648+ "5: \n"
5649+#endif
5650+ " .set mips0 \n"
5651+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5652+ : "Ir" (i));
5653+ } else if (kernel_uses_llsc) {
5654+ __asm__ __volatile__(
5655+ " .set mips3 \n"
5656+ "1: ll %1, %2 # atomic_add_return \n"
5657+#ifdef CONFIG_PAX_REFCOUNT
5658+ "2: add %0, %1, %3 \n"
5659+#else
5660+ " addu %0, %1, %3 \n"
5661+#endif
5662+ " sc %0, %2 \n"
5663+ " bnez %0, 4f \n"
5664+ " b 1b \n"
5665+#ifdef CONFIG_PAX_REFCOUNT
5666+ " .set noreorder \n"
5667+ "3: b 5f \n"
5668+ " move %0, %1 \n"
5669+ " .set reorder \n"
5670+ _ASM_EXTABLE(2b, 3b)
5671+#endif
5672+ "4: addu %0, %1, %3 \n"
5673+#ifdef CONFIG_PAX_REFCOUNT
5674+ "5: \n"
5675+#endif
5676+ " .set mips0 \n"
5677+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5678+ : "Ir" (i));
5679+ } else {
5680+ unsigned long flags;
5681+
5682+ raw_local_irq_save(flags);
5683+ __asm__ __volatile__(
5684+ " lw %0, %1 \n"
5685+#ifdef CONFIG_PAX_REFCOUNT
5686+ /* Exception on overflow. */
5687+ "1: add %0, %2 \n"
5688+#else
5689+ " addu %0, %2 \n"
5690+#endif
5691+ " sw %0, %1 \n"
5692+#ifdef CONFIG_PAX_REFCOUNT
5693+ /* Note: Dest reg is not modified on overflow */
5694+ "2: \n"
5695+ _ASM_EXTABLE(1b, 2b)
5696+#endif
5697+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5698+ raw_local_irq_restore(flags);
5699+ }
5700+
5701+ smp_llsc_mb();
5702+
5703+ return result;
5704+}
5705+
5706+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5707 {
5708 int result;
5709
5710@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5711 return result;
5712 }
5713
5714-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5715+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5716+{
5717+ int result;
5718+ int temp;
5719+
5720+ smp_mb__before_llsc();
5721+
5722+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5723+ __asm__ __volatile__(
5724+ " .set mips3 \n"
5725+ "1: ll %1, %2 # atomic_sub_return \n"
5726+#ifdef CONFIG_PAX_REFCOUNT
5727+ "2: sub %0, %1, %3 \n"
5728+#else
5729+ " subu %0, %1, %3 \n"
5730+#endif
5731+ " sc %0, %2 \n"
5732+ " beqzl %0, 1b \n"
5733+#ifdef CONFIG_PAX_REFCOUNT
5734+ " b 4f \n"
5735+ " .set noreorder \n"
5736+ "3: b 5f \n"
5737+ " move %0, %1 \n"
5738+ " .set reorder \n"
5739+ _ASM_EXTABLE(2b, 3b)
5740+#endif
5741+ "4: subu %0, %1, %3 \n"
5742+#ifdef CONFIG_PAX_REFCOUNT
5743+ "5: \n"
5744+#endif
5745+ " .set mips0 \n"
5746+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5747+ : "Ir" (i), "m" (v->counter)
5748+ : "memory");
5749+ } else if (kernel_uses_llsc) {
5750+ __asm__ __volatile__(
5751+ " .set mips3 \n"
5752+ "1: ll %1, %2 # atomic_sub_return \n"
5753+#ifdef CONFIG_PAX_REFCOUNT
5754+ "2: sub %0, %1, %3 \n"
5755+#else
5756+ " subu %0, %1, %3 \n"
5757+#endif
5758+ " sc %0, %2 \n"
5759+ " bnez %0, 4f \n"
5760+ " b 1b \n"
5761+#ifdef CONFIG_PAX_REFCOUNT
5762+ " .set noreorder \n"
5763+ "3: b 5f \n"
5764+ " move %0, %1 \n"
5765+ " .set reorder \n"
5766+ _ASM_EXTABLE(2b, 3b)
5767+#endif
5768+ "4: subu %0, %1, %3 \n"
5769+#ifdef CONFIG_PAX_REFCOUNT
5770+ "5: \n"
5771+#endif
5772+ " .set mips0 \n"
5773+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5774+ : "Ir" (i));
5775+ } else {
5776+ unsigned long flags;
5777+
5778+ raw_local_irq_save(flags);
5779+ __asm__ __volatile__(
5780+ " lw %0, %1 \n"
5781+#ifdef CONFIG_PAX_REFCOUNT
5782+ /* Exception on overflow. */
5783+ "1: sub %0, %2 \n"
5784+#else
5785+ " subu %0, %2 \n"
5786+#endif
5787+ " sw %0, %1 \n"
5788+#ifdef CONFIG_PAX_REFCOUNT
5789+ /* Note: Dest reg is not modified on overflow */
5790+ "2: \n"
5791+ _ASM_EXTABLE(1b, 2b)
5792+#endif
5793+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5794+ raw_local_irq_restore(flags);
5795+ }
5796+
5797+ smp_llsc_mb();
5798+
5799+ return result;
5800+}
5801+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5802 {
5803 int result;
5804
5805@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5806 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5807 * The function returns the old value of @v minus @i.
5808 */
5809-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5810+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5811 {
5812 int result;
5813
5814@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5815 return result;
5816 }
5817
5818-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5819-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5820+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5821+{
5822+ return cmpxchg(&v->counter, old, new);
5823+}
5824+
5825+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5826+ int new)
5827+{
5828+ return cmpxchg(&(v->counter), old, new);
5829+}
5830+
5831+static inline int atomic_xchg(atomic_t *v, int new)
5832+{
5833+ return xchg(&v->counter, new);
5834+}
5835+
5836+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5837+{
5838+ return xchg(&(v->counter), new);
5839+}
5840
5841 /**
5842 * __atomic_add_unless - add unless the number is a given value
5843@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5844
5845 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5846 #define atomic_inc_return(v) atomic_add_return(1, (v))
5847+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5848+{
5849+ return atomic_add_return_unchecked(1, v);
5850+}
5851
5852 /*
5853 * atomic_sub_and_test - subtract value from variable and test result
5854@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5855 * other cases.
5856 */
5857 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5858+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5859+{
5860+ return atomic_add_return_unchecked(1, v) == 0;
5861+}
5862
5863 /*
5864 * atomic_dec_and_test - decrement by 1 and test
5865@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5866 * Atomically increments @v by 1.
5867 */
5868 #define atomic_inc(v) atomic_add(1, (v))
5869+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5870+{
5871+ atomic_add_unchecked(1, v);
5872+}
5873
5874 /*
5875 * atomic_dec - decrement and test
5876@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5877 * Atomically decrements @v by 1.
5878 */
5879 #define atomic_dec(v) atomic_sub(1, (v))
5880+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5881+{
5882+ atomic_sub_unchecked(1, v);
5883+}
5884
5885 /*
5886 * atomic_add_negative - add and test if negative
5887@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5888 * @v: pointer of type atomic64_t
5889 *
5890 */
5891-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5892+static inline long atomic64_read(const atomic64_t *v)
5893+{
5894+ return (*(volatile const long *) &v->counter);
5895+}
5896+
5897+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5898+{
5899+ return (*(volatile const long *) &v->counter);
5900+}
5901
5902 /*
5903 * atomic64_set - set atomic variable
5904 * @v: pointer of type atomic64_t
5905 * @i: required value
5906 */
5907-#define atomic64_set(v, i) ((v)->counter = (i))
5908+static inline void atomic64_set(atomic64_t *v, long i)
5909+{
5910+ v->counter = i;
5911+}
5912+
5913+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5914+{
5915+ v->counter = i;
5916+}
5917
5918 /*
5919 * atomic64_add - add integer to atomic variable
5920@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5921 *
5922 * Atomically adds @i to @v.
5923 */
5924-static __inline__ void atomic64_add(long i, atomic64_t * v)
5925+static __inline__ void atomic64_add(long i, atomic64_t *v)
5926+{
5927+ long temp;
5928+
5929+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5930+ __asm__ __volatile__(
5931+ " .set mips3 \n"
5932+ "1: lld %0, %1 # atomic64_add \n"
5933+#ifdef CONFIG_PAX_REFCOUNT
5934+ /* Exception on overflow. */
5935+ "2: dadd %0, %2 \n"
5936+#else
5937+ " daddu %0, %2 \n"
5938+#endif
5939+ " scd %0, %1 \n"
5940+ " beqzl %0, 1b \n"
5941+#ifdef CONFIG_PAX_REFCOUNT
5942+ "3: \n"
5943+ _ASM_EXTABLE(2b, 3b)
5944+#endif
5945+ " .set mips0 \n"
5946+ : "=&r" (temp), "+m" (v->counter)
5947+ : "Ir" (i));
5948+ } else if (kernel_uses_llsc) {
5949+ __asm__ __volatile__(
5950+ " .set mips3 \n"
5951+ "1: lld %0, %1 # atomic64_add \n"
5952+#ifdef CONFIG_PAX_REFCOUNT
5953+ /* Exception on overflow. */
5954+ "2: dadd %0, %2 \n"
5955+#else
5956+ " daddu %0, %2 \n"
5957+#endif
5958+ " scd %0, %1 \n"
5959+ " beqz %0, 1b \n"
5960+#ifdef CONFIG_PAX_REFCOUNT
5961+ "3: \n"
5962+ _ASM_EXTABLE(2b, 3b)
5963+#endif
5964+ " .set mips0 \n"
5965+ : "=&r" (temp), "+m" (v->counter)
5966+ : "Ir" (i));
5967+ } else {
5968+ unsigned long flags;
5969+
5970+ raw_local_irq_save(flags);
5971+ __asm__ __volatile__(
5972+#ifdef CONFIG_PAX_REFCOUNT
5973+ /* Exception on overflow. */
5974+ "1: dadd %0, %1 \n"
5975+ "2: \n"
5976+ _ASM_EXTABLE(1b, 2b)
5977+#else
5978+ " daddu %0, %1 \n"
5979+#endif
5980+ : "+r" (v->counter) : "Ir" (i));
5981+ raw_local_irq_restore(flags);
5982+ }
5983+}
5984+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5985 {
5986 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5987 long temp;
5988@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5989 *
5990 * Atomically subtracts @i from @v.
5991 */
5992-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5993+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5994+{
5995+ long temp;
5996+
5997+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5998+ __asm__ __volatile__(
5999+ " .set mips3 \n"
6000+ "1: lld %0, %1 # atomic64_sub \n"
6001+#ifdef CONFIG_PAX_REFCOUNT
6002+ /* Exception on overflow. */
6003+ "2: dsub %0, %2 \n"
6004+#else
6005+ " dsubu %0, %2 \n"
6006+#endif
6007+ " scd %0, %1 \n"
6008+ " beqzl %0, 1b \n"
6009+#ifdef CONFIG_PAX_REFCOUNT
6010+ "3: \n"
6011+ _ASM_EXTABLE(2b, 3b)
6012+#endif
6013+ " .set mips0 \n"
6014+ : "=&r" (temp), "+m" (v->counter)
6015+ : "Ir" (i));
6016+ } else if (kernel_uses_llsc) {
6017+ __asm__ __volatile__(
6018+ " .set mips3 \n"
6019+ "1: lld %0, %1 # atomic64_sub \n"
6020+#ifdef CONFIG_PAX_REFCOUNT
6021+ /* Exception on overflow. */
6022+ "2: dsub %0, %2 \n"
6023+#else
6024+ " dsubu %0, %2 \n"
6025+#endif
6026+ " scd %0, %1 \n"
6027+ " beqz %0, 1b \n"
6028+#ifdef CONFIG_PAX_REFCOUNT
6029+ "3: \n"
6030+ _ASM_EXTABLE(2b, 3b)
6031+#endif
6032+ " .set mips0 \n"
6033+ : "=&r" (temp), "+m" (v->counter)
6034+ : "Ir" (i));
6035+ } else {
6036+ unsigned long flags;
6037+
6038+ raw_local_irq_save(flags);
6039+ __asm__ __volatile__(
6040+#ifdef CONFIG_PAX_REFCOUNT
6041+ /* Exception on overflow. */
6042+ "1: dsub %0, %1 \n"
6043+ "2: \n"
6044+ _ASM_EXTABLE(1b, 2b)
6045+#else
6046+ " dsubu %0, %1 \n"
6047+#endif
6048+ : "+r" (v->counter) : "Ir" (i));
6049+ raw_local_irq_restore(flags);
6050+ }
6051+}
6052+
6053+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6054 {
6055 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6056 long temp;
6057@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6058 /*
6059 * Same as above, but return the result value
6060 */
6061-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6062+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6063+{
6064+ long result;
6065+ long temp;
6066+
6067+ smp_mb__before_llsc();
6068+
6069+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6070+ __asm__ __volatile__(
6071+ " .set mips3 \n"
6072+ "1: lld %1, %2 # atomic64_add_return \n"
6073+#ifdef CONFIG_PAX_REFCOUNT
6074+ "2: dadd %0, %1, %3 \n"
6075+#else
6076+ " daddu %0, %1, %3 \n"
6077+#endif
6078+ " scd %0, %2 \n"
6079+ " beqzl %0, 1b \n"
6080+#ifdef CONFIG_PAX_REFCOUNT
6081+ " b 4f \n"
6082+ " .set noreorder \n"
6083+ "3: b 5f \n"
6084+ " move %0, %1 \n"
6085+ " .set reorder \n"
6086+ _ASM_EXTABLE(2b, 3b)
6087+#endif
6088+ "4: daddu %0, %1, %3 \n"
6089+#ifdef CONFIG_PAX_REFCOUNT
6090+ "5: \n"
6091+#endif
6092+ " .set mips0 \n"
6093+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6094+ : "Ir" (i));
6095+ } else if (kernel_uses_llsc) {
6096+ __asm__ __volatile__(
6097+ " .set mips3 \n"
6098+ "1: lld %1, %2 # atomic64_add_return \n"
6099+#ifdef CONFIG_PAX_REFCOUNT
6100+ "2: dadd %0, %1, %3 \n"
6101+#else
6102+ " daddu %0, %1, %3 \n"
6103+#endif
6104+ " scd %0, %2 \n"
6105+ " bnez %0, 4f \n"
6106+ " b 1b \n"
6107+#ifdef CONFIG_PAX_REFCOUNT
6108+ " .set noreorder \n"
6109+ "3: b 5f \n"
6110+ " move %0, %1 \n"
6111+ " .set reorder \n"
6112+ _ASM_EXTABLE(2b, 3b)
6113+#endif
6114+ "4: daddu %0, %1, %3 \n"
6115+#ifdef CONFIG_PAX_REFCOUNT
6116+ "5: \n"
6117+#endif
6118+ " .set mips0 \n"
6119+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6120+ : "Ir" (i), "m" (v->counter)
6121+ : "memory");
6122+ } else {
6123+ unsigned long flags;
6124+
6125+ raw_local_irq_save(flags);
6126+ __asm__ __volatile__(
6127+ " ld %0, %1 \n"
6128+#ifdef CONFIG_PAX_REFCOUNT
6129+ /* Exception on overflow. */
6130+ "1: dadd %0, %2 \n"
6131+#else
6132+ " daddu %0, %2 \n"
6133+#endif
6134+ " sd %0, %1 \n"
6135+#ifdef CONFIG_PAX_REFCOUNT
6136+ /* Note: Dest reg is not modified on overflow */
6137+ "2: \n"
6138+ _ASM_EXTABLE(1b, 2b)
6139+#endif
6140+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6141+ raw_local_irq_restore(flags);
6142+ }
6143+
6144+ smp_llsc_mb();
6145+
6146+ return result;
6147+}
6148+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6149 {
6150 long result;
6151
6152@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6153 return result;
6154 }
6155
6156-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6157+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6158+{
6159+ long result;
6160+ long temp;
6161+
6162+ smp_mb__before_llsc();
6163+
6164+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6165+ long temp;
6166+
6167+ __asm__ __volatile__(
6168+ " .set mips3 \n"
6169+ "1: lld %1, %2 # atomic64_sub_return \n"
6170+#ifdef CONFIG_PAX_REFCOUNT
6171+ "2: dsub %0, %1, %3 \n"
6172+#else
6173+ " dsubu %0, %1, %3 \n"
6174+#endif
6175+ " scd %0, %2 \n"
6176+ " beqzl %0, 1b \n"
6177+#ifdef CONFIG_PAX_REFCOUNT
6178+ " b 4f \n"
6179+ " .set noreorder \n"
6180+ "3: b 5f \n"
6181+ " move %0, %1 \n"
6182+ " .set reorder \n"
6183+ _ASM_EXTABLE(2b, 3b)
6184+#endif
6185+ "4: dsubu %0, %1, %3 \n"
6186+#ifdef CONFIG_PAX_REFCOUNT
6187+ "5: \n"
6188+#endif
6189+ " .set mips0 \n"
6190+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6191+ : "Ir" (i), "m" (v->counter)
6192+ : "memory");
6193+ } else if (kernel_uses_llsc) {
6194+ __asm__ __volatile__(
6195+ " .set mips3 \n"
6196+ "1: lld %1, %2 # atomic64_sub_return \n"
6197+#ifdef CONFIG_PAX_REFCOUNT
6198+ "2: dsub %0, %1, %3 \n"
6199+#else
6200+ " dsubu %0, %1, %3 \n"
6201+#endif
6202+ " scd %0, %2 \n"
6203+ " bnez %0, 4f \n"
6204+ " b 1b \n"
6205+#ifdef CONFIG_PAX_REFCOUNT
6206+ " .set noreorder \n"
6207+ "3: b 5f \n"
6208+ " move %0, %1 \n"
6209+ " .set reorder \n"
6210+ _ASM_EXTABLE(2b, 3b)
6211+#endif
6212+ "4: dsubu %0, %1, %3 \n"
6213+#ifdef CONFIG_PAX_REFCOUNT
6214+ "5: \n"
6215+#endif
6216+ " .set mips0 \n"
6217+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6218+ : "Ir" (i), "m" (v->counter)
6219+ : "memory");
6220+ } else {
6221+ unsigned long flags;
6222+
6223+ raw_local_irq_save(flags);
6224+ __asm__ __volatile__(
6225+ " ld %0, %1 \n"
6226+#ifdef CONFIG_PAX_REFCOUNT
6227+ /* Exception on overflow. */
6228+ "1: dsub %0, %2 \n"
6229+#else
6230+ " dsubu %0, %2 \n"
6231+#endif
6232+ " sd %0, %1 \n"
6233+#ifdef CONFIG_PAX_REFCOUNT
6234+ /* Note: Dest reg is not modified on overflow */
6235+ "2: \n"
6236+ _ASM_EXTABLE(1b, 2b)
6237+#endif
6238+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6239+ raw_local_irq_restore(flags);
6240+ }
6241+
6242+ smp_llsc_mb();
6243+
6244+ return result;
6245+}
6246+
6247+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6248 {
6249 long result;
6250
6251@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6252 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6253 * The function returns the old value of @v minus @i.
6254 */
6255-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6256+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6257 {
6258 long result;
6259
6260@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6261 return result;
6262 }
6263
6264-#define atomic64_cmpxchg(v, o, n) \
6265- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6266-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6267+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6268+{
6269+ return cmpxchg(&v->counter, old, new);
6270+}
6271+
6272+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6273+ long new)
6274+{
6275+ return cmpxchg(&(v->counter), old, new);
6276+}
6277+
6278+static inline long atomic64_xchg(atomic64_t *v, long new)
6279+{
6280+ return xchg(&v->counter, new);
6281+}
6282+
6283+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6284+{
6285+ return xchg(&(v->counter), new);
6286+}
6287
6288 /**
6289 * atomic64_add_unless - add unless the number is a given value
6290@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6291
6292 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6293 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6294+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6295
6296 /*
6297 * atomic64_sub_and_test - subtract value from variable and test result
6298@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6299 * other cases.
6300 */
6301 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6302+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6303
6304 /*
6305 * atomic64_dec_and_test - decrement by 1 and test
6306@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6307 * Atomically increments @v by 1.
6308 */
6309 #define atomic64_inc(v) atomic64_add(1, (v))
6310+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6311
6312 /*
6313 * atomic64_dec - decrement and test
6314@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6315 * Atomically decrements @v by 1.
6316 */
6317 #define atomic64_dec(v) atomic64_sub(1, (v))
6318+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6319
6320 /*
6321 * atomic64_add_negative - add and test if negative
6322diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6323index b4db69f..8f3b093 100644
6324--- a/arch/mips/include/asm/cache.h
6325+++ b/arch/mips/include/asm/cache.h
6326@@ -9,10 +9,11 @@
6327 #ifndef _ASM_CACHE_H
6328 #define _ASM_CACHE_H
6329
6330+#include <linux/const.h>
6331 #include <kmalloc.h>
6332
6333 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6334-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6335+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6336
6337 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6338 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6339diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6340index a66359e..d3d474a 100644
6341--- a/arch/mips/include/asm/elf.h
6342+++ b/arch/mips/include/asm/elf.h
6343@@ -373,13 +373,16 @@ extern const char *__elf_platform;
6344 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6345 #endif
6346
6347+#ifdef CONFIG_PAX_ASLR
6348+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6349+
6350+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6351+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6352+#endif
6353+
6354 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6355 struct linux_binprm;
6356 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6357 int uses_interp);
6358
6359-struct mm_struct;
6360-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6361-#define arch_randomize_brk arch_randomize_brk
6362-
6363 #endif /* _ASM_ELF_H */
6364diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6365index c1f6afa..38cc6e9 100644
6366--- a/arch/mips/include/asm/exec.h
6367+++ b/arch/mips/include/asm/exec.h
6368@@ -12,6 +12,6 @@
6369 #ifndef _ASM_EXEC_H
6370 #define _ASM_EXEC_H
6371
6372-extern unsigned long arch_align_stack(unsigned long sp);
6373+#define arch_align_stack(x) ((x) & ~0xfUL)
6374
6375 #endif /* _ASM_EXEC_H */
6376diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6377index d44622c..64990d2 100644
6378--- a/arch/mips/include/asm/local.h
6379+++ b/arch/mips/include/asm/local.h
6380@@ -12,15 +12,25 @@ typedef struct
6381 atomic_long_t a;
6382 } local_t;
6383
6384+typedef struct {
6385+ atomic_long_unchecked_t a;
6386+} local_unchecked_t;
6387+
6388 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6389
6390 #define local_read(l) atomic_long_read(&(l)->a)
6391+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6392 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6393+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6394
6395 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6396+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6397 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6398+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6399 #define local_inc(l) atomic_long_inc(&(l)->a)
6400+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6401 #define local_dec(l) atomic_long_dec(&(l)->a)
6402+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6403
6404 /*
6405 * Same as above, but return the result value
6406@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6407 return result;
6408 }
6409
6410+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6411+{
6412+ unsigned long result;
6413+
6414+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6415+ unsigned long temp;
6416+
6417+ __asm__ __volatile__(
6418+ " .set mips3 \n"
6419+ "1:" __LL "%1, %2 # local_add_return \n"
6420+ " addu %0, %1, %3 \n"
6421+ __SC "%0, %2 \n"
6422+ " beqzl %0, 1b \n"
6423+ " addu %0, %1, %3 \n"
6424+ " .set mips0 \n"
6425+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6426+ : "Ir" (i), "m" (l->a.counter)
6427+ : "memory");
6428+ } else if (kernel_uses_llsc) {
6429+ unsigned long temp;
6430+
6431+ __asm__ __volatile__(
6432+ " .set mips3 \n"
6433+ "1:" __LL "%1, %2 # local_add_return \n"
6434+ " addu %0, %1, %3 \n"
6435+ __SC "%0, %2 \n"
6436+ " beqz %0, 1b \n"
6437+ " addu %0, %1, %3 \n"
6438+ " .set mips0 \n"
6439+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6440+ : "Ir" (i), "m" (l->a.counter)
6441+ : "memory");
6442+ } else {
6443+ unsigned long flags;
6444+
6445+ local_irq_save(flags);
6446+ result = l->a.counter;
6447+ result += i;
6448+ l->a.counter = result;
6449+ local_irq_restore(flags);
6450+ }
6451+
6452+ return result;
6453+}
6454+
6455 static __inline__ long local_sub_return(long i, local_t * l)
6456 {
6457 unsigned long result;
6458@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6459
6460 #define local_cmpxchg(l, o, n) \
6461 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6462+#define local_cmpxchg_unchecked(l, o, n) \
6463+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6464 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6465
6466 /**
6467diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6468index f6be474..12ad554 100644
6469--- a/arch/mips/include/asm/page.h
6470+++ b/arch/mips/include/asm/page.h
6471@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6472 #ifdef CONFIG_CPU_MIPS32
6473 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6474 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6475- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6476+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6477 #else
6478 typedef struct { unsigned long long pte; } pte_t;
6479 #define pte_val(x) ((x).pte)
6480diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6481index b336037..5b874cc 100644
6482--- a/arch/mips/include/asm/pgalloc.h
6483+++ b/arch/mips/include/asm/pgalloc.h
6484@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6485 {
6486 set_pud(pud, __pud((unsigned long)pmd));
6487 }
6488+
6489+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6490+{
6491+ pud_populate(mm, pud, pmd);
6492+}
6493 #endif
6494
6495 /*
6496diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6497index 25da651..ae2a259 100644
6498--- a/arch/mips/include/asm/smtc_proc.h
6499+++ b/arch/mips/include/asm/smtc_proc.h
6500@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6501
6502 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6503
6504-extern atomic_t smtc_fpu_recoveries;
6505+extern atomic_unchecked_t smtc_fpu_recoveries;
6506
6507 #endif /* __ASM_SMTC_PROC_H */
6508diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6509index 4f58ef6..5e7081b 100644
6510--- a/arch/mips/include/asm/thread_info.h
6511+++ b/arch/mips/include/asm/thread_info.h
6512@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6513 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6514 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6515 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6516+/* li takes a 32bit immediate */
6517+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6518 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6519
6520 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6521@@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6522 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6523 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6524 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6525+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6526
6527 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6528- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6529+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6530
6531 /* work to do in syscall_trace_leave() */
6532 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6533- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6534+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6535
6536 /* work to do on interrupt/exception return */
6537 #define _TIF_WORK_MASK \
6538@@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6539 /* work to do on any return to u-space */
6540 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6541 _TIF_WORK_SYSCALL_EXIT | \
6542- _TIF_SYSCALL_TRACEPOINT)
6543+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6544
6545 /*
6546 * We stash processor id into a COP0 register to retrieve it fast
6547diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6548index 1188e00..41cf144 100644
6549--- a/arch/mips/kernel/binfmt_elfn32.c
6550+++ b/arch/mips/kernel/binfmt_elfn32.c
6551@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6552 #undef ELF_ET_DYN_BASE
6553 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6554
6555+#ifdef CONFIG_PAX_ASLR
6556+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6557+
6558+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6559+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6560+#endif
6561+
6562 #include <asm/processor.h>
6563 #include <linux/module.h>
6564 #include <linux/elfcore.h>
6565diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6566index 202e581..689ca79 100644
6567--- a/arch/mips/kernel/binfmt_elfo32.c
6568+++ b/arch/mips/kernel/binfmt_elfo32.c
6569@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6570 #undef ELF_ET_DYN_BASE
6571 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6572
6573+#ifdef CONFIG_PAX_ASLR
6574+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6575+
6576+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6577+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6578+#endif
6579+
6580 #include <asm/processor.h>
6581
6582 /*
6583diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6584index d1fea7a..45602ea 100644
6585--- a/arch/mips/kernel/irq.c
6586+++ b/arch/mips/kernel/irq.c
6587@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6588 printk("unexpected IRQ # %d\n", irq);
6589 }
6590
6591-atomic_t irq_err_count;
6592+atomic_unchecked_t irq_err_count;
6593
6594 int arch_show_interrupts(struct seq_file *p, int prec)
6595 {
6596- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6597+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6598 return 0;
6599 }
6600
6601 asmlinkage void spurious_interrupt(void)
6602 {
6603- atomic_inc(&irq_err_count);
6604+ atomic_inc_unchecked(&irq_err_count);
6605 }
6606
6607 void __init init_IRQ(void)
6608diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6609index ddc7610..8c58f17 100644
6610--- a/arch/mips/kernel/process.c
6611+++ b/arch/mips/kernel/process.c
6612@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6613 out:
6614 return pc;
6615 }
6616-
6617-/*
6618- * Don't forget that the stack pointer must be aligned on a 8 bytes
6619- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6620- */
6621-unsigned long arch_align_stack(unsigned long sp)
6622-{
6623- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6624- sp -= get_random_int() & ~PAGE_MASK;
6625-
6626- return sp & ALMASK;
6627-}
6628diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6629index b52e1d2..1a3ca09 100644
6630--- a/arch/mips/kernel/ptrace.c
6631+++ b/arch/mips/kernel/ptrace.c
6632@@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6633 return ret;
6634 }
6635
6636+#ifdef CONFIG_GRKERNSEC_SETXID
6637+extern void gr_delayed_cred_worker(void);
6638+#endif
6639+
6640 /*
6641 * Notification of system call entry/exit
6642 * - triggered by current->work.syscall_trace
6643@@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6644 tracehook_report_syscall_entry(regs))
6645 ret = -1;
6646
6647+#ifdef CONFIG_GRKERNSEC_SETXID
6648+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6649+ gr_delayed_cred_worker();
6650+#endif
6651+
6652 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6653 trace_sys_enter(regs, regs->regs[2]);
6654
6655diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6656index c10aa84..9ec2e60 100644
6657--- a/arch/mips/kernel/smtc-proc.c
6658+++ b/arch/mips/kernel/smtc-proc.c
6659@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6660
6661 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6662
6663-atomic_t smtc_fpu_recoveries;
6664+atomic_unchecked_t smtc_fpu_recoveries;
6665
6666 static int smtc_proc_show(struct seq_file *m, void *v)
6667 {
6668@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6669 for(i = 0; i < NR_CPUS; i++)
6670 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6671 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6672- atomic_read(&smtc_fpu_recoveries));
6673+ atomic_read_unchecked(&smtc_fpu_recoveries));
6674 return 0;
6675 }
6676
6677@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6678 smtc_cpu_stats[i].selfipis = 0;
6679 }
6680
6681- atomic_set(&smtc_fpu_recoveries, 0);
6682+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6683
6684 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6685 }
6686diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6687index dfc1b91..11a2c07 100644
6688--- a/arch/mips/kernel/smtc.c
6689+++ b/arch/mips/kernel/smtc.c
6690@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6691 }
6692 smtc_ipi_qdump();
6693 printk("%d Recoveries of \"stolen\" FPU\n",
6694- atomic_read(&smtc_fpu_recoveries));
6695+ atomic_read_unchecked(&smtc_fpu_recoveries));
6696 }
6697
6698
6699diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6700index 84536bf..79caa4d 100644
6701--- a/arch/mips/kernel/sync-r4k.c
6702+++ b/arch/mips/kernel/sync-r4k.c
6703@@ -21,8 +21,8 @@
6704 #include <asm/mipsregs.h>
6705
6706 static atomic_t count_start_flag = ATOMIC_INIT(0);
6707-static atomic_t count_count_start = ATOMIC_INIT(0);
6708-static atomic_t count_count_stop = ATOMIC_INIT(0);
6709+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6710+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6711 static atomic_t count_reference = ATOMIC_INIT(0);
6712
6713 #define COUNTON 100
6714@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6715
6716 for (i = 0; i < NR_LOOPS; i++) {
6717 /* slaves loop on '!= 2' */
6718- while (atomic_read(&count_count_start) != 1)
6719+ while (atomic_read_unchecked(&count_count_start) != 1)
6720 mb();
6721- atomic_set(&count_count_stop, 0);
6722+ atomic_set_unchecked(&count_count_stop, 0);
6723 smp_wmb();
6724
6725 /* this lets the slaves write their count register */
6726- atomic_inc(&count_count_start);
6727+ atomic_inc_unchecked(&count_count_start);
6728
6729 /*
6730 * Everyone initialises count in the last loop:
6731@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6732 /*
6733 * Wait for all slaves to leave the synchronization point:
6734 */
6735- while (atomic_read(&count_count_stop) != 1)
6736+ while (atomic_read_unchecked(&count_count_stop) != 1)
6737 mb();
6738- atomic_set(&count_count_start, 0);
6739+ atomic_set_unchecked(&count_count_start, 0);
6740 smp_wmb();
6741- atomic_inc(&count_count_stop);
6742+ atomic_inc_unchecked(&count_count_stop);
6743 }
6744 /* Arrange for an interrupt in a short while */
6745 write_c0_compare(read_c0_count() + COUNTON);
6746@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6747 initcount = atomic_read(&count_reference);
6748
6749 for (i = 0; i < NR_LOOPS; i++) {
6750- atomic_inc(&count_count_start);
6751- while (atomic_read(&count_count_start) != 2)
6752+ atomic_inc_unchecked(&count_count_start);
6753+ while (atomic_read_unchecked(&count_count_start) != 2)
6754 mb();
6755
6756 /*
6757@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6758 if (i == NR_LOOPS-1)
6759 write_c0_count(initcount);
6760
6761- atomic_inc(&count_count_stop);
6762- while (atomic_read(&count_count_stop) != 2)
6763+ atomic_inc_unchecked(&count_count_stop);
6764+ while (atomic_read_unchecked(&count_count_stop) != 2)
6765 mb();
6766 }
6767 /* Arrange for an interrupt in a short while */
6768diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6769index f9c8746..78b64e3 100644
6770--- a/arch/mips/kernel/traps.c
6771+++ b/arch/mips/kernel/traps.c
6772@@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6773 siginfo_t info;
6774
6775 prev_state = exception_enter();
6776- die_if_kernel("Integer overflow", regs);
6777+ if (unlikely(!user_mode(regs))) {
6778+
6779+#ifdef CONFIG_PAX_REFCOUNT
6780+ if (fixup_exception(regs)) {
6781+ pax_report_refcount_overflow(regs);
6782+ exception_exit(prev_state);
6783+ return;
6784+ }
6785+#endif
6786+
6787+ die("Integer overflow", regs);
6788+ }
6789
6790 info.si_code = FPE_INTOVF;
6791 info.si_signo = SIGFPE;
6792diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6793index becc42b..9e43d4b 100644
6794--- a/arch/mips/mm/fault.c
6795+++ b/arch/mips/mm/fault.c
6796@@ -28,6 +28,23 @@
6797 #include <asm/highmem.h> /* For VMALLOC_END */
6798 #include <linux/kdebug.h>
6799
6800+#ifdef CONFIG_PAX_PAGEEXEC
6801+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6802+{
6803+ unsigned long i;
6804+
6805+ printk(KERN_ERR "PAX: bytes at PC: ");
6806+ for (i = 0; i < 5; i++) {
6807+ unsigned int c;
6808+ if (get_user(c, (unsigned int *)pc+i))
6809+ printk(KERN_CONT "???????? ");
6810+ else
6811+ printk(KERN_CONT "%08x ", c);
6812+ }
6813+ printk("\n");
6814+}
6815+#endif
6816+
6817 /*
6818 * This routine handles page faults. It determines the address,
6819 * and the problem, and then passes it off to one of the appropriate
6820@@ -199,6 +216,14 @@ bad_area:
6821 bad_area_nosemaphore:
6822 /* User mode accesses just cause a SIGSEGV */
6823 if (user_mode(regs)) {
6824+
6825+#ifdef CONFIG_PAX_PAGEEXEC
6826+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6827+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6828+ do_group_exit(SIGKILL);
6829+ }
6830+#endif
6831+
6832 tsk->thread.cp0_badvaddr = address;
6833 tsk->thread.error_code = write;
6834 #if 0
6835diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6836index f1baadd..8537544 100644
6837--- a/arch/mips/mm/mmap.c
6838+++ b/arch/mips/mm/mmap.c
6839@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6840 struct vm_area_struct *vma;
6841 unsigned long addr = addr0;
6842 int do_color_align;
6843+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6844 struct vm_unmapped_area_info info;
6845
6846 if (unlikely(len > TASK_SIZE))
6847@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6848 do_color_align = 1;
6849
6850 /* requesting a specific address */
6851+
6852+#ifdef CONFIG_PAX_RANDMMAP
6853+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6854+#endif
6855+
6856 if (addr) {
6857 if (do_color_align)
6858 addr = COLOUR_ALIGN(addr, pgoff);
6859@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6860 addr = PAGE_ALIGN(addr);
6861
6862 vma = find_vma(mm, addr);
6863- if (TASK_SIZE - len >= addr &&
6864- (!vma || addr + len <= vma->vm_start))
6865+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6866 return addr;
6867 }
6868
6869 info.length = len;
6870 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6871 info.align_offset = pgoff << PAGE_SHIFT;
6872+ info.threadstack_offset = offset;
6873
6874 if (dir == DOWN) {
6875 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6876@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6877 {
6878 unsigned long random_factor = 0UL;
6879
6880+#ifdef CONFIG_PAX_RANDMMAP
6881+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6882+#endif
6883+
6884 if (current->flags & PF_RANDOMIZE) {
6885 random_factor = get_random_int();
6886 random_factor = random_factor << PAGE_SHIFT;
6887@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6888
6889 if (mmap_is_legacy()) {
6890 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6891+
6892+#ifdef CONFIG_PAX_RANDMMAP
6893+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6894+ mm->mmap_base += mm->delta_mmap;
6895+#endif
6896+
6897 mm->get_unmapped_area = arch_get_unmapped_area;
6898 } else {
6899 mm->mmap_base = mmap_base(random_factor);
6900+
6901+#ifdef CONFIG_PAX_RANDMMAP
6902+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6903+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6904+#endif
6905+
6906 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6907 }
6908 }
6909
6910-static inline unsigned long brk_rnd(void)
6911-{
6912- unsigned long rnd = get_random_int();
6913-
6914- rnd = rnd << PAGE_SHIFT;
6915- /* 8MB for 32bit, 256MB for 64bit */
6916- if (TASK_IS_32BIT_ADDR)
6917- rnd = rnd & 0x7ffffful;
6918- else
6919- rnd = rnd & 0xffffffful;
6920-
6921- return rnd;
6922-}
6923-
6924-unsigned long arch_randomize_brk(struct mm_struct *mm)
6925-{
6926- unsigned long base = mm->brk;
6927- unsigned long ret;
6928-
6929- ret = PAGE_ALIGN(base + brk_rnd());
6930-
6931- if (ret < mm->brk)
6932- return mm->brk;
6933-
6934- return ret;
6935-}
6936-
6937 int __virt_addr_valid(const volatile void *kaddr)
6938 {
6939 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6940diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6941index a2358b4..7cead4f 100644
6942--- a/arch/mips/sgi-ip27/ip27-nmi.c
6943+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6944@@ -187,9 +187,9 @@ void
6945 cont_nmi_dump(void)
6946 {
6947 #ifndef REAL_NMI_SIGNAL
6948- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6949+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6950
6951- atomic_inc(&nmied_cpus);
6952+ atomic_inc_unchecked(&nmied_cpus);
6953 #endif
6954 /*
6955 * Only allow 1 cpu to proceed
6956@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6957 udelay(10000);
6958 }
6959 #else
6960- while (atomic_read(&nmied_cpus) != num_online_cpus());
6961+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6962 #endif
6963
6964 /*
6965diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6966index 967d144..db12197 100644
6967--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6968+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6969@@ -11,12 +11,14 @@
6970 #ifndef _ASM_PROC_CACHE_H
6971 #define _ASM_PROC_CACHE_H
6972
6973+#include <linux/const.h>
6974+
6975 /* L1 cache */
6976
6977 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6978 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6979-#define L1_CACHE_BYTES 16 /* bytes per entry */
6980 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6981+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6982 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6983
6984 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6985diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6986index bcb5df2..84fabd2 100644
6987--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6988+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6989@@ -16,13 +16,15 @@
6990 #ifndef _ASM_PROC_CACHE_H
6991 #define _ASM_PROC_CACHE_H
6992
6993+#include <linux/const.h>
6994+
6995 /*
6996 * L1 cache
6997 */
6998 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6999 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7000-#define L1_CACHE_BYTES 32 /* bytes per entry */
7001 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7002+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7003 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7004
7005 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7006diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7007index 4ce7a01..449202a 100644
7008--- a/arch/openrisc/include/asm/cache.h
7009+++ b/arch/openrisc/include/asm/cache.h
7010@@ -19,11 +19,13 @@
7011 #ifndef __ASM_OPENRISC_CACHE_H
7012 #define __ASM_OPENRISC_CACHE_H
7013
7014+#include <linux/const.h>
7015+
7016 /* FIXME: How can we replace these with values from the CPU...
7017 * they shouldn't be hard-coded!
7018 */
7019
7020-#define L1_CACHE_BYTES 16
7021 #define L1_CACHE_SHIFT 4
7022+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7023
7024 #endif /* __ASM_OPENRISC_CACHE_H */
7025diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7026index 472886c..00e7df9 100644
7027--- a/arch/parisc/include/asm/atomic.h
7028+++ b/arch/parisc/include/asm/atomic.h
7029@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7030 return dec;
7031 }
7032
7033+#define atomic64_read_unchecked(v) atomic64_read(v)
7034+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7035+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7036+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7037+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7038+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7039+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7040+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7041+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7042+
7043 #endif /* !CONFIG_64BIT */
7044
7045
7046diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7047index 47f11c7..3420df2 100644
7048--- a/arch/parisc/include/asm/cache.h
7049+++ b/arch/parisc/include/asm/cache.h
7050@@ -5,6 +5,7 @@
7051 #ifndef __ARCH_PARISC_CACHE_H
7052 #define __ARCH_PARISC_CACHE_H
7053
7054+#include <linux/const.h>
7055
7056 /*
7057 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7058@@ -15,13 +16,13 @@
7059 * just ruin performance.
7060 */
7061 #ifdef CONFIG_PA20
7062-#define L1_CACHE_BYTES 64
7063 #define L1_CACHE_SHIFT 6
7064 #else
7065-#define L1_CACHE_BYTES 32
7066 #define L1_CACHE_SHIFT 5
7067 #endif
7068
7069+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7070+
7071 #ifndef __ASSEMBLY__
7072
7073 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7074diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7075index ad2b503..bdf1651 100644
7076--- a/arch/parisc/include/asm/elf.h
7077+++ b/arch/parisc/include/asm/elf.h
7078@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7079
7080 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7081
7082+#ifdef CONFIG_PAX_ASLR
7083+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7084+
7085+#define PAX_DELTA_MMAP_LEN 16
7086+#define PAX_DELTA_STACK_LEN 16
7087+#endif
7088+
7089 /* This yields a mask that user programs can use to figure out what
7090 instruction set this CPU supports. This could be done in user space,
7091 but it's not easy, and we've already done it here. */
7092diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7093index f213f5b..0af3e8e 100644
7094--- a/arch/parisc/include/asm/pgalloc.h
7095+++ b/arch/parisc/include/asm/pgalloc.h
7096@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7097 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7098 }
7099
7100+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7101+{
7102+ pgd_populate(mm, pgd, pmd);
7103+}
7104+
7105 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7106 {
7107 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7108@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7109 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7110 #define pmd_free(mm, x) do { } while (0)
7111 #define pgd_populate(mm, pmd, pte) BUG()
7112+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7113
7114 #endif
7115
7116diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7117index 34899b5..02dd060 100644
7118--- a/arch/parisc/include/asm/pgtable.h
7119+++ b/arch/parisc/include/asm/pgtable.h
7120@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7121 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7122 #define PAGE_COPY PAGE_EXECREAD
7123 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7124+
7125+#ifdef CONFIG_PAX_PAGEEXEC
7126+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7127+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7128+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7129+#else
7130+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7131+# define PAGE_COPY_NOEXEC PAGE_COPY
7132+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7133+#endif
7134+
7135 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7136 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7137 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7138diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7139index 4006964..fcb3cc2 100644
7140--- a/arch/parisc/include/asm/uaccess.h
7141+++ b/arch/parisc/include/asm/uaccess.h
7142@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7143 const void __user *from,
7144 unsigned long n)
7145 {
7146- int sz = __compiletime_object_size(to);
7147+ size_t sz = __compiletime_object_size(to);
7148 int ret = -EFAULT;
7149
7150- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7151+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7152 ret = __copy_from_user(to, from, n);
7153 else
7154 copy_from_user_overflow();
7155diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7156index 50dfafc..b9fc230 100644
7157--- a/arch/parisc/kernel/module.c
7158+++ b/arch/parisc/kernel/module.c
7159@@ -98,16 +98,38 @@
7160
7161 /* three functions to determine where in the module core
7162 * or init pieces the location is */
7163+static inline int in_init_rx(struct module *me, void *loc)
7164+{
7165+ return (loc >= me->module_init_rx &&
7166+ loc < (me->module_init_rx + me->init_size_rx));
7167+}
7168+
7169+static inline int in_init_rw(struct module *me, void *loc)
7170+{
7171+ return (loc >= me->module_init_rw &&
7172+ loc < (me->module_init_rw + me->init_size_rw));
7173+}
7174+
7175 static inline int in_init(struct module *me, void *loc)
7176 {
7177- return (loc >= me->module_init &&
7178- loc <= (me->module_init + me->init_size));
7179+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7180+}
7181+
7182+static inline int in_core_rx(struct module *me, void *loc)
7183+{
7184+ return (loc >= me->module_core_rx &&
7185+ loc < (me->module_core_rx + me->core_size_rx));
7186+}
7187+
7188+static inline int in_core_rw(struct module *me, void *loc)
7189+{
7190+ return (loc >= me->module_core_rw &&
7191+ loc < (me->module_core_rw + me->core_size_rw));
7192 }
7193
7194 static inline int in_core(struct module *me, void *loc)
7195 {
7196- return (loc >= me->module_core &&
7197- loc <= (me->module_core + me->core_size));
7198+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7199 }
7200
7201 static inline int in_local(struct module *me, void *loc)
7202@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7203 }
7204
7205 /* align things a bit */
7206- me->core_size = ALIGN(me->core_size, 16);
7207- me->arch.got_offset = me->core_size;
7208- me->core_size += gots * sizeof(struct got_entry);
7209+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7210+ me->arch.got_offset = me->core_size_rw;
7211+ me->core_size_rw += gots * sizeof(struct got_entry);
7212
7213- me->core_size = ALIGN(me->core_size, 16);
7214- me->arch.fdesc_offset = me->core_size;
7215- me->core_size += fdescs * sizeof(Elf_Fdesc);
7216+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7217+ me->arch.fdesc_offset = me->core_size_rw;
7218+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7219
7220 me->arch.got_max = gots;
7221 me->arch.fdesc_max = fdescs;
7222@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7223
7224 BUG_ON(value == 0);
7225
7226- got = me->module_core + me->arch.got_offset;
7227+ got = me->module_core_rw + me->arch.got_offset;
7228 for (i = 0; got[i].addr; i++)
7229 if (got[i].addr == value)
7230 goto out;
7231@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7232 #ifdef CONFIG_64BIT
7233 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7234 {
7235- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7236+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7237
7238 if (!value) {
7239 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7240@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7241
7242 /* Create new one */
7243 fdesc->addr = value;
7244- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7245+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7246 return (Elf_Addr)fdesc;
7247 }
7248 #endif /* CONFIG_64BIT */
7249@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7250
7251 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7252 end = table + sechdrs[me->arch.unwind_section].sh_size;
7253- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7254+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7255
7256 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7257 me->arch.unwind_section, table, end, gp);
7258diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7259index 0d3a9d4..20a99b0 100644
7260--- a/arch/parisc/kernel/sys_parisc.c
7261+++ b/arch/parisc/kernel/sys_parisc.c
7262@@ -33,9 +33,11 @@
7263 #include <linux/utsname.h>
7264 #include <linux/personality.h>
7265
7266-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7267+static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7268+ unsigned long flags)
7269 {
7270 struct vm_unmapped_area_info info;
7271+ unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7272
7273 info.flags = 0;
7274 info.length = len;
7275@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7276 info.high_limit = TASK_SIZE;
7277 info.align_mask = 0;
7278 info.align_offset = 0;
7279+ info.threadstack_offset = offset;
7280 return vm_unmapped_area(&info);
7281 }
7282
7283@@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7284 }
7285
7286 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7287- unsigned long len, unsigned long pgoff)
7288+ unsigned long len, unsigned long pgoff, unsigned long flags)
7289 {
7290 struct vm_unmapped_area_info info;
7291+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7292
7293 info.flags = 0;
7294 info.length = len;
7295@@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7296 info.high_limit = TASK_SIZE;
7297 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7298 info.align_offset = shared_align_offset(filp, pgoff);
7299+ info.threadstack_offset = offset;
7300 return vm_unmapped_area(&info);
7301 }
7302
7303@@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7304 return -EINVAL;
7305 return addr;
7306 }
7307- if (!addr)
7308+ if (!addr) {
7309 addr = TASK_UNMAPPED_BASE;
7310
7311+#ifdef CONFIG_PAX_RANDMMAP
7312+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7313+ addr += current->mm->delta_mmap;
7314+#endif
7315+
7316+ }
7317+
7318 if (filp || (flags & MAP_SHARED))
7319- addr = get_shared_area(filp, addr, len, pgoff);
7320+ addr = get_shared_area(filp, addr, len, pgoff, flags);
7321 else
7322- addr = get_unshared_area(addr, len);
7323+ addr = get_unshared_area(addr, len, flags);
7324
7325 return addr;
7326 }
7327diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7328index 1cd1d0c..44ec918 100644
7329--- a/arch/parisc/kernel/traps.c
7330+++ b/arch/parisc/kernel/traps.c
7331@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7332
7333 down_read(&current->mm->mmap_sem);
7334 vma = find_vma(current->mm,regs->iaoq[0]);
7335- if (vma && (regs->iaoq[0] >= vma->vm_start)
7336- && (vma->vm_flags & VM_EXEC)) {
7337-
7338+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7339 fault_address = regs->iaoq[0];
7340 fault_space = regs->iasq[0];
7341
7342diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7343index 9d08c71..e2b4d20 100644
7344--- a/arch/parisc/mm/fault.c
7345+++ b/arch/parisc/mm/fault.c
7346@@ -15,6 +15,7 @@
7347 #include <linux/sched.h>
7348 #include <linux/interrupt.h>
7349 #include <linux/module.h>
7350+#include <linux/unistd.h>
7351
7352 #include <asm/uaccess.h>
7353 #include <asm/traps.h>
7354@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7355 static unsigned long
7356 parisc_acctyp(unsigned long code, unsigned int inst)
7357 {
7358- if (code == 6 || code == 16)
7359+ if (code == 6 || code == 7 || code == 16)
7360 return VM_EXEC;
7361
7362 switch (inst & 0xf0000000) {
7363@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7364 }
7365 #endif
7366
7367+#ifdef CONFIG_PAX_PAGEEXEC
7368+/*
7369+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7370+ *
7371+ * returns 1 when task should be killed
7372+ * 2 when rt_sigreturn trampoline was detected
7373+ * 3 when unpatched PLT trampoline was detected
7374+ */
7375+static int pax_handle_fetch_fault(struct pt_regs *regs)
7376+{
7377+
7378+#ifdef CONFIG_PAX_EMUPLT
7379+ int err;
7380+
7381+ do { /* PaX: unpatched PLT emulation */
7382+ unsigned int bl, depwi;
7383+
7384+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7385+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7386+
7387+ if (err)
7388+ break;
7389+
7390+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7391+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7392+
7393+ err = get_user(ldw, (unsigned int *)addr);
7394+ err |= get_user(bv, (unsigned int *)(addr+4));
7395+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7396+
7397+ if (err)
7398+ break;
7399+
7400+ if (ldw == 0x0E801096U &&
7401+ bv == 0xEAC0C000U &&
7402+ ldw2 == 0x0E881095U)
7403+ {
7404+ unsigned int resolver, map;
7405+
7406+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7407+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7408+ if (err)
7409+ break;
7410+
7411+ regs->gr[20] = instruction_pointer(regs)+8;
7412+ regs->gr[21] = map;
7413+ regs->gr[22] = resolver;
7414+ regs->iaoq[0] = resolver | 3UL;
7415+ regs->iaoq[1] = regs->iaoq[0] + 4;
7416+ return 3;
7417+ }
7418+ }
7419+ } while (0);
7420+#endif
7421+
7422+#ifdef CONFIG_PAX_EMUTRAMP
7423+
7424+#ifndef CONFIG_PAX_EMUSIGRT
7425+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7426+ return 1;
7427+#endif
7428+
7429+ do { /* PaX: rt_sigreturn emulation */
7430+ unsigned int ldi1, ldi2, bel, nop;
7431+
7432+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7433+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7434+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7435+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7436+
7437+ if (err)
7438+ break;
7439+
7440+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7441+ ldi2 == 0x3414015AU &&
7442+ bel == 0xE4008200U &&
7443+ nop == 0x08000240U)
7444+ {
7445+ regs->gr[25] = (ldi1 & 2) >> 1;
7446+ regs->gr[20] = __NR_rt_sigreturn;
7447+ regs->gr[31] = regs->iaoq[1] + 16;
7448+ regs->sr[0] = regs->iasq[1];
7449+ regs->iaoq[0] = 0x100UL;
7450+ regs->iaoq[1] = regs->iaoq[0] + 4;
7451+ regs->iasq[0] = regs->sr[2];
7452+ regs->iasq[1] = regs->sr[2];
7453+ return 2;
7454+ }
7455+ } while (0);
7456+#endif
7457+
7458+ return 1;
7459+}
7460+
7461+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7462+{
7463+ unsigned long i;
7464+
7465+ printk(KERN_ERR "PAX: bytes at PC: ");
7466+ for (i = 0; i < 5; i++) {
7467+ unsigned int c;
7468+ if (get_user(c, (unsigned int *)pc+i))
7469+ printk(KERN_CONT "???????? ");
7470+ else
7471+ printk(KERN_CONT "%08x ", c);
7472+ }
7473+ printk("\n");
7474+}
7475+#endif
7476+
7477 int fixup_exception(struct pt_regs *regs)
7478 {
7479 const struct exception_table_entry *fix;
7480@@ -210,8 +321,33 @@ retry:
7481
7482 good_area:
7483
7484- if ((vma->vm_flags & acc_type) != acc_type)
7485+ if ((vma->vm_flags & acc_type) != acc_type) {
7486+
7487+#ifdef CONFIG_PAX_PAGEEXEC
7488+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7489+ (address & ~3UL) == instruction_pointer(regs))
7490+ {
7491+ up_read(&mm->mmap_sem);
7492+ switch (pax_handle_fetch_fault(regs)) {
7493+
7494+#ifdef CONFIG_PAX_EMUPLT
7495+ case 3:
7496+ return;
7497+#endif
7498+
7499+#ifdef CONFIG_PAX_EMUTRAMP
7500+ case 2:
7501+ return;
7502+#endif
7503+
7504+ }
7505+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7506+ do_group_exit(SIGKILL);
7507+ }
7508+#endif
7509+
7510 goto bad_area;
7511+ }
7512
7513 /*
7514 * If for any reason at all we couldn't handle the fault, make
7515diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7516index b44b52c..4cd253c 100644
7517--- a/arch/powerpc/Kconfig
7518+++ b/arch/powerpc/Kconfig
7519@@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7520 config KEXEC
7521 bool "kexec system call"
7522 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7523+ depends on !GRKERNSEC_KMEM
7524 help
7525 kexec is a system call that implements the ability to shutdown your
7526 current kernel, and to start another kernel. It is like a reboot
7527diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7528index e3b1d41..8e81edf 100644
7529--- a/arch/powerpc/include/asm/atomic.h
7530+++ b/arch/powerpc/include/asm/atomic.h
7531@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7532 return t1;
7533 }
7534
7535+#define atomic64_read_unchecked(v) atomic64_read(v)
7536+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7537+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7538+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7539+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7540+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7541+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7542+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7543+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7544+
7545 #endif /* __powerpc64__ */
7546
7547 #endif /* __KERNEL__ */
7548diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7549index 9e495c9..b6878e5 100644
7550--- a/arch/powerpc/include/asm/cache.h
7551+++ b/arch/powerpc/include/asm/cache.h
7552@@ -3,6 +3,7 @@
7553
7554 #ifdef __KERNEL__
7555
7556+#include <linux/const.h>
7557
7558 /* bytes per L1 cache line */
7559 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7560@@ -22,7 +23,7 @@
7561 #define L1_CACHE_SHIFT 7
7562 #endif
7563
7564-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7565+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7566
7567 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7568
7569diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7570index 935b5e7..7001d2d 100644
7571--- a/arch/powerpc/include/asm/elf.h
7572+++ b/arch/powerpc/include/asm/elf.h
7573@@ -28,8 +28,19 @@
7574 the loader. We need to make sure that it is out of the way of the program
7575 that it will "exec", and that there is sufficient room for the brk. */
7576
7577-extern unsigned long randomize_et_dyn(unsigned long base);
7578-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7579+#define ELF_ET_DYN_BASE (0x20000000)
7580+
7581+#ifdef CONFIG_PAX_ASLR
7582+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7583+
7584+#ifdef __powerpc64__
7585+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7586+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7587+#else
7588+#define PAX_DELTA_MMAP_LEN 15
7589+#define PAX_DELTA_STACK_LEN 15
7590+#endif
7591+#endif
7592
7593 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7594
7595@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7596 (0x7ff >> (PAGE_SHIFT - 12)) : \
7597 (0x3ffff >> (PAGE_SHIFT - 12)))
7598
7599-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7600-#define arch_randomize_brk arch_randomize_brk
7601-
7602-
7603 #ifdef CONFIG_SPU_BASE
7604 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7605 #define NT_SPU 1
7606diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7607index 8196e9c..d83a9f3 100644
7608--- a/arch/powerpc/include/asm/exec.h
7609+++ b/arch/powerpc/include/asm/exec.h
7610@@ -4,6 +4,6 @@
7611 #ifndef _ASM_POWERPC_EXEC_H
7612 #define _ASM_POWERPC_EXEC_H
7613
7614-extern unsigned long arch_align_stack(unsigned long sp);
7615+#define arch_align_stack(x) ((x) & ~0xfUL)
7616
7617 #endif /* _ASM_POWERPC_EXEC_H */
7618diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7619index 5acabbd..7ea14fa 100644
7620--- a/arch/powerpc/include/asm/kmap_types.h
7621+++ b/arch/powerpc/include/asm/kmap_types.h
7622@@ -10,7 +10,7 @@
7623 * 2 of the License, or (at your option) any later version.
7624 */
7625
7626-#define KM_TYPE_NR 16
7627+#define KM_TYPE_NR 17
7628
7629 #endif /* __KERNEL__ */
7630 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7631diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7632index 8565c25..2865190 100644
7633--- a/arch/powerpc/include/asm/mman.h
7634+++ b/arch/powerpc/include/asm/mman.h
7635@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7636 }
7637 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7638
7639-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7640+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7641 {
7642 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7643 }
7644diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7645index 32e4e21..62afb12 100644
7646--- a/arch/powerpc/include/asm/page.h
7647+++ b/arch/powerpc/include/asm/page.h
7648@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7649 * and needs to be executable. This means the whole heap ends
7650 * up being executable.
7651 */
7652-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7653- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7654+#define VM_DATA_DEFAULT_FLAGS32 \
7655+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7656+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7657
7658 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7659 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7660@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7661 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7662 #endif
7663
7664+#define ktla_ktva(addr) (addr)
7665+#define ktva_ktla(addr) (addr)
7666+
7667 #ifndef CONFIG_PPC_BOOK3S_64
7668 /*
7669 * Use the top bit of the higher-level page table entries to indicate whether
7670diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7671index 88693ce..ac6f9ab 100644
7672--- a/arch/powerpc/include/asm/page_64.h
7673+++ b/arch/powerpc/include/asm/page_64.h
7674@@ -153,15 +153,18 @@ do { \
7675 * stack by default, so in the absence of a PT_GNU_STACK program header
7676 * we turn execute permission off.
7677 */
7678-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7679- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7680+#define VM_STACK_DEFAULT_FLAGS32 \
7681+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7682+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7683
7684 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7685 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7686
7687+#ifndef CONFIG_PAX_PAGEEXEC
7688 #define VM_STACK_DEFAULT_FLAGS \
7689 (is_32bit_task() ? \
7690 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7691+#endif
7692
7693 #include <asm-generic/getorder.h>
7694
7695diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7696index 4b0be20..c15a27d 100644
7697--- a/arch/powerpc/include/asm/pgalloc-64.h
7698+++ b/arch/powerpc/include/asm/pgalloc-64.h
7699@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7700 #ifndef CONFIG_PPC_64K_PAGES
7701
7702 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7703+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7704
7705 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7706 {
7707@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7708 pud_set(pud, (unsigned long)pmd);
7709 }
7710
7711+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7712+{
7713+ pud_populate(mm, pud, pmd);
7714+}
7715+
7716 #define pmd_populate(mm, pmd, pte_page) \
7717 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7718 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7719@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
7720 #endif
7721
7722 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7723+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7724
7725 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7726 pte_t *pte)
7727diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7728index 7d6eacf..14c0240 100644
7729--- a/arch/powerpc/include/asm/pgtable.h
7730+++ b/arch/powerpc/include/asm/pgtable.h
7731@@ -2,6 +2,7 @@
7732 #define _ASM_POWERPC_PGTABLE_H
7733 #ifdef __KERNEL__
7734
7735+#include <linux/const.h>
7736 #ifndef __ASSEMBLY__
7737 #include <asm/processor.h> /* For TASK_SIZE */
7738 #include <asm/mmu.h>
7739diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7740index 4aad413..85d86bf 100644
7741--- a/arch/powerpc/include/asm/pte-hash32.h
7742+++ b/arch/powerpc/include/asm/pte-hash32.h
7743@@ -21,6 +21,7 @@
7744 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7745 #define _PAGE_USER 0x004 /* usermode access allowed */
7746 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7747+#define _PAGE_EXEC _PAGE_GUARDED
7748 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7749 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7750 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7751diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7752index fa8388e..f985549 100644
7753--- a/arch/powerpc/include/asm/reg.h
7754+++ b/arch/powerpc/include/asm/reg.h
7755@@ -239,6 +239,7 @@
7756 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7757 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7758 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7759+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7760 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7761 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7762 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7763diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7764index 084e080..9415a3d 100644
7765--- a/arch/powerpc/include/asm/smp.h
7766+++ b/arch/powerpc/include/asm/smp.h
7767@@ -51,7 +51,7 @@ struct smp_ops_t {
7768 int (*cpu_disable)(void);
7769 void (*cpu_die)(unsigned int nr);
7770 int (*cpu_bootable)(unsigned int nr);
7771-};
7772+} __no_const;
7773
7774 extern void smp_send_debugger_break(void);
7775 extern void start_secondary_resume(void);
7776diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7777index 9854c56..7517190 100644
7778--- a/arch/powerpc/include/asm/thread_info.h
7779+++ b/arch/powerpc/include/asm/thread_info.h
7780@@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
7781 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7782 TIF_NEED_RESCHED */
7783 #define TIF_32BIT 4 /* 32 bit binary */
7784-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7785 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7786 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7787 #define TIF_SINGLESTEP 8 /* singlestepping active */
7788@@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
7789 #if defined(CONFIG_PPC64)
7790 #define TIF_ELF2ABI 18 /* function descriptors must die! */
7791 #endif
7792+#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
7793+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7794+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7795
7796 /* as above, but as bit values */
7797 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7798@@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
7799 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7800 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7801 #define _TIF_NOHZ (1<<TIF_NOHZ)
7802+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7803 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7804 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7805- _TIF_NOHZ)
7806+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7807
7808 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7809 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7810diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7811index 9485b43..4718d50 100644
7812--- a/arch/powerpc/include/asm/uaccess.h
7813+++ b/arch/powerpc/include/asm/uaccess.h
7814@@ -318,52 +318,6 @@ do { \
7815 extern unsigned long __copy_tofrom_user(void __user *to,
7816 const void __user *from, unsigned long size);
7817
7818-#ifndef __powerpc64__
7819-
7820-static inline unsigned long copy_from_user(void *to,
7821- const void __user *from, unsigned long n)
7822-{
7823- unsigned long over;
7824-
7825- if (access_ok(VERIFY_READ, from, n))
7826- return __copy_tofrom_user((__force void __user *)to, from, n);
7827- if ((unsigned long)from < TASK_SIZE) {
7828- over = (unsigned long)from + n - TASK_SIZE;
7829- return __copy_tofrom_user((__force void __user *)to, from,
7830- n - over) + over;
7831- }
7832- return n;
7833-}
7834-
7835-static inline unsigned long copy_to_user(void __user *to,
7836- const void *from, unsigned long n)
7837-{
7838- unsigned long over;
7839-
7840- if (access_ok(VERIFY_WRITE, to, n))
7841- return __copy_tofrom_user(to, (__force void __user *)from, n);
7842- if ((unsigned long)to < TASK_SIZE) {
7843- over = (unsigned long)to + n - TASK_SIZE;
7844- return __copy_tofrom_user(to, (__force void __user *)from,
7845- n - over) + over;
7846- }
7847- return n;
7848-}
7849-
7850-#else /* __powerpc64__ */
7851-
7852-#define __copy_in_user(to, from, size) \
7853- __copy_tofrom_user((to), (from), (size))
7854-
7855-extern unsigned long copy_from_user(void *to, const void __user *from,
7856- unsigned long n);
7857-extern unsigned long copy_to_user(void __user *to, const void *from,
7858- unsigned long n);
7859-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7860- unsigned long n);
7861-
7862-#endif /* __powerpc64__ */
7863-
7864 static inline unsigned long __copy_from_user_inatomic(void *to,
7865 const void __user *from, unsigned long n)
7866 {
7867@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7868 if (ret == 0)
7869 return 0;
7870 }
7871+
7872+ if (!__builtin_constant_p(n))
7873+ check_object_size(to, n, false);
7874+
7875 return __copy_tofrom_user((__force void __user *)to, from, n);
7876 }
7877
7878@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7879 if (ret == 0)
7880 return 0;
7881 }
7882+
7883+ if (!__builtin_constant_p(n))
7884+ check_object_size(from, n, true);
7885+
7886 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7887 }
7888
7889@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7890 return __copy_to_user_inatomic(to, from, size);
7891 }
7892
7893+#ifndef __powerpc64__
7894+
7895+static inline unsigned long __must_check copy_from_user(void *to,
7896+ const void __user *from, unsigned long n)
7897+{
7898+ unsigned long over;
7899+
7900+ if ((long)n < 0)
7901+ return n;
7902+
7903+ if (access_ok(VERIFY_READ, from, n)) {
7904+ if (!__builtin_constant_p(n))
7905+ check_object_size(to, n, false);
7906+ return __copy_tofrom_user((__force void __user *)to, from, n);
7907+ }
7908+ if ((unsigned long)from < TASK_SIZE) {
7909+ over = (unsigned long)from + n - TASK_SIZE;
7910+ if (!__builtin_constant_p(n - over))
7911+ check_object_size(to, n - over, false);
7912+ return __copy_tofrom_user((__force void __user *)to, from,
7913+ n - over) + over;
7914+ }
7915+ return n;
7916+}
7917+
7918+static inline unsigned long __must_check copy_to_user(void __user *to,
7919+ const void *from, unsigned long n)
7920+{
7921+ unsigned long over;
7922+
7923+ if ((long)n < 0)
7924+ return n;
7925+
7926+ if (access_ok(VERIFY_WRITE, to, n)) {
7927+ if (!__builtin_constant_p(n))
7928+ check_object_size(from, n, true);
7929+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7930+ }
7931+ if ((unsigned long)to < TASK_SIZE) {
7932+ over = (unsigned long)to + n - TASK_SIZE;
7933+ if (!__builtin_constant_p(n))
7934+ check_object_size(from, n - over, true);
7935+ return __copy_tofrom_user(to, (__force void __user *)from,
7936+ n - over) + over;
7937+ }
7938+ return n;
7939+}
7940+
7941+#else /* __powerpc64__ */
7942+
7943+#define __copy_in_user(to, from, size) \
7944+ __copy_tofrom_user((to), (from), (size))
7945+
7946+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7947+{
7948+ if ((long)n < 0 || n > INT_MAX)
7949+ return n;
7950+
7951+ if (!__builtin_constant_p(n))
7952+ check_object_size(to, n, false);
7953+
7954+ if (likely(access_ok(VERIFY_READ, from, n)))
7955+ n = __copy_from_user(to, from, n);
7956+ else
7957+ memset(to, 0, n);
7958+ return n;
7959+}
7960+
7961+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7962+{
7963+ if ((long)n < 0 || n > INT_MAX)
7964+ return n;
7965+
7966+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7967+ if (!__builtin_constant_p(n))
7968+ check_object_size(from, n, true);
7969+ n = __copy_to_user(to, from, n);
7970+ }
7971+ return n;
7972+}
7973+
7974+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7975+ unsigned long n);
7976+
7977+#endif /* __powerpc64__ */
7978+
7979 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7980
7981 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7982diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7983index e775156..af2d1c0 100644
7984--- a/arch/powerpc/kernel/exceptions-64e.S
7985+++ b/arch/powerpc/kernel/exceptions-64e.S
7986@@ -759,6 +759,7 @@ storage_fault_common:
7987 std r14,_DAR(r1)
7988 std r15,_DSISR(r1)
7989 addi r3,r1,STACK_FRAME_OVERHEAD
7990+ bl .save_nvgprs
7991 mr r4,r14
7992 mr r5,r15
7993 ld r14,PACA_EXGEN+EX_R14(r13)
7994@@ -767,8 +768,7 @@ storage_fault_common:
7995 cmpdi r3,0
7996 bne- 1f
7997 b .ret_from_except_lite
7998-1: bl .save_nvgprs
7999- mr r5,r3
8000+1: mr r5,r3
8001 addi r3,r1,STACK_FRAME_OVERHEAD
8002 ld r4,_DAR(r1)
8003 bl .bad_page_fault
8004diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8005index 9f905e4..1d6b3d2 100644
8006--- a/arch/powerpc/kernel/exceptions-64s.S
8007+++ b/arch/powerpc/kernel/exceptions-64s.S
8008@@ -1390,10 +1390,10 @@ handle_page_fault:
8009 11: ld r4,_DAR(r1)
8010 ld r5,_DSISR(r1)
8011 addi r3,r1,STACK_FRAME_OVERHEAD
8012+ bl .save_nvgprs
8013 bl .do_page_fault
8014 cmpdi r3,0
8015 beq+ 12f
8016- bl .save_nvgprs
8017 mr r5,r3
8018 addi r3,r1,STACK_FRAME_OVERHEAD
8019 lwz r4,_DAR(r1)
8020diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8021index 6cff040..74ac5d1 100644
8022--- a/arch/powerpc/kernel/module_32.c
8023+++ b/arch/powerpc/kernel/module_32.c
8024@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8025 me->arch.core_plt_section = i;
8026 }
8027 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8028- printk("Module doesn't contain .plt or .init.plt sections.\n");
8029+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8030 return -ENOEXEC;
8031 }
8032
8033@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8034
8035 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8036 /* Init, or core PLT? */
8037- if (location >= mod->module_core
8038- && location < mod->module_core + mod->core_size)
8039+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8040+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8041 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8042- else
8043+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8044+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8045 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8046+ else {
8047+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8048+ return ~0UL;
8049+ }
8050
8051 /* Find this entry, or if that fails, the next avail. entry */
8052 while (entry->jump[0]) {
8053@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8054 }
8055 #ifdef CONFIG_DYNAMIC_FTRACE
8056 module->arch.tramp =
8057- do_plt_call(module->module_core,
8058+ do_plt_call(module->module_core_rx,
8059 (unsigned long)ftrace_caller,
8060 sechdrs, module);
8061 #endif
8062diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8063index 4a96556..dd95f6c 100644
8064--- a/arch/powerpc/kernel/process.c
8065+++ b/arch/powerpc/kernel/process.c
8066@@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8067 * Lookup NIP late so we have the best change of getting the
8068 * above info out without failing
8069 */
8070- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8071- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8072+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8073+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8074 #endif
8075 show_stack(current, (unsigned long *) regs->gpr[1]);
8076 if (!user_mode(regs))
8077@@ -1376,10 +1376,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8078 newsp = stack[0];
8079 ip = stack[STACK_FRAME_LR_SAVE];
8080 if (!firstframe || ip != lr) {
8081- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8082+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8083 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8084 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8085- printk(" (%pS)",
8086+ printk(" (%pA)",
8087 (void *)current->ret_stack[curr_frame].ret);
8088 curr_frame--;
8089 }
8090@@ -1399,7 +1399,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8091 struct pt_regs *regs = (struct pt_regs *)
8092 (sp + STACK_FRAME_OVERHEAD);
8093 lr = regs->link;
8094- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8095+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8096 regs->trap, (void *)regs->nip, (void *)lr);
8097 firstframe = 1;
8098 }
8099@@ -1435,58 +1435,3 @@ void notrace __ppc64_runlatch_off(void)
8100 mtspr(SPRN_CTRLT, ctrl);
8101 }
8102 #endif /* CONFIG_PPC64 */
8103-
8104-unsigned long arch_align_stack(unsigned long sp)
8105-{
8106- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8107- sp -= get_random_int() & ~PAGE_MASK;
8108- return sp & ~0xf;
8109-}
8110-
8111-static inline unsigned long brk_rnd(void)
8112-{
8113- unsigned long rnd = 0;
8114-
8115- /* 8MB for 32bit, 1GB for 64bit */
8116- if (is_32bit_task())
8117- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8118- else
8119- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8120-
8121- return rnd << PAGE_SHIFT;
8122-}
8123-
8124-unsigned long arch_randomize_brk(struct mm_struct *mm)
8125-{
8126- unsigned long base = mm->brk;
8127- unsigned long ret;
8128-
8129-#ifdef CONFIG_PPC_STD_MMU_64
8130- /*
8131- * If we are using 1TB segments and we are allowed to randomise
8132- * the heap, we can put it above 1TB so it is backed by a 1TB
8133- * segment. Otherwise the heap will be in the bottom 1TB
8134- * which always uses 256MB segments and this may result in a
8135- * performance penalty.
8136- */
8137- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8138- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8139-#endif
8140-
8141- ret = PAGE_ALIGN(base + brk_rnd());
8142-
8143- if (ret < mm->brk)
8144- return mm->brk;
8145-
8146- return ret;
8147-}
8148-
8149-unsigned long randomize_et_dyn(unsigned long base)
8150-{
8151- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8152-
8153- if (ret < base)
8154- return base;
8155-
8156- return ret;
8157-}
8158diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8159index 2e3d2bf..35df241 100644
8160--- a/arch/powerpc/kernel/ptrace.c
8161+++ b/arch/powerpc/kernel/ptrace.c
8162@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8163 return ret;
8164 }
8165
8166+#ifdef CONFIG_GRKERNSEC_SETXID
8167+extern void gr_delayed_cred_worker(void);
8168+#endif
8169+
8170 /*
8171 * We must return the syscall number to actually look up in the table.
8172 * This can be -1L to skip running any syscall at all.
8173@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8174
8175 secure_computing_strict(regs->gpr[0]);
8176
8177+#ifdef CONFIG_GRKERNSEC_SETXID
8178+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8179+ gr_delayed_cred_worker();
8180+#endif
8181+
8182 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8183 tracehook_report_syscall_entry(regs))
8184 /*
8185@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8186 {
8187 int step;
8188
8189+#ifdef CONFIG_GRKERNSEC_SETXID
8190+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8191+ gr_delayed_cred_worker();
8192+#endif
8193+
8194 audit_syscall_exit(regs);
8195
8196 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8197diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8198index 68027bf..b26fd31 100644
8199--- a/arch/powerpc/kernel/signal_32.c
8200+++ b/arch/powerpc/kernel/signal_32.c
8201@@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8202 /* Save user registers on the stack */
8203 frame = &rt_sf->uc.uc_mcontext;
8204 addr = frame;
8205- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8206+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8207 sigret = 0;
8208 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8209 } else {
8210diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8211index 4299104..29e2c51 100644
8212--- a/arch/powerpc/kernel/signal_64.c
8213+++ b/arch/powerpc/kernel/signal_64.c
8214@@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8215 #endif
8216
8217 /* Set up to return from userspace. */
8218- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8219+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8220 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8221 } else {
8222 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8223diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8224index 907a472..4ba206f 100644
8225--- a/arch/powerpc/kernel/traps.c
8226+++ b/arch/powerpc/kernel/traps.c
8227@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8228 return flags;
8229 }
8230
8231+extern void gr_handle_kernel_exploit(void);
8232+
8233 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8234 int signr)
8235 {
8236@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8237 panic("Fatal exception in interrupt");
8238 if (panic_on_oops)
8239 panic("Fatal exception");
8240+
8241+ gr_handle_kernel_exploit();
8242+
8243 do_exit(signr);
8244 }
8245
8246diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8247index 094e45c..d82b848 100644
8248--- a/arch/powerpc/kernel/vdso.c
8249+++ b/arch/powerpc/kernel/vdso.c
8250@@ -35,6 +35,7 @@
8251 #include <asm/vdso.h>
8252 #include <asm/vdso_datapage.h>
8253 #include <asm/setup.h>
8254+#include <asm/mman.h>
8255
8256 #undef DEBUG
8257
8258@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8259 vdso_base = VDSO32_MBASE;
8260 #endif
8261
8262- current->mm->context.vdso_base = 0;
8263+ current->mm->context.vdso_base = ~0UL;
8264
8265 /* vDSO has a problem and was disabled, just don't "enable" it for the
8266 * process
8267@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8268 vdso_base = get_unmapped_area(NULL, vdso_base,
8269 (vdso_pages << PAGE_SHIFT) +
8270 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8271- 0, 0);
8272+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8273 if (IS_ERR_VALUE(vdso_base)) {
8274 rc = vdso_base;
8275 goto fail_mmapsem;
8276diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8277index 5eea6f3..5d10396 100644
8278--- a/arch/powerpc/lib/usercopy_64.c
8279+++ b/arch/powerpc/lib/usercopy_64.c
8280@@ -9,22 +9,6 @@
8281 #include <linux/module.h>
8282 #include <asm/uaccess.h>
8283
8284-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8285-{
8286- if (likely(access_ok(VERIFY_READ, from, n)))
8287- n = __copy_from_user(to, from, n);
8288- else
8289- memset(to, 0, n);
8290- return n;
8291-}
8292-
8293-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8294-{
8295- if (likely(access_ok(VERIFY_WRITE, to, n)))
8296- n = __copy_to_user(to, from, n);
8297- return n;
8298-}
8299-
8300 unsigned long copy_in_user(void __user *to, const void __user *from,
8301 unsigned long n)
8302 {
8303@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8304 return n;
8305 }
8306
8307-EXPORT_SYMBOL(copy_from_user);
8308-EXPORT_SYMBOL(copy_to_user);
8309 EXPORT_SYMBOL(copy_in_user);
8310
8311diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8312index 51ab9e7..7d3c78b 100644
8313--- a/arch/powerpc/mm/fault.c
8314+++ b/arch/powerpc/mm/fault.c
8315@@ -33,6 +33,10 @@
8316 #include <linux/magic.h>
8317 #include <linux/ratelimit.h>
8318 #include <linux/context_tracking.h>
8319+#include <linux/slab.h>
8320+#include <linux/pagemap.h>
8321+#include <linux/compiler.h>
8322+#include <linux/unistd.h>
8323
8324 #include <asm/firmware.h>
8325 #include <asm/page.h>
8326@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8327 }
8328 #endif
8329
8330+#ifdef CONFIG_PAX_PAGEEXEC
8331+/*
8332+ * PaX: decide what to do with offenders (regs->nip = fault address)
8333+ *
8334+ * returns 1 when task should be killed
8335+ */
8336+static int pax_handle_fetch_fault(struct pt_regs *regs)
8337+{
8338+ return 1;
8339+}
8340+
8341+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8342+{
8343+ unsigned long i;
8344+
8345+ printk(KERN_ERR "PAX: bytes at PC: ");
8346+ for (i = 0; i < 5; i++) {
8347+ unsigned int c;
8348+ if (get_user(c, (unsigned int __user *)pc+i))
8349+ printk(KERN_CONT "???????? ");
8350+ else
8351+ printk(KERN_CONT "%08x ", c);
8352+ }
8353+ printk("\n");
8354+}
8355+#endif
8356+
8357 /*
8358 * Check whether the instruction at regs->nip is a store using
8359 * an update addressing form which will update r1.
8360@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8361 * indicate errors in DSISR but can validly be set in SRR1.
8362 */
8363 if (trap == 0x400)
8364- error_code &= 0x48200000;
8365+ error_code &= 0x58200000;
8366 else
8367 is_write = error_code & DSISR_ISSTORE;
8368 #else
8369@@ -378,7 +409,7 @@ good_area:
8370 * "undefined". Of those that can be set, this is the only
8371 * one which seems bad.
8372 */
8373- if (error_code & 0x10000000)
8374+ if (error_code & DSISR_GUARDED)
8375 /* Guarded storage error. */
8376 goto bad_area;
8377 #endif /* CONFIG_8xx */
8378@@ -393,7 +424,7 @@ good_area:
8379 * processors use the same I/D cache coherency mechanism
8380 * as embedded.
8381 */
8382- if (error_code & DSISR_PROTFAULT)
8383+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8384 goto bad_area;
8385 #endif /* CONFIG_PPC_STD_MMU */
8386
8387@@ -483,6 +514,23 @@ bad_area:
8388 bad_area_nosemaphore:
8389 /* User mode accesses cause a SIGSEGV */
8390 if (user_mode(regs)) {
8391+
8392+#ifdef CONFIG_PAX_PAGEEXEC
8393+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8394+#ifdef CONFIG_PPC_STD_MMU
8395+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8396+#else
8397+ if (is_exec && regs->nip == address) {
8398+#endif
8399+ switch (pax_handle_fetch_fault(regs)) {
8400+ }
8401+
8402+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8403+ do_group_exit(SIGKILL);
8404+ }
8405+ }
8406+#endif
8407+
8408 _exception(SIGSEGV, regs, code, address);
8409 goto bail;
8410 }
8411diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8412index cb8bdbe..d770680 100644
8413--- a/arch/powerpc/mm/mmap.c
8414+++ b/arch/powerpc/mm/mmap.c
8415@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8416 {
8417 unsigned long rnd = 0;
8418
8419+#ifdef CONFIG_PAX_RANDMMAP
8420+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8421+#endif
8422+
8423 if (current->flags & PF_RANDOMIZE) {
8424 /* 8MB for 32bit, 1GB for 64bit */
8425 if (is_32bit_task())
8426@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8427 */
8428 if (mmap_is_legacy()) {
8429 mm->mmap_base = TASK_UNMAPPED_BASE;
8430+
8431+#ifdef CONFIG_PAX_RANDMMAP
8432+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8433+ mm->mmap_base += mm->delta_mmap;
8434+#endif
8435+
8436 mm->get_unmapped_area = arch_get_unmapped_area;
8437 } else {
8438 mm->mmap_base = mmap_base();
8439+
8440+#ifdef CONFIG_PAX_RANDMMAP
8441+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8442+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8443+#endif
8444+
8445 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8446 }
8447 }
8448diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8449index 7ce9cf3..a964087 100644
8450--- a/arch/powerpc/mm/slice.c
8451+++ b/arch/powerpc/mm/slice.c
8452@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8453 if ((mm->task_size - len) < addr)
8454 return 0;
8455 vma = find_vma(mm, addr);
8456- return (!vma || (addr + len) <= vma->vm_start);
8457+ return check_heap_stack_gap(vma, addr, len, 0);
8458 }
8459
8460 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8461@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8462 info.align_offset = 0;
8463
8464 addr = TASK_UNMAPPED_BASE;
8465+
8466+#ifdef CONFIG_PAX_RANDMMAP
8467+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8468+ addr += mm->delta_mmap;
8469+#endif
8470+
8471 while (addr < TASK_SIZE) {
8472 info.low_limit = addr;
8473 if (!slice_scan_available(addr, available, 1, &addr))
8474@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8475 if (fixed && addr > (mm->task_size - len))
8476 return -EINVAL;
8477
8478+#ifdef CONFIG_PAX_RANDMMAP
8479+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8480+ addr = 0;
8481+#endif
8482+
8483 /* If hint, make sure it matches our alignment restrictions */
8484 if (!fixed && addr) {
8485 addr = _ALIGN_UP(addr, 1ul << pshift);
8486diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8487index 9098692..3d54cd1 100644
8488--- a/arch/powerpc/platforms/cell/spufs/file.c
8489+++ b/arch/powerpc/platforms/cell/spufs/file.c
8490@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8491 return VM_FAULT_NOPAGE;
8492 }
8493
8494-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8495+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8496 unsigned long address,
8497- void *buf, int len, int write)
8498+ void *buf, size_t len, int write)
8499 {
8500 struct spu_context *ctx = vma->vm_file->private_data;
8501 unsigned long offset = address - vma->vm_start;
8502diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8503index fa9aaf7..3f5d836 100644
8504--- a/arch/s390/include/asm/atomic.h
8505+++ b/arch/s390/include/asm/atomic.h
8506@@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8507 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8509
8510+#define atomic64_read_unchecked(v) atomic64_read(v)
8511+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8512+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8513+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8514+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8515+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8516+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8517+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8518+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8519+
8520 #define smp_mb__before_atomic_dec() smp_mb()
8521 #define smp_mb__after_atomic_dec() smp_mb()
8522 #define smp_mb__before_atomic_inc() smp_mb()
8523diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8524index 4d7ccac..d03d0ad 100644
8525--- a/arch/s390/include/asm/cache.h
8526+++ b/arch/s390/include/asm/cache.h
8527@@ -9,8 +9,10 @@
8528 #ifndef __ARCH_S390_CACHE_H
8529 #define __ARCH_S390_CACHE_H
8530
8531-#define L1_CACHE_BYTES 256
8532+#include <linux/const.h>
8533+
8534 #define L1_CACHE_SHIFT 8
8535+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8536 #define NET_SKB_PAD 32
8537
8538 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8539diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8540index 78f4f87..598ce39 100644
8541--- a/arch/s390/include/asm/elf.h
8542+++ b/arch/s390/include/asm/elf.h
8543@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8544 the loader. We need to make sure that it is out of the way of the program
8545 that it will "exec", and that there is sufficient room for the brk. */
8546
8547-extern unsigned long randomize_et_dyn(unsigned long base);
8548-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8549+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8550+
8551+#ifdef CONFIG_PAX_ASLR
8552+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8553+
8554+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8555+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8556+#endif
8557
8558 /* This yields a mask that user programs can use to figure out what
8559 instruction set this CPU supports. */
8560@@ -222,9 +228,6 @@ struct linux_binprm;
8561 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8562 int arch_setup_additional_pages(struct linux_binprm *, int);
8563
8564-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8565-#define arch_randomize_brk arch_randomize_brk
8566-
8567 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8568
8569 #endif
8570diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8571index c4a93d6..4d2a9b4 100644
8572--- a/arch/s390/include/asm/exec.h
8573+++ b/arch/s390/include/asm/exec.h
8574@@ -7,6 +7,6 @@
8575 #ifndef __ASM_EXEC_H
8576 #define __ASM_EXEC_H
8577
8578-extern unsigned long arch_align_stack(unsigned long sp);
8579+#define arch_align_stack(x) ((x) & ~0xfUL)
8580
8581 #endif /* __ASM_EXEC_H */
8582diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8583index 79330af..a3a7b06 100644
8584--- a/arch/s390/include/asm/uaccess.h
8585+++ b/arch/s390/include/asm/uaccess.h
8586@@ -245,6 +245,10 @@ static inline unsigned long __must_check
8587 copy_to_user(void __user *to, const void *from, unsigned long n)
8588 {
8589 might_fault();
8590+
8591+ if ((long)n < 0)
8592+ return n;
8593+
8594 return __copy_to_user(to, from, n);
8595 }
8596
8597@@ -268,6 +272,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8598 static inline unsigned long __must_check
8599 __copy_from_user(void *to, const void __user *from, unsigned long n)
8600 {
8601+ if ((long)n < 0)
8602+ return n;
8603+
8604 return uaccess.copy_from_user(n, from, to);
8605 }
8606
8607@@ -296,10 +303,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8608 static inline unsigned long __must_check
8609 copy_from_user(void *to, const void __user *from, unsigned long n)
8610 {
8611- unsigned int sz = __compiletime_object_size(to);
8612+ size_t sz = __compiletime_object_size(to);
8613
8614 might_fault();
8615- if (unlikely(sz != -1 && sz < n)) {
8616+
8617+ if ((long)n < 0)
8618+ return n;
8619+
8620+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8621 copy_from_user_overflow();
8622 return n;
8623 }
8624diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8625index b89b591..fd9609d 100644
8626--- a/arch/s390/kernel/module.c
8627+++ b/arch/s390/kernel/module.c
8628@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8629
8630 /* Increase core size by size of got & plt and set start
8631 offsets for got and plt. */
8632- me->core_size = ALIGN(me->core_size, 4);
8633- me->arch.got_offset = me->core_size;
8634- me->core_size += me->arch.got_size;
8635- me->arch.plt_offset = me->core_size;
8636- me->core_size += me->arch.plt_size;
8637+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8638+ me->arch.got_offset = me->core_size_rw;
8639+ me->core_size_rw += me->arch.got_size;
8640+ me->arch.plt_offset = me->core_size_rx;
8641+ me->core_size_rx += me->arch.plt_size;
8642 return 0;
8643 }
8644
8645@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8646 if (info->got_initialized == 0) {
8647 Elf_Addr *gotent;
8648
8649- gotent = me->module_core + me->arch.got_offset +
8650+ gotent = me->module_core_rw + me->arch.got_offset +
8651 info->got_offset;
8652 *gotent = val;
8653 info->got_initialized = 1;
8654@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8655 rc = apply_rela_bits(loc, val, 0, 64, 0);
8656 else if (r_type == R_390_GOTENT ||
8657 r_type == R_390_GOTPLTENT) {
8658- val += (Elf_Addr) me->module_core - loc;
8659+ val += (Elf_Addr) me->module_core_rw - loc;
8660 rc = apply_rela_bits(loc, val, 1, 32, 1);
8661 }
8662 break;
8663@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8664 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8665 if (info->plt_initialized == 0) {
8666 unsigned int *ip;
8667- ip = me->module_core + me->arch.plt_offset +
8668+ ip = me->module_core_rx + me->arch.plt_offset +
8669 info->plt_offset;
8670 #ifndef CONFIG_64BIT
8671 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8672@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8673 val - loc + 0xffffUL < 0x1ffffeUL) ||
8674 (r_type == R_390_PLT32DBL &&
8675 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8676- val = (Elf_Addr) me->module_core +
8677+ val = (Elf_Addr) me->module_core_rx +
8678 me->arch.plt_offset +
8679 info->plt_offset;
8680 val += rela->r_addend - loc;
8681@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8682 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8683 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8684 val = val + rela->r_addend -
8685- ((Elf_Addr) me->module_core + me->arch.got_offset);
8686+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8687 if (r_type == R_390_GOTOFF16)
8688 rc = apply_rela_bits(loc, val, 0, 16, 0);
8689 else if (r_type == R_390_GOTOFF32)
8690@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8691 break;
8692 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8693 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8694- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8695+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8696 rela->r_addend - loc;
8697 if (r_type == R_390_GOTPC)
8698 rc = apply_rela_bits(loc, val, 1, 32, 0);
8699diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8700index 7ed0d4e..1dfc145 100644
8701--- a/arch/s390/kernel/process.c
8702+++ b/arch/s390/kernel/process.c
8703@@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
8704 }
8705 return 0;
8706 }
8707-
8708-unsigned long arch_align_stack(unsigned long sp)
8709-{
8710- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8711- sp -= get_random_int() & ~PAGE_MASK;
8712- return sp & ~0xf;
8713-}
8714-
8715-static inline unsigned long brk_rnd(void)
8716-{
8717- /* 8MB for 32bit, 1GB for 64bit */
8718- if (is_32bit_task())
8719- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8720- else
8721- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8722-}
8723-
8724-unsigned long arch_randomize_brk(struct mm_struct *mm)
8725-{
8726- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8727-
8728- if (ret < mm->brk)
8729- return mm->brk;
8730- return ret;
8731-}
8732-
8733-unsigned long randomize_et_dyn(unsigned long base)
8734-{
8735- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8736-
8737- if (!(current->flags & PF_RANDOMIZE))
8738- return base;
8739- if (ret < base)
8740- return base;
8741- return ret;
8742-}
8743diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8744index 9b436c2..54fbf0a 100644
8745--- a/arch/s390/mm/mmap.c
8746+++ b/arch/s390/mm/mmap.c
8747@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8748 */
8749 if (mmap_is_legacy()) {
8750 mm->mmap_base = mmap_base_legacy();
8751+
8752+#ifdef CONFIG_PAX_RANDMMAP
8753+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8754+ mm->mmap_base += mm->delta_mmap;
8755+#endif
8756+
8757 mm->get_unmapped_area = arch_get_unmapped_area;
8758 } else {
8759 mm->mmap_base = mmap_base();
8760+
8761+#ifdef CONFIG_PAX_RANDMMAP
8762+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8763+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8764+#endif
8765+
8766 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8767 }
8768 }
8769@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8770 */
8771 if (mmap_is_legacy()) {
8772 mm->mmap_base = mmap_base_legacy();
8773+
8774+#ifdef CONFIG_PAX_RANDMMAP
8775+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8776+ mm->mmap_base += mm->delta_mmap;
8777+#endif
8778+
8779 mm->get_unmapped_area = s390_get_unmapped_area;
8780 } else {
8781 mm->mmap_base = mmap_base();
8782+
8783+#ifdef CONFIG_PAX_RANDMMAP
8784+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8785+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8786+#endif
8787+
8788 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8789 }
8790 }
8791diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8792index ae3d59f..f65f075 100644
8793--- a/arch/score/include/asm/cache.h
8794+++ b/arch/score/include/asm/cache.h
8795@@ -1,7 +1,9 @@
8796 #ifndef _ASM_SCORE_CACHE_H
8797 #define _ASM_SCORE_CACHE_H
8798
8799+#include <linux/const.h>
8800+
8801 #define L1_CACHE_SHIFT 4
8802-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8803+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8804
8805 #endif /* _ASM_SCORE_CACHE_H */
8806diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8807index f9f3cd5..58ff438 100644
8808--- a/arch/score/include/asm/exec.h
8809+++ b/arch/score/include/asm/exec.h
8810@@ -1,6 +1,6 @@
8811 #ifndef _ASM_SCORE_EXEC_H
8812 #define _ASM_SCORE_EXEC_H
8813
8814-extern unsigned long arch_align_stack(unsigned long sp);
8815+#define arch_align_stack(x) (x)
8816
8817 #endif /* _ASM_SCORE_EXEC_H */
8818diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8819index a1519ad3..e8ac1ff 100644
8820--- a/arch/score/kernel/process.c
8821+++ b/arch/score/kernel/process.c
8822@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8823
8824 return task_pt_regs(task)->cp0_epc;
8825 }
8826-
8827-unsigned long arch_align_stack(unsigned long sp)
8828-{
8829- return sp;
8830-}
8831diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8832index ef9e555..331bd29 100644
8833--- a/arch/sh/include/asm/cache.h
8834+++ b/arch/sh/include/asm/cache.h
8835@@ -9,10 +9,11 @@
8836 #define __ASM_SH_CACHE_H
8837 #ifdef __KERNEL__
8838
8839+#include <linux/const.h>
8840 #include <linux/init.h>
8841 #include <cpu/cache.h>
8842
8843-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8844+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8845
8846 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8847
8848diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8849index 6777177..cb5e44f 100644
8850--- a/arch/sh/mm/mmap.c
8851+++ b/arch/sh/mm/mmap.c
8852@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8853 struct mm_struct *mm = current->mm;
8854 struct vm_area_struct *vma;
8855 int do_colour_align;
8856+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8857 struct vm_unmapped_area_info info;
8858
8859 if (flags & MAP_FIXED) {
8860@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8861 if (filp || (flags & MAP_SHARED))
8862 do_colour_align = 1;
8863
8864+#ifdef CONFIG_PAX_RANDMMAP
8865+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8866+#endif
8867+
8868 if (addr) {
8869 if (do_colour_align)
8870 addr = COLOUR_ALIGN(addr, pgoff);
8871@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8872 addr = PAGE_ALIGN(addr);
8873
8874 vma = find_vma(mm, addr);
8875- if (TASK_SIZE - len >= addr &&
8876- (!vma || addr + len <= vma->vm_start))
8877+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8878 return addr;
8879 }
8880
8881 info.flags = 0;
8882 info.length = len;
8883- info.low_limit = TASK_UNMAPPED_BASE;
8884+ info.low_limit = mm->mmap_base;
8885 info.high_limit = TASK_SIZE;
8886 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8887 info.align_offset = pgoff << PAGE_SHIFT;
8888@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8889 struct mm_struct *mm = current->mm;
8890 unsigned long addr = addr0;
8891 int do_colour_align;
8892+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8893 struct vm_unmapped_area_info info;
8894
8895 if (flags & MAP_FIXED) {
8896@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8897 if (filp || (flags & MAP_SHARED))
8898 do_colour_align = 1;
8899
8900+#ifdef CONFIG_PAX_RANDMMAP
8901+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8902+#endif
8903+
8904 /* requesting a specific address */
8905 if (addr) {
8906 if (do_colour_align)
8907@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8908 addr = PAGE_ALIGN(addr);
8909
8910 vma = find_vma(mm, addr);
8911- if (TASK_SIZE - len >= addr &&
8912- (!vma || addr + len <= vma->vm_start))
8913+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8914 return addr;
8915 }
8916
8917@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8918 VM_BUG_ON(addr != -ENOMEM);
8919 info.flags = 0;
8920 info.low_limit = TASK_UNMAPPED_BASE;
8921+
8922+#ifdef CONFIG_PAX_RANDMMAP
8923+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8924+ info.low_limit += mm->delta_mmap;
8925+#endif
8926+
8927 info.high_limit = TASK_SIZE;
8928 addr = vm_unmapped_area(&info);
8929 }
8930diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8931index be56a24..443328f 100644
8932--- a/arch/sparc/include/asm/atomic_64.h
8933+++ b/arch/sparc/include/asm/atomic_64.h
8934@@ -14,18 +14,40 @@
8935 #define ATOMIC64_INIT(i) { (i) }
8936
8937 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8938+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8939+{
8940+ return v->counter;
8941+}
8942 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8943+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8944+{
8945+ return v->counter;
8946+}
8947
8948 #define atomic_set(v, i) (((v)->counter) = i)
8949+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8950+{
8951+ v->counter = i;
8952+}
8953 #define atomic64_set(v, i) (((v)->counter) = i)
8954+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8955+{
8956+ v->counter = i;
8957+}
8958
8959 extern void atomic_add(int, atomic_t *);
8960+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8961 extern void atomic64_add(long, atomic64_t *);
8962+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8963 extern void atomic_sub(int, atomic_t *);
8964+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8965 extern void atomic64_sub(long, atomic64_t *);
8966+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8967
8968 extern int atomic_add_ret(int, atomic_t *);
8969+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8970 extern long atomic64_add_ret(long, atomic64_t *);
8971+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8972 extern int atomic_sub_ret(int, atomic_t *);
8973 extern long atomic64_sub_ret(long, atomic64_t *);
8974
8975@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8976 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8977
8978 #define atomic_inc_return(v) atomic_add_ret(1, v)
8979+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8980+{
8981+ return atomic_add_ret_unchecked(1, v);
8982+}
8983 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8984+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8985+{
8986+ return atomic64_add_ret_unchecked(1, v);
8987+}
8988
8989 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8990 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8991
8992 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8993+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8994+{
8995+ return atomic_add_ret_unchecked(i, v);
8996+}
8997 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8998+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8999+{
9000+ return atomic64_add_ret_unchecked(i, v);
9001+}
9002
9003 /*
9004 * atomic_inc_and_test - increment and test
9005@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9006 * other cases.
9007 */
9008 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9009+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9010+{
9011+ return atomic_inc_return_unchecked(v) == 0;
9012+}
9013 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9014
9015 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9016@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9017 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9018
9019 #define atomic_inc(v) atomic_add(1, v)
9020+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9021+{
9022+ atomic_add_unchecked(1, v);
9023+}
9024 #define atomic64_inc(v) atomic64_add(1, v)
9025+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9026+{
9027+ atomic64_add_unchecked(1, v);
9028+}
9029
9030 #define atomic_dec(v) atomic_sub(1, v)
9031+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9032+{
9033+ atomic_sub_unchecked(1, v);
9034+}
9035 #define atomic64_dec(v) atomic64_sub(1, v)
9036+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9037+{
9038+ atomic64_sub_unchecked(1, v);
9039+}
9040
9041 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9042 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9043
9044 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9045+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9046+{
9047+ return cmpxchg(&v->counter, old, new);
9048+}
9049 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9050+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9051+{
9052+ return xchg(&v->counter, new);
9053+}
9054
9055 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9056 {
9057- int c, old;
9058+ int c, old, new;
9059 c = atomic_read(v);
9060 for (;;) {
9061- if (unlikely(c == (u)))
9062+ if (unlikely(c == u))
9063 break;
9064- old = atomic_cmpxchg((v), c, c + (a));
9065+
9066+ asm volatile("addcc %2, %0, %0\n"
9067+
9068+#ifdef CONFIG_PAX_REFCOUNT
9069+ "tvs %%icc, 6\n"
9070+#endif
9071+
9072+ : "=r" (new)
9073+ : "0" (c), "ir" (a)
9074+ : "cc");
9075+
9076+ old = atomic_cmpxchg(v, c, new);
9077 if (likely(old == c))
9078 break;
9079 c = old;
9080@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9081 #define atomic64_cmpxchg(v, o, n) \
9082 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9083 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9084+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9085+{
9086+ return xchg(&v->counter, new);
9087+}
9088
9089 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9090 {
9091- long c, old;
9092+ long c, old, new;
9093 c = atomic64_read(v);
9094 for (;;) {
9095- if (unlikely(c == (u)))
9096+ if (unlikely(c == u))
9097 break;
9098- old = atomic64_cmpxchg((v), c, c + (a));
9099+
9100+ asm volatile("addcc %2, %0, %0\n"
9101+
9102+#ifdef CONFIG_PAX_REFCOUNT
9103+ "tvs %%xcc, 6\n"
9104+#endif
9105+
9106+ : "=r" (new)
9107+ : "0" (c), "ir" (a)
9108+ : "cc");
9109+
9110+ old = atomic64_cmpxchg(v, c, new);
9111 if (likely(old == c))
9112 break;
9113 c = old;
9114 }
9115- return c != (u);
9116+ return c != u;
9117 }
9118
9119 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9120diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9121index 5bb6991..5c2132e 100644
9122--- a/arch/sparc/include/asm/cache.h
9123+++ b/arch/sparc/include/asm/cache.h
9124@@ -7,10 +7,12 @@
9125 #ifndef _SPARC_CACHE_H
9126 #define _SPARC_CACHE_H
9127
9128+#include <linux/const.h>
9129+
9130 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9131
9132 #define L1_CACHE_SHIFT 5
9133-#define L1_CACHE_BYTES 32
9134+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9135
9136 #ifdef CONFIG_SPARC32
9137 #define SMP_CACHE_BYTES_SHIFT 5
9138diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9139index a24e41f..47677ff 100644
9140--- a/arch/sparc/include/asm/elf_32.h
9141+++ b/arch/sparc/include/asm/elf_32.h
9142@@ -114,6 +114,13 @@ typedef struct {
9143
9144 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9145
9146+#ifdef CONFIG_PAX_ASLR
9147+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9148+
9149+#define PAX_DELTA_MMAP_LEN 16
9150+#define PAX_DELTA_STACK_LEN 16
9151+#endif
9152+
9153 /* This yields a mask that user programs can use to figure out what
9154 instruction set this cpu supports. This can NOT be done in userspace
9155 on Sparc. */
9156diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9157index 370ca1e..d4f4a98 100644
9158--- a/arch/sparc/include/asm/elf_64.h
9159+++ b/arch/sparc/include/asm/elf_64.h
9160@@ -189,6 +189,13 @@ typedef struct {
9161 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9162 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9163
9164+#ifdef CONFIG_PAX_ASLR
9165+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9166+
9167+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9168+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9169+#endif
9170+
9171 extern unsigned long sparc64_elf_hwcap;
9172 #define ELF_HWCAP sparc64_elf_hwcap
9173
9174diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9175index 9b1c36d..209298b 100644
9176--- a/arch/sparc/include/asm/pgalloc_32.h
9177+++ b/arch/sparc/include/asm/pgalloc_32.h
9178@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9179 }
9180
9181 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9182+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9183
9184 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9185 unsigned long address)
9186diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9187index bcfe063..b333142 100644
9188--- a/arch/sparc/include/asm/pgalloc_64.h
9189+++ b/arch/sparc/include/asm/pgalloc_64.h
9190@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9191 }
9192
9193 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9194+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9195
9196 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9197 {
9198diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9199index 502f632..da1917f 100644
9200--- a/arch/sparc/include/asm/pgtable_32.h
9201+++ b/arch/sparc/include/asm/pgtable_32.h
9202@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9203 #define PAGE_SHARED SRMMU_PAGE_SHARED
9204 #define PAGE_COPY SRMMU_PAGE_COPY
9205 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9206+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9207+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9208+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9209 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9210
9211 /* Top-level page directory - dummy used by init-mm.
9212@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9213
9214 /* xwr */
9215 #define __P000 PAGE_NONE
9216-#define __P001 PAGE_READONLY
9217-#define __P010 PAGE_COPY
9218-#define __P011 PAGE_COPY
9219+#define __P001 PAGE_READONLY_NOEXEC
9220+#define __P010 PAGE_COPY_NOEXEC
9221+#define __P011 PAGE_COPY_NOEXEC
9222 #define __P100 PAGE_READONLY
9223 #define __P101 PAGE_READONLY
9224 #define __P110 PAGE_COPY
9225 #define __P111 PAGE_COPY
9226
9227 #define __S000 PAGE_NONE
9228-#define __S001 PAGE_READONLY
9229-#define __S010 PAGE_SHARED
9230-#define __S011 PAGE_SHARED
9231+#define __S001 PAGE_READONLY_NOEXEC
9232+#define __S010 PAGE_SHARED_NOEXEC
9233+#define __S011 PAGE_SHARED_NOEXEC
9234 #define __S100 PAGE_READONLY
9235 #define __S101 PAGE_READONLY
9236 #define __S110 PAGE_SHARED
9237diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9238index 79da178..c2eede8 100644
9239--- a/arch/sparc/include/asm/pgtsrmmu.h
9240+++ b/arch/sparc/include/asm/pgtsrmmu.h
9241@@ -115,6 +115,11 @@
9242 SRMMU_EXEC | SRMMU_REF)
9243 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9244 SRMMU_EXEC | SRMMU_REF)
9245+
9246+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9247+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9248+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9249+
9250 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9251 SRMMU_DIRTY | SRMMU_REF)
9252
9253diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9254index 9689176..63c18ea 100644
9255--- a/arch/sparc/include/asm/spinlock_64.h
9256+++ b/arch/sparc/include/asm/spinlock_64.h
9257@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9258
9259 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9260
9261-static void inline arch_read_lock(arch_rwlock_t *lock)
9262+static inline void arch_read_lock(arch_rwlock_t *lock)
9263 {
9264 unsigned long tmp1, tmp2;
9265
9266 __asm__ __volatile__ (
9267 "1: ldsw [%2], %0\n"
9268 " brlz,pn %0, 2f\n"
9269-"4: add %0, 1, %1\n"
9270+"4: addcc %0, 1, %1\n"
9271+
9272+#ifdef CONFIG_PAX_REFCOUNT
9273+" tvs %%icc, 6\n"
9274+#endif
9275+
9276 " cas [%2], %0, %1\n"
9277 " cmp %0, %1\n"
9278 " bne,pn %%icc, 1b\n"
9279@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9280 " .previous"
9281 : "=&r" (tmp1), "=&r" (tmp2)
9282 : "r" (lock)
9283- : "memory");
9284+ : "memory", "cc");
9285 }
9286
9287-static int inline arch_read_trylock(arch_rwlock_t *lock)
9288+static inline int arch_read_trylock(arch_rwlock_t *lock)
9289 {
9290 int tmp1, tmp2;
9291
9292@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9293 "1: ldsw [%2], %0\n"
9294 " brlz,a,pn %0, 2f\n"
9295 " mov 0, %0\n"
9296-" add %0, 1, %1\n"
9297+" addcc %0, 1, %1\n"
9298+
9299+#ifdef CONFIG_PAX_REFCOUNT
9300+" tvs %%icc, 6\n"
9301+#endif
9302+
9303 " cas [%2], %0, %1\n"
9304 " cmp %0, %1\n"
9305 " bne,pn %%icc, 1b\n"
9306@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9307 return tmp1;
9308 }
9309
9310-static void inline arch_read_unlock(arch_rwlock_t *lock)
9311+static inline void arch_read_unlock(arch_rwlock_t *lock)
9312 {
9313 unsigned long tmp1, tmp2;
9314
9315 __asm__ __volatile__(
9316 "1: lduw [%2], %0\n"
9317-" sub %0, 1, %1\n"
9318+" subcc %0, 1, %1\n"
9319+
9320+#ifdef CONFIG_PAX_REFCOUNT
9321+" tvs %%icc, 6\n"
9322+#endif
9323+
9324 " cas [%2], %0, %1\n"
9325 " cmp %0, %1\n"
9326 " bne,pn %%xcc, 1b\n"
9327@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9328 : "memory");
9329 }
9330
9331-static void inline arch_write_lock(arch_rwlock_t *lock)
9332+static inline void arch_write_lock(arch_rwlock_t *lock)
9333 {
9334 unsigned long mask, tmp1, tmp2;
9335
9336@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9337 : "memory");
9338 }
9339
9340-static void inline arch_write_unlock(arch_rwlock_t *lock)
9341+static inline void arch_write_unlock(arch_rwlock_t *lock)
9342 {
9343 __asm__ __volatile__(
9344 " stw %%g0, [%0]"
9345@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9346 : "memory");
9347 }
9348
9349-static int inline arch_write_trylock(arch_rwlock_t *lock)
9350+static inline int arch_write_trylock(arch_rwlock_t *lock)
9351 {
9352 unsigned long mask, tmp1, tmp2, result;
9353
9354diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9355index 96efa7a..16858bf 100644
9356--- a/arch/sparc/include/asm/thread_info_32.h
9357+++ b/arch/sparc/include/asm/thread_info_32.h
9358@@ -49,6 +49,8 @@ struct thread_info {
9359 unsigned long w_saved;
9360
9361 struct restart_block restart_block;
9362+
9363+ unsigned long lowest_stack;
9364 };
9365
9366 /*
9367diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9368index a5f01ac..703b554 100644
9369--- a/arch/sparc/include/asm/thread_info_64.h
9370+++ b/arch/sparc/include/asm/thread_info_64.h
9371@@ -63,6 +63,8 @@ struct thread_info {
9372 struct pt_regs *kern_una_regs;
9373 unsigned int kern_una_insn;
9374
9375+ unsigned long lowest_stack;
9376+
9377 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9378 };
9379
9380@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9381 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9382 /* flag bit 4 is available */
9383 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9384-/* flag bit 6 is available */
9385+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9386 #define TIF_32BIT 7 /* 32-bit binary */
9387 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9388 #define TIF_SECCOMP 9 /* secure computing */
9389 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9390 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9391+
9392 /* NOTE: Thread flags >= 12 should be ones we have no interest
9393 * in using in assembly, else we can't use the mask as
9394 * an immediate value in instructions such as andcc.
9395@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9396 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9397 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9398 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9399+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9400
9401 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9402 _TIF_DO_NOTIFY_RESUME_MASK | \
9403 _TIF_NEED_RESCHED)
9404 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9405
9406+#define _TIF_WORK_SYSCALL \
9407+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9408+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9409+
9410+
9411 /*
9412 * Thread-synchronous status.
9413 *
9414diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9415index 0167d26..767bb0c 100644
9416--- a/arch/sparc/include/asm/uaccess.h
9417+++ b/arch/sparc/include/asm/uaccess.h
9418@@ -1,5 +1,6 @@
9419 #ifndef ___ASM_SPARC_UACCESS_H
9420 #define ___ASM_SPARC_UACCESS_H
9421+
9422 #if defined(__sparc__) && defined(__arch64__)
9423 #include <asm/uaccess_64.h>
9424 #else
9425diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9426index 53a28dd..50c38c3 100644
9427--- a/arch/sparc/include/asm/uaccess_32.h
9428+++ b/arch/sparc/include/asm/uaccess_32.h
9429@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9430
9431 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9432 {
9433- if (n && __access_ok((unsigned long) to, n))
9434+ if ((long)n < 0)
9435+ return n;
9436+
9437+ if (n && __access_ok((unsigned long) to, n)) {
9438+ if (!__builtin_constant_p(n))
9439+ check_object_size(from, n, true);
9440 return __copy_user(to, (__force void __user *) from, n);
9441- else
9442+ } else
9443 return n;
9444 }
9445
9446 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9447 {
9448+ if ((long)n < 0)
9449+ return n;
9450+
9451+ if (!__builtin_constant_p(n))
9452+ check_object_size(from, n, true);
9453+
9454 return __copy_user(to, (__force void __user *) from, n);
9455 }
9456
9457 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9458 {
9459- if (n && __access_ok((unsigned long) from, n))
9460+ if ((long)n < 0)
9461+ return n;
9462+
9463+ if (n && __access_ok((unsigned long) from, n)) {
9464+ if (!__builtin_constant_p(n))
9465+ check_object_size(to, n, false);
9466 return __copy_user((__force void __user *) to, from, n);
9467- else
9468+ } else
9469 return n;
9470 }
9471
9472 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9473 {
9474+ if ((long)n < 0)
9475+ return n;
9476+
9477 return __copy_user((__force void __user *) to, from, n);
9478 }
9479
9480diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9481index ad7e178..c9e7423 100644
9482--- a/arch/sparc/include/asm/uaccess_64.h
9483+++ b/arch/sparc/include/asm/uaccess_64.h
9484@@ -10,6 +10,7 @@
9485 #include <linux/compiler.h>
9486 #include <linux/string.h>
9487 #include <linux/thread_info.h>
9488+#include <linux/kernel.h>
9489 #include <asm/asi.h>
9490 #include <asm/spitfire.h>
9491 #include <asm-generic/uaccess-unaligned.h>
9492@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9493 static inline unsigned long __must_check
9494 copy_from_user(void *to, const void __user *from, unsigned long size)
9495 {
9496- unsigned long ret = ___copy_from_user(to, from, size);
9497+ unsigned long ret;
9498
9499+ if ((long)size < 0 || size > INT_MAX)
9500+ return size;
9501+
9502+ if (!__builtin_constant_p(size))
9503+ check_object_size(to, size, false);
9504+
9505+ ret = ___copy_from_user(to, from, size);
9506 if (unlikely(ret))
9507 ret = copy_from_user_fixup(to, from, size);
9508
9509@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9510 static inline unsigned long __must_check
9511 copy_to_user(void __user *to, const void *from, unsigned long size)
9512 {
9513- unsigned long ret = ___copy_to_user(to, from, size);
9514+ unsigned long ret;
9515
9516+ if ((long)size < 0 || size > INT_MAX)
9517+ return size;
9518+
9519+ if (!__builtin_constant_p(size))
9520+ check_object_size(from, size, true);
9521+
9522+ ret = ___copy_to_user(to, from, size);
9523 if (unlikely(ret))
9524 ret = copy_to_user_fixup(to, from, size);
9525 return ret;
9526diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9527index d15cc17..d0ae796 100644
9528--- a/arch/sparc/kernel/Makefile
9529+++ b/arch/sparc/kernel/Makefile
9530@@ -4,7 +4,7 @@
9531 #
9532
9533 asflags-y := -ansi
9534-ccflags-y := -Werror
9535+#ccflags-y := -Werror
9536
9537 extra-y := head_$(BITS).o
9538
9539diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9540index fdd819d..5af08c8 100644
9541--- a/arch/sparc/kernel/process_32.c
9542+++ b/arch/sparc/kernel/process_32.c
9543@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9544
9545 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9546 r->psr, r->pc, r->npc, r->y, print_tainted());
9547- printk("PC: <%pS>\n", (void *) r->pc);
9548+ printk("PC: <%pA>\n", (void *) r->pc);
9549 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9550 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9551 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9552 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9553 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9554 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9555- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9556+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9557
9558 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9559 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9560@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9561 rw = (struct reg_window32 *) fp;
9562 pc = rw->ins[7];
9563 printk("[%08lx : ", pc);
9564- printk("%pS ] ", (void *) pc);
9565+ printk("%pA ] ", (void *) pc);
9566 fp = rw->ins[6];
9567 } while (++count < 16);
9568 printk("\n");
9569diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9570index 32a280e..84fc6a9 100644
9571--- a/arch/sparc/kernel/process_64.c
9572+++ b/arch/sparc/kernel/process_64.c
9573@@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
9574 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9575 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9576 if (regs->tstate & TSTATE_PRIV)
9577- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9578+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9579 }
9580
9581 void show_regs(struct pt_regs *regs)
9582@@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
9583
9584 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9585 regs->tpc, regs->tnpc, regs->y, print_tainted());
9586- printk("TPC: <%pS>\n", (void *) regs->tpc);
9587+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9588 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9589 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9590 regs->u_regs[3]);
9591@@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
9592 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9593 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9594 regs->u_regs[15]);
9595- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9596+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9597 show_regwindow(regs);
9598 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9599 }
9600@@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
9601 ((tp && tp->task) ? tp->task->pid : -1));
9602
9603 if (gp->tstate & TSTATE_PRIV) {
9604- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9605+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9606 (void *) gp->tpc,
9607 (void *) gp->o7,
9608 (void *) gp->i7,
9609diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9610index 79cc0d1..ec62734 100644
9611--- a/arch/sparc/kernel/prom_common.c
9612+++ b/arch/sparc/kernel/prom_common.c
9613@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9614
9615 unsigned int prom_early_allocated __initdata;
9616
9617-static struct of_pdt_ops prom_sparc_ops __initdata = {
9618+static struct of_pdt_ops prom_sparc_ops __initconst = {
9619 .nextprop = prom_common_nextprop,
9620 .getproplen = prom_getproplen,
9621 .getproperty = prom_getproperty,
9622diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9623index c13c9f2..d572c34 100644
9624--- a/arch/sparc/kernel/ptrace_64.c
9625+++ b/arch/sparc/kernel/ptrace_64.c
9626@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
9627 return ret;
9628 }
9629
9630+#ifdef CONFIG_GRKERNSEC_SETXID
9631+extern void gr_delayed_cred_worker(void);
9632+#endif
9633+
9634 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9635 {
9636 int ret = 0;
9637@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9638 if (test_thread_flag(TIF_NOHZ))
9639 user_exit();
9640
9641+#ifdef CONFIG_GRKERNSEC_SETXID
9642+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9643+ gr_delayed_cred_worker();
9644+#endif
9645+
9646 if (test_thread_flag(TIF_SYSCALL_TRACE))
9647 ret = tracehook_report_syscall_entry(regs);
9648
9649@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9650 if (test_thread_flag(TIF_NOHZ))
9651 user_exit();
9652
9653+#ifdef CONFIG_GRKERNSEC_SETXID
9654+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9655+ gr_delayed_cred_worker();
9656+#endif
9657+
9658 audit_syscall_exit(regs);
9659
9660 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9661diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9662index b085311..6f885f7 100644
9663--- a/arch/sparc/kernel/smp_64.c
9664+++ b/arch/sparc/kernel/smp_64.c
9665@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9666 extern unsigned long xcall_flush_dcache_page_spitfire;
9667
9668 #ifdef CONFIG_DEBUG_DCFLUSH
9669-extern atomic_t dcpage_flushes;
9670-extern atomic_t dcpage_flushes_xcall;
9671+extern atomic_unchecked_t dcpage_flushes;
9672+extern atomic_unchecked_t dcpage_flushes_xcall;
9673 #endif
9674
9675 static inline void __local_flush_dcache_page(struct page *page)
9676@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9677 return;
9678
9679 #ifdef CONFIG_DEBUG_DCFLUSH
9680- atomic_inc(&dcpage_flushes);
9681+ atomic_inc_unchecked(&dcpage_flushes);
9682 #endif
9683
9684 this_cpu = get_cpu();
9685@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9686 xcall_deliver(data0, __pa(pg_addr),
9687 (u64) pg_addr, cpumask_of(cpu));
9688 #ifdef CONFIG_DEBUG_DCFLUSH
9689- atomic_inc(&dcpage_flushes_xcall);
9690+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9691 #endif
9692 }
9693 }
9694@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9695 preempt_disable();
9696
9697 #ifdef CONFIG_DEBUG_DCFLUSH
9698- atomic_inc(&dcpage_flushes);
9699+ atomic_inc_unchecked(&dcpage_flushes);
9700 #endif
9701 data0 = 0;
9702 pg_addr = page_address(page);
9703@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9704 xcall_deliver(data0, __pa(pg_addr),
9705 (u64) pg_addr, cpu_online_mask);
9706 #ifdef CONFIG_DEBUG_DCFLUSH
9707- atomic_inc(&dcpage_flushes_xcall);
9708+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9709 #endif
9710 }
9711 __local_flush_dcache_page(page);
9712diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9713index 3a8d184..49498a8 100644
9714--- a/arch/sparc/kernel/sys_sparc_32.c
9715+++ b/arch/sparc/kernel/sys_sparc_32.c
9716@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9717 if (len > TASK_SIZE - PAGE_SIZE)
9718 return -ENOMEM;
9719 if (!addr)
9720- addr = TASK_UNMAPPED_BASE;
9721+ addr = current->mm->mmap_base;
9722
9723 info.flags = 0;
9724 info.length = len;
9725diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9726index beb0b5a..5a153f7 100644
9727--- a/arch/sparc/kernel/sys_sparc_64.c
9728+++ b/arch/sparc/kernel/sys_sparc_64.c
9729@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9730 struct vm_area_struct * vma;
9731 unsigned long task_size = TASK_SIZE;
9732 int do_color_align;
9733+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9734 struct vm_unmapped_area_info info;
9735
9736 if (flags & MAP_FIXED) {
9737 /* We do not accept a shared mapping if it would violate
9738 * cache aliasing constraints.
9739 */
9740- if ((flags & MAP_SHARED) &&
9741+ if ((filp || (flags & MAP_SHARED)) &&
9742 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9743 return -EINVAL;
9744 return addr;
9745@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9746 if (filp || (flags & MAP_SHARED))
9747 do_color_align = 1;
9748
9749+#ifdef CONFIG_PAX_RANDMMAP
9750+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9751+#endif
9752+
9753 if (addr) {
9754 if (do_color_align)
9755 addr = COLOR_ALIGN(addr, pgoff);
9756@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9757 addr = PAGE_ALIGN(addr);
9758
9759 vma = find_vma(mm, addr);
9760- if (task_size - len >= addr &&
9761- (!vma || addr + len <= vma->vm_start))
9762+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9763 return addr;
9764 }
9765
9766 info.flags = 0;
9767 info.length = len;
9768- info.low_limit = TASK_UNMAPPED_BASE;
9769+ info.low_limit = mm->mmap_base;
9770 info.high_limit = min(task_size, VA_EXCLUDE_START);
9771 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9772 info.align_offset = pgoff << PAGE_SHIFT;
9773+ info.threadstack_offset = offset;
9774 addr = vm_unmapped_area(&info);
9775
9776 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9777 VM_BUG_ON(addr != -ENOMEM);
9778 info.low_limit = VA_EXCLUDE_END;
9779+
9780+#ifdef CONFIG_PAX_RANDMMAP
9781+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9782+ info.low_limit += mm->delta_mmap;
9783+#endif
9784+
9785 info.high_limit = task_size;
9786 addr = vm_unmapped_area(&info);
9787 }
9788@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9789 unsigned long task_size = STACK_TOP32;
9790 unsigned long addr = addr0;
9791 int do_color_align;
9792+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9793 struct vm_unmapped_area_info info;
9794
9795 /* This should only ever run for 32-bit processes. */
9796@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9797 /* We do not accept a shared mapping if it would violate
9798 * cache aliasing constraints.
9799 */
9800- if ((flags & MAP_SHARED) &&
9801+ if ((filp || (flags & MAP_SHARED)) &&
9802 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9803 return -EINVAL;
9804 return addr;
9805@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9806 if (filp || (flags & MAP_SHARED))
9807 do_color_align = 1;
9808
9809+#ifdef CONFIG_PAX_RANDMMAP
9810+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9811+#endif
9812+
9813 /* requesting a specific address */
9814 if (addr) {
9815 if (do_color_align)
9816@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9817 addr = PAGE_ALIGN(addr);
9818
9819 vma = find_vma(mm, addr);
9820- if (task_size - len >= addr &&
9821- (!vma || addr + len <= vma->vm_start))
9822+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9823 return addr;
9824 }
9825
9826@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9827 info.high_limit = mm->mmap_base;
9828 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9829 info.align_offset = pgoff << PAGE_SHIFT;
9830+ info.threadstack_offset = offset;
9831 addr = vm_unmapped_area(&info);
9832
9833 /*
9834@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9835 VM_BUG_ON(addr != -ENOMEM);
9836 info.flags = 0;
9837 info.low_limit = TASK_UNMAPPED_BASE;
9838+
9839+#ifdef CONFIG_PAX_RANDMMAP
9840+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9841+ info.low_limit += mm->delta_mmap;
9842+#endif
9843+
9844 info.high_limit = STACK_TOP32;
9845 addr = vm_unmapped_area(&info);
9846 }
9847@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9848 EXPORT_SYMBOL(get_fb_unmapped_area);
9849
9850 /* Essentially the same as PowerPC. */
9851-static unsigned long mmap_rnd(void)
9852+static unsigned long mmap_rnd(struct mm_struct *mm)
9853 {
9854 unsigned long rnd = 0UL;
9855
9856+#ifdef CONFIG_PAX_RANDMMAP
9857+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9858+#endif
9859+
9860 if (current->flags & PF_RANDOMIZE) {
9861 unsigned long val = get_random_int();
9862 if (test_thread_flag(TIF_32BIT))
9863@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
9864
9865 void arch_pick_mmap_layout(struct mm_struct *mm)
9866 {
9867- unsigned long random_factor = mmap_rnd();
9868+ unsigned long random_factor = mmap_rnd(mm);
9869 unsigned long gap;
9870
9871 /*
9872@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9873 gap == RLIM_INFINITY ||
9874 sysctl_legacy_va_layout) {
9875 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9876+
9877+#ifdef CONFIG_PAX_RANDMMAP
9878+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9879+ mm->mmap_base += mm->delta_mmap;
9880+#endif
9881+
9882 mm->get_unmapped_area = arch_get_unmapped_area;
9883 } else {
9884 /* We know it's 32-bit */
9885@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9886 gap = (task_size / 6 * 5);
9887
9888 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9889+
9890+#ifdef CONFIG_PAX_RANDMMAP
9891+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9892+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9893+#endif
9894+
9895 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9896 }
9897 }
9898diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9899index 87729ff..192f9d8 100644
9900--- a/arch/sparc/kernel/syscalls.S
9901+++ b/arch/sparc/kernel/syscalls.S
9902@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9903 #endif
9904 .align 32
9905 1: ldx [%g6 + TI_FLAGS], %l5
9906- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9907+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9908 be,pt %icc, rtrap
9909 nop
9910 call syscall_trace_leave
9911@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9912
9913 srl %i3, 0, %o3 ! IEU0
9914 srl %i2, 0, %o2 ! IEU0 Group
9915- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9916+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9917 bne,pn %icc, linux_syscall_trace32 ! CTI
9918 mov %i0, %l5 ! IEU1
9919 5: call %l7 ! CTI Group brk forced
9920@@ -207,7 +207,7 @@ linux_sparc_syscall:
9921
9922 mov %i3, %o3 ! IEU1
9923 mov %i4, %o4 ! IEU0 Group
9924- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9925+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9926 bne,pn %icc, linux_syscall_trace ! CTI Group
9927 mov %i0, %l5 ! IEU0
9928 2: call %l7 ! CTI Group brk forced
9929@@ -223,7 +223,7 @@ ret_sys_call:
9930
9931 cmp %o0, -ERESTART_RESTARTBLOCK
9932 bgeu,pn %xcc, 1f
9933- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9934+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9935 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9936
9937 2:
9938diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9939index 6629829..036032d 100644
9940--- a/arch/sparc/kernel/traps_32.c
9941+++ b/arch/sparc/kernel/traps_32.c
9942@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9943 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9944 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9945
9946+extern void gr_handle_kernel_exploit(void);
9947+
9948 void die_if_kernel(char *str, struct pt_regs *regs)
9949 {
9950 static int die_counter;
9951@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9952 count++ < 30 &&
9953 (((unsigned long) rw) >= PAGE_OFFSET) &&
9954 !(((unsigned long) rw) & 0x7)) {
9955- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9956+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9957 (void *) rw->ins[7]);
9958 rw = (struct reg_window32 *)rw->ins[6];
9959 }
9960 }
9961 printk("Instruction DUMP:");
9962 instruction_dump ((unsigned long *) regs->pc);
9963- if(regs->psr & PSR_PS)
9964+ if(regs->psr & PSR_PS) {
9965+ gr_handle_kernel_exploit();
9966 do_exit(SIGKILL);
9967+ }
9968 do_exit(SIGSEGV);
9969 }
9970
9971diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9972index 4ced92f..965eeed 100644
9973--- a/arch/sparc/kernel/traps_64.c
9974+++ b/arch/sparc/kernel/traps_64.c
9975@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9976 i + 1,
9977 p->trapstack[i].tstate, p->trapstack[i].tpc,
9978 p->trapstack[i].tnpc, p->trapstack[i].tt);
9979- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9980+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9981 }
9982 }
9983
9984@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9985
9986 lvl -= 0x100;
9987 if (regs->tstate & TSTATE_PRIV) {
9988+
9989+#ifdef CONFIG_PAX_REFCOUNT
9990+ if (lvl == 6)
9991+ pax_report_refcount_overflow(regs);
9992+#endif
9993+
9994 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9995 die_if_kernel(buffer, regs);
9996 }
9997@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9998 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9999 {
10000 char buffer[32];
10001-
10002+
10003 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10004 0, lvl, SIGTRAP) == NOTIFY_STOP)
10005 return;
10006
10007+#ifdef CONFIG_PAX_REFCOUNT
10008+ if (lvl == 6)
10009+ pax_report_refcount_overflow(regs);
10010+#endif
10011+
10012 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10013
10014 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10015@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10016 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10017 printk("%s" "ERROR(%d): ",
10018 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10019- printk("TPC<%pS>\n", (void *) regs->tpc);
10020+ printk("TPC<%pA>\n", (void *) regs->tpc);
10021 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10022 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10023 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10024@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10025 smp_processor_id(),
10026 (type & 0x1) ? 'I' : 'D',
10027 regs->tpc);
10028- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10029+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10030 panic("Irrecoverable Cheetah+ parity error.");
10031 }
10032
10033@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10034 smp_processor_id(),
10035 (type & 0x1) ? 'I' : 'D',
10036 regs->tpc);
10037- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10038+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10039 }
10040
10041 struct sun4v_error_entry {
10042@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10043 /*0x38*/u64 reserved_5;
10044 };
10045
10046-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10047-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10048+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10049+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10050
10051 static const char *sun4v_err_type_to_str(u8 type)
10052 {
10053@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10054 }
10055
10056 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10057- int cpu, const char *pfx, atomic_t *ocnt)
10058+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10059 {
10060 u64 *raw_ptr = (u64 *) ent;
10061 u32 attrs;
10062@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10063
10064 show_regs(regs);
10065
10066- if ((cnt = atomic_read(ocnt)) != 0) {
10067- atomic_set(ocnt, 0);
10068+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10069+ atomic_set_unchecked(ocnt, 0);
10070 wmb();
10071 printk("%s: Queue overflowed %d times.\n",
10072 pfx, cnt);
10073@@ -2046,7 +2057,7 @@ out:
10074 */
10075 void sun4v_resum_overflow(struct pt_regs *regs)
10076 {
10077- atomic_inc(&sun4v_resum_oflow_cnt);
10078+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10079 }
10080
10081 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10082@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10083 /* XXX Actually even this can make not that much sense. Perhaps
10084 * XXX we should just pull the plug and panic directly from here?
10085 */
10086- atomic_inc(&sun4v_nonresum_oflow_cnt);
10087+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10088 }
10089
10090 unsigned long sun4v_err_itlb_vaddr;
10091@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10092
10093 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10094 regs->tpc, tl);
10095- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10096+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10097 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10098- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10099+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10100 (void *) regs->u_regs[UREG_I7]);
10101 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10102 "pte[%lx] error[%lx]\n",
10103@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10104
10105 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10106 regs->tpc, tl);
10107- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10108+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10109 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10110- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10111+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10112 (void *) regs->u_regs[UREG_I7]);
10113 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10114 "pte[%lx] error[%lx]\n",
10115@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10116 fp = (unsigned long)sf->fp + STACK_BIAS;
10117 }
10118
10119- printk(" [%016lx] %pS\n", pc, (void *) pc);
10120+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10121 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10122 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10123 int index = tsk->curr_ret_stack;
10124 if (tsk->ret_stack && index >= graph) {
10125 pc = tsk->ret_stack[index - graph].ret;
10126- printk(" [%016lx] %pS\n", pc, (void *) pc);
10127+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10128 graph++;
10129 }
10130 }
10131@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10132 return (struct reg_window *) (fp + STACK_BIAS);
10133 }
10134
10135+extern void gr_handle_kernel_exploit(void);
10136+
10137 void die_if_kernel(char *str, struct pt_regs *regs)
10138 {
10139 static int die_counter;
10140@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10141 while (rw &&
10142 count++ < 30 &&
10143 kstack_valid(tp, (unsigned long) rw)) {
10144- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10145+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10146 (void *) rw->ins[7]);
10147
10148 rw = kernel_stack_up(rw);
10149@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10150 }
10151 user_instruction_dump ((unsigned int __user *) regs->tpc);
10152 }
10153- if (regs->tstate & TSTATE_PRIV)
10154+ if (regs->tstate & TSTATE_PRIV) {
10155+ gr_handle_kernel_exploit();
10156 do_exit(SIGKILL);
10157+ }
10158 do_exit(SIGSEGV);
10159 }
10160 EXPORT_SYMBOL(die_if_kernel);
10161diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10162index 3c1a7cb..73e1923 100644
10163--- a/arch/sparc/kernel/unaligned_64.c
10164+++ b/arch/sparc/kernel/unaligned_64.c
10165@@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10166 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10167
10168 if (__ratelimit(&ratelimit)) {
10169- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10170+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10171 regs->tpc, (void *) regs->tpc);
10172 }
10173 }
10174diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10175index dbe119b..089c7c1 100644
10176--- a/arch/sparc/lib/Makefile
10177+++ b/arch/sparc/lib/Makefile
10178@@ -2,7 +2,7 @@
10179 #
10180
10181 asflags-y := -ansi -DST_DIV0=0x02
10182-ccflags-y := -Werror
10183+#ccflags-y := -Werror
10184
10185 lib-$(CONFIG_SPARC32) += ashrdi3.o
10186 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10187diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10188index 85c233d..68500e0 100644
10189--- a/arch/sparc/lib/atomic_64.S
10190+++ b/arch/sparc/lib/atomic_64.S
10191@@ -17,7 +17,12 @@
10192 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10193 BACKOFF_SETUP(%o2)
10194 1: lduw [%o1], %g1
10195- add %g1, %o0, %g7
10196+ addcc %g1, %o0, %g7
10197+
10198+#ifdef CONFIG_PAX_REFCOUNT
10199+ tvs %icc, 6
10200+#endif
10201+
10202 cas [%o1], %g1, %g7
10203 cmp %g1, %g7
10204 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10205@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10206 2: BACKOFF_SPIN(%o2, %o3, 1b)
10207 ENDPROC(atomic_add)
10208
10209+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10210+ BACKOFF_SETUP(%o2)
10211+1: lduw [%o1], %g1
10212+ add %g1, %o0, %g7
10213+ cas [%o1], %g1, %g7
10214+ cmp %g1, %g7
10215+ bne,pn %icc, 2f
10216+ nop
10217+ retl
10218+ nop
10219+2: BACKOFF_SPIN(%o2, %o3, 1b)
10220+ENDPROC(atomic_add_unchecked)
10221+
10222 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10223 BACKOFF_SETUP(%o2)
10224 1: lduw [%o1], %g1
10225- sub %g1, %o0, %g7
10226+ subcc %g1, %o0, %g7
10227+
10228+#ifdef CONFIG_PAX_REFCOUNT
10229+ tvs %icc, 6
10230+#endif
10231+
10232 cas [%o1], %g1, %g7
10233 cmp %g1, %g7
10234 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10235@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10236 2: BACKOFF_SPIN(%o2, %o3, 1b)
10237 ENDPROC(atomic_sub)
10238
10239+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10240+ BACKOFF_SETUP(%o2)
10241+1: lduw [%o1], %g1
10242+ sub %g1, %o0, %g7
10243+ cas [%o1], %g1, %g7
10244+ cmp %g1, %g7
10245+ bne,pn %icc, 2f
10246+ nop
10247+ retl
10248+ nop
10249+2: BACKOFF_SPIN(%o2, %o3, 1b)
10250+ENDPROC(atomic_sub_unchecked)
10251+
10252 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10253 BACKOFF_SETUP(%o2)
10254 1: lduw [%o1], %g1
10255- add %g1, %o0, %g7
10256+ addcc %g1, %o0, %g7
10257+
10258+#ifdef CONFIG_PAX_REFCOUNT
10259+ tvs %icc, 6
10260+#endif
10261+
10262 cas [%o1], %g1, %g7
10263 cmp %g1, %g7
10264 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10265@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10266 2: BACKOFF_SPIN(%o2, %o3, 1b)
10267 ENDPROC(atomic_add_ret)
10268
10269+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10270+ BACKOFF_SETUP(%o2)
10271+1: lduw [%o1], %g1
10272+ addcc %g1, %o0, %g7
10273+ cas [%o1], %g1, %g7
10274+ cmp %g1, %g7
10275+ bne,pn %icc, 2f
10276+ add %g7, %o0, %g7
10277+ sra %g7, 0, %o0
10278+ retl
10279+ nop
10280+2: BACKOFF_SPIN(%o2, %o3, 1b)
10281+ENDPROC(atomic_add_ret_unchecked)
10282+
10283 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10284 BACKOFF_SETUP(%o2)
10285 1: lduw [%o1], %g1
10286- sub %g1, %o0, %g7
10287+ subcc %g1, %o0, %g7
10288+
10289+#ifdef CONFIG_PAX_REFCOUNT
10290+ tvs %icc, 6
10291+#endif
10292+
10293 cas [%o1], %g1, %g7
10294 cmp %g1, %g7
10295 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10296@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10297 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10298 BACKOFF_SETUP(%o2)
10299 1: ldx [%o1], %g1
10300- add %g1, %o0, %g7
10301+ addcc %g1, %o0, %g7
10302+
10303+#ifdef CONFIG_PAX_REFCOUNT
10304+ tvs %xcc, 6
10305+#endif
10306+
10307 casx [%o1], %g1, %g7
10308 cmp %g1, %g7
10309 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10310@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10311 2: BACKOFF_SPIN(%o2, %o3, 1b)
10312 ENDPROC(atomic64_add)
10313
10314+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10315+ BACKOFF_SETUP(%o2)
10316+1: ldx [%o1], %g1
10317+ addcc %g1, %o0, %g7
10318+ casx [%o1], %g1, %g7
10319+ cmp %g1, %g7
10320+ bne,pn %xcc, 2f
10321+ nop
10322+ retl
10323+ nop
10324+2: BACKOFF_SPIN(%o2, %o3, 1b)
10325+ENDPROC(atomic64_add_unchecked)
10326+
10327 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10328 BACKOFF_SETUP(%o2)
10329 1: ldx [%o1], %g1
10330- sub %g1, %o0, %g7
10331+ subcc %g1, %o0, %g7
10332+
10333+#ifdef CONFIG_PAX_REFCOUNT
10334+ tvs %xcc, 6
10335+#endif
10336+
10337 casx [%o1], %g1, %g7
10338 cmp %g1, %g7
10339 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10340@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10341 2: BACKOFF_SPIN(%o2, %o3, 1b)
10342 ENDPROC(atomic64_sub)
10343
10344+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10345+ BACKOFF_SETUP(%o2)
10346+1: ldx [%o1], %g1
10347+ subcc %g1, %o0, %g7
10348+ casx [%o1], %g1, %g7
10349+ cmp %g1, %g7
10350+ bne,pn %xcc, 2f
10351+ nop
10352+ retl
10353+ nop
10354+2: BACKOFF_SPIN(%o2, %o3, 1b)
10355+ENDPROC(atomic64_sub_unchecked)
10356+
10357 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10358 BACKOFF_SETUP(%o2)
10359 1: ldx [%o1], %g1
10360- add %g1, %o0, %g7
10361+ addcc %g1, %o0, %g7
10362+
10363+#ifdef CONFIG_PAX_REFCOUNT
10364+ tvs %xcc, 6
10365+#endif
10366+
10367 casx [%o1], %g1, %g7
10368 cmp %g1, %g7
10369 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10370@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10371 2: BACKOFF_SPIN(%o2, %o3, 1b)
10372 ENDPROC(atomic64_add_ret)
10373
10374+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10375+ BACKOFF_SETUP(%o2)
10376+1: ldx [%o1], %g1
10377+ addcc %g1, %o0, %g7
10378+ casx [%o1], %g1, %g7
10379+ cmp %g1, %g7
10380+ bne,pn %xcc, 2f
10381+ add %g7, %o0, %g7
10382+ mov %g7, %o0
10383+ retl
10384+ nop
10385+2: BACKOFF_SPIN(%o2, %o3, 1b)
10386+ENDPROC(atomic64_add_ret_unchecked)
10387+
10388 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10389 BACKOFF_SETUP(%o2)
10390 1: ldx [%o1], %g1
10391- sub %g1, %o0, %g7
10392+ subcc %g1, %o0, %g7
10393+
10394+#ifdef CONFIG_PAX_REFCOUNT
10395+ tvs %xcc, 6
10396+#endif
10397+
10398 casx [%o1], %g1, %g7
10399 cmp %g1, %g7
10400 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10401diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10402index 323335b..ed85ea2 100644
10403--- a/arch/sparc/lib/ksyms.c
10404+++ b/arch/sparc/lib/ksyms.c
10405@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10406
10407 /* Atomic counter implementation. */
10408 EXPORT_SYMBOL(atomic_add);
10409+EXPORT_SYMBOL(atomic_add_unchecked);
10410 EXPORT_SYMBOL(atomic_add_ret);
10411+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10412 EXPORT_SYMBOL(atomic_sub);
10413+EXPORT_SYMBOL(atomic_sub_unchecked);
10414 EXPORT_SYMBOL(atomic_sub_ret);
10415 EXPORT_SYMBOL(atomic64_add);
10416+EXPORT_SYMBOL(atomic64_add_unchecked);
10417 EXPORT_SYMBOL(atomic64_add_ret);
10418+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10419 EXPORT_SYMBOL(atomic64_sub);
10420+EXPORT_SYMBOL(atomic64_sub_unchecked);
10421 EXPORT_SYMBOL(atomic64_sub_ret);
10422 EXPORT_SYMBOL(atomic64_dec_if_positive);
10423
10424diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10425index 30c3ecc..736f015 100644
10426--- a/arch/sparc/mm/Makefile
10427+++ b/arch/sparc/mm/Makefile
10428@@ -2,7 +2,7 @@
10429 #
10430
10431 asflags-y := -ansi
10432-ccflags-y := -Werror
10433+#ccflags-y := -Werror
10434
10435 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10436 obj-y += fault_$(BITS).o
10437diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10438index 59dbd46..1dd7f5e 100644
10439--- a/arch/sparc/mm/fault_32.c
10440+++ b/arch/sparc/mm/fault_32.c
10441@@ -21,6 +21,9 @@
10442 #include <linux/perf_event.h>
10443 #include <linux/interrupt.h>
10444 #include <linux/kdebug.h>
10445+#include <linux/slab.h>
10446+#include <linux/pagemap.h>
10447+#include <linux/compiler.h>
10448
10449 #include <asm/page.h>
10450 #include <asm/pgtable.h>
10451@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10452 return safe_compute_effective_address(regs, insn);
10453 }
10454
10455+#ifdef CONFIG_PAX_PAGEEXEC
10456+#ifdef CONFIG_PAX_DLRESOLVE
10457+static void pax_emuplt_close(struct vm_area_struct *vma)
10458+{
10459+ vma->vm_mm->call_dl_resolve = 0UL;
10460+}
10461+
10462+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10463+{
10464+ unsigned int *kaddr;
10465+
10466+ vmf->page = alloc_page(GFP_HIGHUSER);
10467+ if (!vmf->page)
10468+ return VM_FAULT_OOM;
10469+
10470+ kaddr = kmap(vmf->page);
10471+ memset(kaddr, 0, PAGE_SIZE);
10472+ kaddr[0] = 0x9DE3BFA8U; /* save */
10473+ flush_dcache_page(vmf->page);
10474+ kunmap(vmf->page);
10475+ return VM_FAULT_MAJOR;
10476+}
10477+
10478+static const struct vm_operations_struct pax_vm_ops = {
10479+ .close = pax_emuplt_close,
10480+ .fault = pax_emuplt_fault
10481+};
10482+
10483+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10484+{
10485+ int ret;
10486+
10487+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10488+ vma->vm_mm = current->mm;
10489+ vma->vm_start = addr;
10490+ vma->vm_end = addr + PAGE_SIZE;
10491+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10492+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10493+ vma->vm_ops = &pax_vm_ops;
10494+
10495+ ret = insert_vm_struct(current->mm, vma);
10496+ if (ret)
10497+ return ret;
10498+
10499+ ++current->mm->total_vm;
10500+ return 0;
10501+}
10502+#endif
10503+
10504+/*
10505+ * PaX: decide what to do with offenders (regs->pc = fault address)
10506+ *
10507+ * returns 1 when task should be killed
10508+ * 2 when patched PLT trampoline was detected
10509+ * 3 when unpatched PLT trampoline was detected
10510+ */
10511+static int pax_handle_fetch_fault(struct pt_regs *regs)
10512+{
10513+
10514+#ifdef CONFIG_PAX_EMUPLT
10515+ int err;
10516+
10517+ do { /* PaX: patched PLT emulation #1 */
10518+ unsigned int sethi1, sethi2, jmpl;
10519+
10520+ err = get_user(sethi1, (unsigned int *)regs->pc);
10521+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10522+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10523+
10524+ if (err)
10525+ break;
10526+
10527+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10528+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10529+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10530+ {
10531+ unsigned int addr;
10532+
10533+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10534+ addr = regs->u_regs[UREG_G1];
10535+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10536+ regs->pc = addr;
10537+ regs->npc = addr+4;
10538+ return 2;
10539+ }
10540+ } while (0);
10541+
10542+ do { /* PaX: patched PLT emulation #2 */
10543+ unsigned int ba;
10544+
10545+ err = get_user(ba, (unsigned int *)regs->pc);
10546+
10547+ if (err)
10548+ break;
10549+
10550+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10551+ unsigned int addr;
10552+
10553+ if ((ba & 0xFFC00000U) == 0x30800000U)
10554+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10555+ else
10556+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10557+ regs->pc = addr;
10558+ regs->npc = addr+4;
10559+ return 2;
10560+ }
10561+ } while (0);
10562+
10563+ do { /* PaX: patched PLT emulation #3 */
10564+ unsigned int sethi, bajmpl, nop;
10565+
10566+ err = get_user(sethi, (unsigned int *)regs->pc);
10567+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10568+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10569+
10570+ if (err)
10571+ break;
10572+
10573+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10574+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10575+ nop == 0x01000000U)
10576+ {
10577+ unsigned int addr;
10578+
10579+ addr = (sethi & 0x003FFFFFU) << 10;
10580+ regs->u_regs[UREG_G1] = addr;
10581+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10582+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10583+ else
10584+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10585+ regs->pc = addr;
10586+ regs->npc = addr+4;
10587+ return 2;
10588+ }
10589+ } while (0);
10590+
10591+ do { /* PaX: unpatched PLT emulation step 1 */
10592+ unsigned int sethi, ba, nop;
10593+
10594+ err = get_user(sethi, (unsigned int *)regs->pc);
10595+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10596+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10597+
10598+ if (err)
10599+ break;
10600+
10601+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10602+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10603+ nop == 0x01000000U)
10604+ {
10605+ unsigned int addr, save, call;
10606+
10607+ if ((ba & 0xFFC00000U) == 0x30800000U)
10608+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10609+ else
10610+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10611+
10612+ err = get_user(save, (unsigned int *)addr);
10613+ err |= get_user(call, (unsigned int *)(addr+4));
10614+ err |= get_user(nop, (unsigned int *)(addr+8));
10615+ if (err)
10616+ break;
10617+
10618+#ifdef CONFIG_PAX_DLRESOLVE
10619+ if (save == 0x9DE3BFA8U &&
10620+ (call & 0xC0000000U) == 0x40000000U &&
10621+ nop == 0x01000000U)
10622+ {
10623+ struct vm_area_struct *vma;
10624+ unsigned long call_dl_resolve;
10625+
10626+ down_read(&current->mm->mmap_sem);
10627+ call_dl_resolve = current->mm->call_dl_resolve;
10628+ up_read(&current->mm->mmap_sem);
10629+ if (likely(call_dl_resolve))
10630+ goto emulate;
10631+
10632+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10633+
10634+ down_write(&current->mm->mmap_sem);
10635+ if (current->mm->call_dl_resolve) {
10636+ call_dl_resolve = current->mm->call_dl_resolve;
10637+ up_write(&current->mm->mmap_sem);
10638+ if (vma)
10639+ kmem_cache_free(vm_area_cachep, vma);
10640+ goto emulate;
10641+ }
10642+
10643+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10644+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10645+ up_write(&current->mm->mmap_sem);
10646+ if (vma)
10647+ kmem_cache_free(vm_area_cachep, vma);
10648+ return 1;
10649+ }
10650+
10651+ if (pax_insert_vma(vma, call_dl_resolve)) {
10652+ up_write(&current->mm->mmap_sem);
10653+ kmem_cache_free(vm_area_cachep, vma);
10654+ return 1;
10655+ }
10656+
10657+ current->mm->call_dl_resolve = call_dl_resolve;
10658+ up_write(&current->mm->mmap_sem);
10659+
10660+emulate:
10661+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10662+ regs->pc = call_dl_resolve;
10663+ regs->npc = addr+4;
10664+ return 3;
10665+ }
10666+#endif
10667+
10668+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10669+ if ((save & 0xFFC00000U) == 0x05000000U &&
10670+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10671+ nop == 0x01000000U)
10672+ {
10673+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10674+ regs->u_regs[UREG_G2] = addr + 4;
10675+ addr = (save & 0x003FFFFFU) << 10;
10676+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10677+ regs->pc = addr;
10678+ regs->npc = addr+4;
10679+ return 3;
10680+ }
10681+ }
10682+ } while (0);
10683+
10684+ do { /* PaX: unpatched PLT emulation step 2 */
10685+ unsigned int save, call, nop;
10686+
10687+ err = get_user(save, (unsigned int *)(regs->pc-4));
10688+ err |= get_user(call, (unsigned int *)regs->pc);
10689+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10690+ if (err)
10691+ break;
10692+
10693+ if (save == 0x9DE3BFA8U &&
10694+ (call & 0xC0000000U) == 0x40000000U &&
10695+ nop == 0x01000000U)
10696+ {
10697+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10698+
10699+ regs->u_regs[UREG_RETPC] = regs->pc;
10700+ regs->pc = dl_resolve;
10701+ regs->npc = dl_resolve+4;
10702+ return 3;
10703+ }
10704+ } while (0);
10705+#endif
10706+
10707+ return 1;
10708+}
10709+
10710+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10711+{
10712+ unsigned long i;
10713+
10714+ printk(KERN_ERR "PAX: bytes at PC: ");
10715+ for (i = 0; i < 8; i++) {
10716+ unsigned int c;
10717+ if (get_user(c, (unsigned int *)pc+i))
10718+ printk(KERN_CONT "???????? ");
10719+ else
10720+ printk(KERN_CONT "%08x ", c);
10721+ }
10722+ printk("\n");
10723+}
10724+#endif
10725+
10726 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10727 int text_fault)
10728 {
10729@@ -229,6 +503,24 @@ good_area:
10730 if (!(vma->vm_flags & VM_WRITE))
10731 goto bad_area;
10732 } else {
10733+
10734+#ifdef CONFIG_PAX_PAGEEXEC
10735+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10736+ up_read(&mm->mmap_sem);
10737+ switch (pax_handle_fetch_fault(regs)) {
10738+
10739+#ifdef CONFIG_PAX_EMUPLT
10740+ case 2:
10741+ case 3:
10742+ return;
10743+#endif
10744+
10745+ }
10746+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10747+ do_group_exit(SIGKILL);
10748+ }
10749+#endif
10750+
10751 /* Allow reads even for write-only mappings */
10752 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10753 goto bad_area;
10754diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10755index 69bb818..6ca35c8 100644
10756--- a/arch/sparc/mm/fault_64.c
10757+++ b/arch/sparc/mm/fault_64.c
10758@@ -22,6 +22,9 @@
10759 #include <linux/kdebug.h>
10760 #include <linux/percpu.h>
10761 #include <linux/context_tracking.h>
10762+#include <linux/slab.h>
10763+#include <linux/pagemap.h>
10764+#include <linux/compiler.h>
10765
10766 #include <asm/page.h>
10767 #include <asm/pgtable.h>
10768@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10769 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10770 regs->tpc);
10771 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10772- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10773+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10774 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10775 dump_stack();
10776 unhandled_fault(regs->tpc, current, regs);
10777@@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10778 show_regs(regs);
10779 }
10780
10781+#ifdef CONFIG_PAX_PAGEEXEC
10782+#ifdef CONFIG_PAX_DLRESOLVE
10783+static void pax_emuplt_close(struct vm_area_struct *vma)
10784+{
10785+ vma->vm_mm->call_dl_resolve = 0UL;
10786+}
10787+
10788+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10789+{
10790+ unsigned int *kaddr;
10791+
10792+ vmf->page = alloc_page(GFP_HIGHUSER);
10793+ if (!vmf->page)
10794+ return VM_FAULT_OOM;
10795+
10796+ kaddr = kmap(vmf->page);
10797+ memset(kaddr, 0, PAGE_SIZE);
10798+ kaddr[0] = 0x9DE3BFA8U; /* save */
10799+ flush_dcache_page(vmf->page);
10800+ kunmap(vmf->page);
10801+ return VM_FAULT_MAJOR;
10802+}
10803+
10804+static const struct vm_operations_struct pax_vm_ops = {
10805+ .close = pax_emuplt_close,
10806+ .fault = pax_emuplt_fault
10807+};
10808+
10809+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10810+{
10811+ int ret;
10812+
10813+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10814+ vma->vm_mm = current->mm;
10815+ vma->vm_start = addr;
10816+ vma->vm_end = addr + PAGE_SIZE;
10817+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10818+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10819+ vma->vm_ops = &pax_vm_ops;
10820+
10821+ ret = insert_vm_struct(current->mm, vma);
10822+ if (ret)
10823+ return ret;
10824+
10825+ ++current->mm->total_vm;
10826+ return 0;
10827+}
10828+#endif
10829+
10830+/*
10831+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10832+ *
10833+ * returns 1 when task should be killed
10834+ * 2 when patched PLT trampoline was detected
10835+ * 3 when unpatched PLT trampoline was detected
10836+ */
10837+static int pax_handle_fetch_fault(struct pt_regs *regs)
10838+{
10839+
10840+#ifdef CONFIG_PAX_EMUPLT
10841+ int err;
10842+
10843+ do { /* PaX: patched PLT emulation #1 */
10844+ unsigned int sethi1, sethi2, jmpl;
10845+
10846+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10847+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10848+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10849+
10850+ if (err)
10851+ break;
10852+
10853+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10854+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10855+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10856+ {
10857+ unsigned long addr;
10858+
10859+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10860+ addr = regs->u_regs[UREG_G1];
10861+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10862+
10863+ if (test_thread_flag(TIF_32BIT))
10864+ addr &= 0xFFFFFFFFUL;
10865+
10866+ regs->tpc = addr;
10867+ regs->tnpc = addr+4;
10868+ return 2;
10869+ }
10870+ } while (0);
10871+
10872+ do { /* PaX: patched PLT emulation #2 */
10873+ unsigned int ba;
10874+
10875+ err = get_user(ba, (unsigned int *)regs->tpc);
10876+
10877+ if (err)
10878+ break;
10879+
10880+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10881+ unsigned long addr;
10882+
10883+ if ((ba & 0xFFC00000U) == 0x30800000U)
10884+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10885+ else
10886+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10887+
10888+ if (test_thread_flag(TIF_32BIT))
10889+ addr &= 0xFFFFFFFFUL;
10890+
10891+ regs->tpc = addr;
10892+ regs->tnpc = addr+4;
10893+ return 2;
10894+ }
10895+ } while (0);
10896+
10897+ do { /* PaX: patched PLT emulation #3 */
10898+ unsigned int sethi, bajmpl, nop;
10899+
10900+ err = get_user(sethi, (unsigned int *)regs->tpc);
10901+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10902+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10903+
10904+ if (err)
10905+ break;
10906+
10907+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10908+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10909+ nop == 0x01000000U)
10910+ {
10911+ unsigned long addr;
10912+
10913+ addr = (sethi & 0x003FFFFFU) << 10;
10914+ regs->u_regs[UREG_G1] = addr;
10915+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10916+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10917+ else
10918+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10919+
10920+ if (test_thread_flag(TIF_32BIT))
10921+ addr &= 0xFFFFFFFFUL;
10922+
10923+ regs->tpc = addr;
10924+ regs->tnpc = addr+4;
10925+ return 2;
10926+ }
10927+ } while (0);
10928+
10929+ do { /* PaX: patched PLT emulation #4 */
10930+ unsigned int sethi, mov1, call, mov2;
10931+
10932+ err = get_user(sethi, (unsigned int *)regs->tpc);
10933+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10934+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10935+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10936+
10937+ if (err)
10938+ break;
10939+
10940+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10941+ mov1 == 0x8210000FU &&
10942+ (call & 0xC0000000U) == 0x40000000U &&
10943+ mov2 == 0x9E100001U)
10944+ {
10945+ unsigned long addr;
10946+
10947+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10948+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10949+
10950+ if (test_thread_flag(TIF_32BIT))
10951+ addr &= 0xFFFFFFFFUL;
10952+
10953+ regs->tpc = addr;
10954+ regs->tnpc = addr+4;
10955+ return 2;
10956+ }
10957+ } while (0);
10958+
10959+ do { /* PaX: patched PLT emulation #5 */
10960+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10961+
10962+ err = get_user(sethi, (unsigned int *)regs->tpc);
10963+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10964+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10965+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10966+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10967+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10968+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10969+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10970+
10971+ if (err)
10972+ break;
10973+
10974+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10975+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10976+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10977+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10978+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10979+ sllx == 0x83287020U &&
10980+ jmpl == 0x81C04005U &&
10981+ nop == 0x01000000U)
10982+ {
10983+ unsigned long addr;
10984+
10985+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10986+ regs->u_regs[UREG_G1] <<= 32;
10987+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10988+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10989+ regs->tpc = addr;
10990+ regs->tnpc = addr+4;
10991+ return 2;
10992+ }
10993+ } while (0);
10994+
10995+ do { /* PaX: patched PLT emulation #6 */
10996+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10997+
10998+ err = get_user(sethi, (unsigned int *)regs->tpc);
10999+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11000+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11001+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11002+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11003+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11004+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11005+
11006+ if (err)
11007+ break;
11008+
11009+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11010+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11011+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11012+ sllx == 0x83287020U &&
11013+ (or & 0xFFFFE000U) == 0x8A116000U &&
11014+ jmpl == 0x81C04005U &&
11015+ nop == 0x01000000U)
11016+ {
11017+ unsigned long addr;
11018+
11019+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11020+ regs->u_regs[UREG_G1] <<= 32;
11021+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11022+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11023+ regs->tpc = addr;
11024+ regs->tnpc = addr+4;
11025+ return 2;
11026+ }
11027+ } while (0);
11028+
11029+ do { /* PaX: unpatched PLT emulation step 1 */
11030+ unsigned int sethi, ba, nop;
11031+
11032+ err = get_user(sethi, (unsigned int *)regs->tpc);
11033+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11034+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11035+
11036+ if (err)
11037+ break;
11038+
11039+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11040+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11041+ nop == 0x01000000U)
11042+ {
11043+ unsigned long addr;
11044+ unsigned int save, call;
11045+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11046+
11047+ if ((ba & 0xFFC00000U) == 0x30800000U)
11048+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11049+ else
11050+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11051+
11052+ if (test_thread_flag(TIF_32BIT))
11053+ addr &= 0xFFFFFFFFUL;
11054+
11055+ err = get_user(save, (unsigned int *)addr);
11056+ err |= get_user(call, (unsigned int *)(addr+4));
11057+ err |= get_user(nop, (unsigned int *)(addr+8));
11058+ if (err)
11059+ break;
11060+
11061+#ifdef CONFIG_PAX_DLRESOLVE
11062+ if (save == 0x9DE3BFA8U &&
11063+ (call & 0xC0000000U) == 0x40000000U &&
11064+ nop == 0x01000000U)
11065+ {
11066+ struct vm_area_struct *vma;
11067+ unsigned long call_dl_resolve;
11068+
11069+ down_read(&current->mm->mmap_sem);
11070+ call_dl_resolve = current->mm->call_dl_resolve;
11071+ up_read(&current->mm->mmap_sem);
11072+ if (likely(call_dl_resolve))
11073+ goto emulate;
11074+
11075+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11076+
11077+ down_write(&current->mm->mmap_sem);
11078+ if (current->mm->call_dl_resolve) {
11079+ call_dl_resolve = current->mm->call_dl_resolve;
11080+ up_write(&current->mm->mmap_sem);
11081+ if (vma)
11082+ kmem_cache_free(vm_area_cachep, vma);
11083+ goto emulate;
11084+ }
11085+
11086+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11087+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11088+ up_write(&current->mm->mmap_sem);
11089+ if (vma)
11090+ kmem_cache_free(vm_area_cachep, vma);
11091+ return 1;
11092+ }
11093+
11094+ if (pax_insert_vma(vma, call_dl_resolve)) {
11095+ up_write(&current->mm->mmap_sem);
11096+ kmem_cache_free(vm_area_cachep, vma);
11097+ return 1;
11098+ }
11099+
11100+ current->mm->call_dl_resolve = call_dl_resolve;
11101+ up_write(&current->mm->mmap_sem);
11102+
11103+emulate:
11104+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11105+ regs->tpc = call_dl_resolve;
11106+ regs->tnpc = addr+4;
11107+ return 3;
11108+ }
11109+#endif
11110+
11111+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11112+ if ((save & 0xFFC00000U) == 0x05000000U &&
11113+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11114+ nop == 0x01000000U)
11115+ {
11116+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11117+ regs->u_regs[UREG_G2] = addr + 4;
11118+ addr = (save & 0x003FFFFFU) << 10;
11119+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11120+
11121+ if (test_thread_flag(TIF_32BIT))
11122+ addr &= 0xFFFFFFFFUL;
11123+
11124+ regs->tpc = addr;
11125+ regs->tnpc = addr+4;
11126+ return 3;
11127+ }
11128+
11129+ /* PaX: 64-bit PLT stub */
11130+ err = get_user(sethi1, (unsigned int *)addr);
11131+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11132+ err |= get_user(or1, (unsigned int *)(addr+8));
11133+ err |= get_user(or2, (unsigned int *)(addr+12));
11134+ err |= get_user(sllx, (unsigned int *)(addr+16));
11135+ err |= get_user(add, (unsigned int *)(addr+20));
11136+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11137+ err |= get_user(nop, (unsigned int *)(addr+28));
11138+ if (err)
11139+ break;
11140+
11141+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11142+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11143+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11144+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11145+ sllx == 0x89293020U &&
11146+ add == 0x8A010005U &&
11147+ jmpl == 0x89C14000U &&
11148+ nop == 0x01000000U)
11149+ {
11150+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11151+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11152+ regs->u_regs[UREG_G4] <<= 32;
11153+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11154+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11155+ regs->u_regs[UREG_G4] = addr + 24;
11156+ addr = regs->u_regs[UREG_G5];
11157+ regs->tpc = addr;
11158+ regs->tnpc = addr+4;
11159+ return 3;
11160+ }
11161+ }
11162+ } while (0);
11163+
11164+#ifdef CONFIG_PAX_DLRESOLVE
11165+ do { /* PaX: unpatched PLT emulation step 2 */
11166+ unsigned int save, call, nop;
11167+
11168+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11169+ err |= get_user(call, (unsigned int *)regs->tpc);
11170+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11171+ if (err)
11172+ break;
11173+
11174+ if (save == 0x9DE3BFA8U &&
11175+ (call & 0xC0000000U) == 0x40000000U &&
11176+ nop == 0x01000000U)
11177+ {
11178+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11179+
11180+ if (test_thread_flag(TIF_32BIT))
11181+ dl_resolve &= 0xFFFFFFFFUL;
11182+
11183+ regs->u_regs[UREG_RETPC] = regs->tpc;
11184+ regs->tpc = dl_resolve;
11185+ regs->tnpc = dl_resolve+4;
11186+ return 3;
11187+ }
11188+ } while (0);
11189+#endif
11190+
11191+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11192+ unsigned int sethi, ba, nop;
11193+
11194+ err = get_user(sethi, (unsigned int *)regs->tpc);
11195+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11196+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11197+
11198+ if (err)
11199+ break;
11200+
11201+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11202+ (ba & 0xFFF00000U) == 0x30600000U &&
11203+ nop == 0x01000000U)
11204+ {
11205+ unsigned long addr;
11206+
11207+ addr = (sethi & 0x003FFFFFU) << 10;
11208+ regs->u_regs[UREG_G1] = addr;
11209+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11210+
11211+ if (test_thread_flag(TIF_32BIT))
11212+ addr &= 0xFFFFFFFFUL;
11213+
11214+ regs->tpc = addr;
11215+ regs->tnpc = addr+4;
11216+ return 2;
11217+ }
11218+ } while (0);
11219+
11220+#endif
11221+
11222+ return 1;
11223+}
11224+
11225+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11226+{
11227+ unsigned long i;
11228+
11229+ printk(KERN_ERR "PAX: bytes at PC: ");
11230+ for (i = 0; i < 8; i++) {
11231+ unsigned int c;
11232+ if (get_user(c, (unsigned int *)pc+i))
11233+ printk(KERN_CONT "???????? ");
11234+ else
11235+ printk(KERN_CONT "%08x ", c);
11236+ }
11237+ printk("\n");
11238+}
11239+#endif
11240+
11241 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11242 {
11243 enum ctx_state prev_state = exception_enter();
11244@@ -344,6 +807,29 @@ retry:
11245 if (!vma)
11246 goto bad_area;
11247
11248+#ifdef CONFIG_PAX_PAGEEXEC
11249+ /* PaX: detect ITLB misses on non-exec pages */
11250+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11251+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11252+ {
11253+ if (address != regs->tpc)
11254+ goto good_area;
11255+
11256+ up_read(&mm->mmap_sem);
11257+ switch (pax_handle_fetch_fault(regs)) {
11258+
11259+#ifdef CONFIG_PAX_EMUPLT
11260+ case 2:
11261+ case 3:
11262+ return;
11263+#endif
11264+
11265+ }
11266+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11267+ do_group_exit(SIGKILL);
11268+ }
11269+#endif
11270+
11271 /* Pure DTLB misses do not tell us whether the fault causing
11272 * load/store/atomic was a write or not, it only says that there
11273 * was no match. So in such a case we (carefully) read the
11274diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11275index 3096317..a7b7654 100644
11276--- a/arch/sparc/mm/hugetlbpage.c
11277+++ b/arch/sparc/mm/hugetlbpage.c
11278@@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11279 unsigned long addr,
11280 unsigned long len,
11281 unsigned long pgoff,
11282- unsigned long flags)
11283+ unsigned long flags,
11284+ unsigned long offset)
11285 {
11286 unsigned long task_size = TASK_SIZE;
11287 struct vm_unmapped_area_info info;
11288@@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11289
11290 info.flags = 0;
11291 info.length = len;
11292- info.low_limit = TASK_UNMAPPED_BASE;
11293+ info.low_limit = mm->mmap_base;
11294 info.high_limit = min(task_size, VA_EXCLUDE_START);
11295 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11296 info.align_offset = 0;
11297+ info.threadstack_offset = offset;
11298 addr = vm_unmapped_area(&info);
11299
11300 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11301 VM_BUG_ON(addr != -ENOMEM);
11302 info.low_limit = VA_EXCLUDE_END;
11303+
11304+#ifdef CONFIG_PAX_RANDMMAP
11305+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11306+ info.low_limit += mm->delta_mmap;
11307+#endif
11308+
11309 info.high_limit = task_size;
11310 addr = vm_unmapped_area(&info);
11311 }
11312@@ -56,7 +64,8 @@ static unsigned long
11313 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11314 const unsigned long len,
11315 const unsigned long pgoff,
11316- const unsigned long flags)
11317+ const unsigned long flags,
11318+ const unsigned long offset)
11319 {
11320 struct mm_struct *mm = current->mm;
11321 unsigned long addr = addr0;
11322@@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11323 info.high_limit = mm->mmap_base;
11324 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11325 info.align_offset = 0;
11326+ info.threadstack_offset = offset;
11327 addr = vm_unmapped_area(&info);
11328
11329 /*
11330@@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11331 VM_BUG_ON(addr != -ENOMEM);
11332 info.flags = 0;
11333 info.low_limit = TASK_UNMAPPED_BASE;
11334+
11335+#ifdef CONFIG_PAX_RANDMMAP
11336+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11337+ info.low_limit += mm->delta_mmap;
11338+#endif
11339+
11340 info.high_limit = STACK_TOP32;
11341 addr = vm_unmapped_area(&info);
11342 }
11343@@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11344 struct mm_struct *mm = current->mm;
11345 struct vm_area_struct *vma;
11346 unsigned long task_size = TASK_SIZE;
11347+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11348
11349 if (test_thread_flag(TIF_32BIT))
11350 task_size = STACK_TOP32;
11351@@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11352 return addr;
11353 }
11354
11355+#ifdef CONFIG_PAX_RANDMMAP
11356+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11357+#endif
11358+
11359 if (addr) {
11360 addr = ALIGN(addr, HPAGE_SIZE);
11361 vma = find_vma(mm, addr);
11362- if (task_size - len >= addr &&
11363- (!vma || addr + len <= vma->vm_start))
11364+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11365 return addr;
11366 }
11367 if (mm->get_unmapped_area == arch_get_unmapped_area)
11368 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11369- pgoff, flags);
11370+ pgoff, flags, offset);
11371 else
11372 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11373- pgoff, flags);
11374+ pgoff, flags, offset);
11375 }
11376
11377 pte_t *huge_pte_alloc(struct mm_struct *mm,
11378diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11379index 5322e53..f820c5e 100644
11380--- a/arch/sparc/mm/init_64.c
11381+++ b/arch/sparc/mm/init_64.c
11382@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11383 int num_kernel_image_mappings;
11384
11385 #ifdef CONFIG_DEBUG_DCFLUSH
11386-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11387+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11388 #ifdef CONFIG_SMP
11389-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11390+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11391 #endif
11392 #endif
11393
11394@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11395 {
11396 BUG_ON(tlb_type == hypervisor);
11397 #ifdef CONFIG_DEBUG_DCFLUSH
11398- atomic_inc(&dcpage_flushes);
11399+ atomic_inc_unchecked(&dcpage_flushes);
11400 #endif
11401
11402 #ifdef DCACHE_ALIASING_POSSIBLE
11403@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11404
11405 #ifdef CONFIG_DEBUG_DCFLUSH
11406 seq_printf(m, "DCPageFlushes\t: %d\n",
11407- atomic_read(&dcpage_flushes));
11408+ atomic_read_unchecked(&dcpage_flushes));
11409 #ifdef CONFIG_SMP
11410 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11411- atomic_read(&dcpage_flushes_xcall));
11412+ atomic_read_unchecked(&dcpage_flushes_xcall));
11413 #endif /* CONFIG_SMP */
11414 #endif /* CONFIG_DEBUG_DCFLUSH */
11415 }
11416diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11417index b3692ce..e4517c9 100644
11418--- a/arch/tile/Kconfig
11419+++ b/arch/tile/Kconfig
11420@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11421
11422 config KEXEC
11423 bool "kexec system call"
11424+ depends on !GRKERNSEC_KMEM
11425 ---help---
11426 kexec is a system call that implements the ability to shutdown your
11427 current kernel, and to start another kernel. It is like a reboot
11428diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11429index ad220ee..2f537b3 100644
11430--- a/arch/tile/include/asm/atomic_64.h
11431+++ b/arch/tile/include/asm/atomic_64.h
11432@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11433
11434 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11435
11436+#define atomic64_read_unchecked(v) atomic64_read(v)
11437+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11438+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11439+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11440+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11441+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11442+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11443+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11444+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11445+
11446 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11447 #define smp_mb__before_atomic_dec() smp_mb()
11448 #define smp_mb__after_atomic_dec() smp_mb()
11449diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11450index 6160761..00cac88 100644
11451--- a/arch/tile/include/asm/cache.h
11452+++ b/arch/tile/include/asm/cache.h
11453@@ -15,11 +15,12 @@
11454 #ifndef _ASM_TILE_CACHE_H
11455 #define _ASM_TILE_CACHE_H
11456
11457+#include <linux/const.h>
11458 #include <arch/chip.h>
11459
11460 /* bytes per L1 data cache line */
11461 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11462-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11463+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11464
11465 /* bytes per L2 cache line */
11466 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11467diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11468index b6cde32..c0cb736 100644
11469--- a/arch/tile/include/asm/uaccess.h
11470+++ b/arch/tile/include/asm/uaccess.h
11471@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11472 const void __user *from,
11473 unsigned long n)
11474 {
11475- int sz = __compiletime_object_size(to);
11476+ size_t sz = __compiletime_object_size(to);
11477
11478- if (likely(sz == -1 || sz >= n))
11479+ if (likely(sz == (size_t)-1 || sz >= n))
11480 n = _copy_from_user(to, from, n);
11481 else
11482 copy_from_user_overflow();
11483diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11484index 0cb3bba..7338b2d 100644
11485--- a/arch/tile/mm/hugetlbpage.c
11486+++ b/arch/tile/mm/hugetlbpage.c
11487@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11488 info.high_limit = TASK_SIZE;
11489 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11490 info.align_offset = 0;
11491+ info.threadstack_offset = 0;
11492 return vm_unmapped_area(&info);
11493 }
11494
11495@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11496 info.high_limit = current->mm->mmap_base;
11497 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11498 info.align_offset = 0;
11499+ info.threadstack_offset = 0;
11500 addr = vm_unmapped_area(&info);
11501
11502 /*
11503diff --git a/arch/um/Makefile b/arch/um/Makefile
11504index 36e658a..71a5c5a 100644
11505--- a/arch/um/Makefile
11506+++ b/arch/um/Makefile
11507@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11508 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11509 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11510
11511+ifdef CONSTIFY_PLUGIN
11512+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11513+endif
11514+
11515 #This will adjust *FLAGS accordingly to the platform.
11516 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11517
11518diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11519index 19e1bdd..3665b77 100644
11520--- a/arch/um/include/asm/cache.h
11521+++ b/arch/um/include/asm/cache.h
11522@@ -1,6 +1,7 @@
11523 #ifndef __UM_CACHE_H
11524 #define __UM_CACHE_H
11525
11526+#include <linux/const.h>
11527
11528 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11529 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11530@@ -12,6 +13,6 @@
11531 # define L1_CACHE_SHIFT 5
11532 #endif
11533
11534-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11535+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11536
11537 #endif
11538diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11539index 2e0a6b1..a64d0f5 100644
11540--- a/arch/um/include/asm/kmap_types.h
11541+++ b/arch/um/include/asm/kmap_types.h
11542@@ -8,6 +8,6 @@
11543
11544 /* No more #include "asm/arch/kmap_types.h" ! */
11545
11546-#define KM_TYPE_NR 14
11547+#define KM_TYPE_NR 15
11548
11549 #endif
11550diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11551index 5ff53d9..5850cdf 100644
11552--- a/arch/um/include/asm/page.h
11553+++ b/arch/um/include/asm/page.h
11554@@ -14,6 +14,9 @@
11555 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11556 #define PAGE_MASK (~(PAGE_SIZE-1))
11557
11558+#define ktla_ktva(addr) (addr)
11559+#define ktva_ktla(addr) (addr)
11560+
11561 #ifndef __ASSEMBLY__
11562
11563 struct page;
11564diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11565index 0032f92..cd151e0 100644
11566--- a/arch/um/include/asm/pgtable-3level.h
11567+++ b/arch/um/include/asm/pgtable-3level.h
11568@@ -58,6 +58,7 @@
11569 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11570 #define pud_populate(mm, pud, pmd) \
11571 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11572+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11573
11574 #ifdef CONFIG_64BIT
11575 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11576diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11577index eecc414..48adb87 100644
11578--- a/arch/um/kernel/process.c
11579+++ b/arch/um/kernel/process.c
11580@@ -356,22 +356,6 @@ int singlestepping(void * t)
11581 return 2;
11582 }
11583
11584-/*
11585- * Only x86 and x86_64 have an arch_align_stack().
11586- * All other arches have "#define arch_align_stack(x) (x)"
11587- * in their asm/system.h
11588- * As this is included in UML from asm-um/system-generic.h,
11589- * we can use it to behave as the subarch does.
11590- */
11591-#ifndef arch_align_stack
11592-unsigned long arch_align_stack(unsigned long sp)
11593-{
11594- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11595- sp -= get_random_int() % 8192;
11596- return sp & ~0xf;
11597-}
11598-#endif
11599-
11600 unsigned long get_wchan(struct task_struct *p)
11601 {
11602 unsigned long stack_page, sp, ip;
11603diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11604index ad8f795..2c7eec6 100644
11605--- a/arch/unicore32/include/asm/cache.h
11606+++ b/arch/unicore32/include/asm/cache.h
11607@@ -12,8 +12,10 @@
11608 #ifndef __UNICORE_CACHE_H__
11609 #define __UNICORE_CACHE_H__
11610
11611-#define L1_CACHE_SHIFT (5)
11612-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11613+#include <linux/const.h>
11614+
11615+#define L1_CACHE_SHIFT 5
11616+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11617
11618 /*
11619 * Memory returned by kmalloc() may be used for DMA, so we must make
11620diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11621index 0952ecd..75e0e8a 100644
11622--- a/arch/x86/Kconfig
11623+++ b/arch/x86/Kconfig
11624@@ -249,7 +249,7 @@ config X86_HT
11625
11626 config X86_32_LAZY_GS
11627 def_bool y
11628- depends on X86_32 && !CC_STACKPROTECTOR
11629+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11630
11631 config ARCH_HWEIGHT_CFLAGS
11632 string
11633@@ -1104,6 +1104,7 @@ config MICROCODE_EARLY
11634
11635 config X86_MSR
11636 tristate "/dev/cpu/*/msr - Model-specific register support"
11637+ depends on !GRKERNSEC_KMEM
11638 ---help---
11639 This device gives privileged processes access to the x86
11640 Model-Specific Registers (MSRs). It is a character device with
11641@@ -1127,7 +1128,7 @@ choice
11642
11643 config NOHIGHMEM
11644 bool "off"
11645- depends on !X86_NUMAQ
11646+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11647 ---help---
11648 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11649 However, the address space of 32-bit x86 processors is only 4
11650@@ -1164,7 +1165,7 @@ config NOHIGHMEM
11651
11652 config HIGHMEM4G
11653 bool "4GB"
11654- depends on !X86_NUMAQ
11655+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11656 ---help---
11657 Select this if you have a 32-bit processor and between 1 and 4
11658 gigabytes of physical RAM.
11659@@ -1217,7 +1218,7 @@ config PAGE_OFFSET
11660 hex
11661 default 0xB0000000 if VMSPLIT_3G_OPT
11662 default 0x80000000 if VMSPLIT_2G
11663- default 0x78000000 if VMSPLIT_2G_OPT
11664+ default 0x70000000 if VMSPLIT_2G_OPT
11665 default 0x40000000 if VMSPLIT_1G
11666 default 0xC0000000
11667 depends on X86_32
11668@@ -1619,6 +1620,7 @@ config SECCOMP
11669
11670 config CC_STACKPROTECTOR
11671 bool "Enable -fstack-protector buffer overflow detection"
11672+ depends on X86_64 || !PAX_MEMORY_UDEREF
11673 ---help---
11674 This option turns on the -fstack-protector GCC feature. This
11675 feature puts, at the beginning of functions, a canary value on
11676@@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
11677
11678 config KEXEC
11679 bool "kexec system call"
11680+ depends on !GRKERNSEC_KMEM
11681 ---help---
11682 kexec is a system call that implements the ability to shutdown your
11683 current kernel, and to start another kernel. It is like a reboot
11684@@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
11685 config PHYSICAL_ALIGN
11686 hex "Alignment value to which kernel should be aligned"
11687 default "0x1000000"
11688+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11689+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11690 range 0x2000 0x1000000 if X86_32
11691 range 0x200000 0x1000000 if X86_64
11692 ---help---
11693@@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
11694 If unsure, say N.
11695
11696 config COMPAT_VDSO
11697- def_bool y
11698+ def_bool n
11699 prompt "Compat VDSO support"
11700 depends on X86_32 || IA32_EMULATION
11701+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11702 ---help---
11703 Map the 32-bit VDSO to the predictable old-style address too.
11704
11705diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11706index c026cca..14657ae 100644
11707--- a/arch/x86/Kconfig.cpu
11708+++ b/arch/x86/Kconfig.cpu
11709@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11710
11711 config X86_F00F_BUG
11712 def_bool y
11713- depends on M586MMX || M586TSC || M586 || M486
11714+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11715
11716 config X86_INVD_BUG
11717 def_bool y
11718@@ -327,7 +327,7 @@ config X86_INVD_BUG
11719
11720 config X86_ALIGNMENT_16
11721 def_bool y
11722- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11723+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11724
11725 config X86_INTEL_USERCOPY
11726 def_bool y
11727@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11728 # generates cmov.
11729 config X86_CMOV
11730 def_bool y
11731- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11732+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11733
11734 config X86_MINIMUM_CPU_FAMILY
11735 int
11736diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11737index 0f3621e..282f24b 100644
11738--- a/arch/x86/Kconfig.debug
11739+++ b/arch/x86/Kconfig.debug
11740@@ -84,7 +84,7 @@ config X86_PTDUMP
11741 config DEBUG_RODATA
11742 bool "Write protect kernel read-only data structures"
11743 default y
11744- depends on DEBUG_KERNEL
11745+ depends on DEBUG_KERNEL && BROKEN
11746 ---help---
11747 Mark the kernel read-only data as write-protected in the pagetables,
11748 in order to catch accidental (and incorrect) writes to such const
11749@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
11750
11751 config DEBUG_SET_MODULE_RONX
11752 bool "Set loadable kernel module data as NX and text as RO"
11753- depends on MODULES
11754+ depends on MODULES && BROKEN
11755 ---help---
11756 This option helps catch unintended modifications to loadable
11757 kernel module's text and read-only data. It also prevents execution
11758diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11759index 57d0215..b4373fb 100644
11760--- a/arch/x86/Makefile
11761+++ b/arch/x86/Makefile
11762@@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
11763 # CPU-specific tuning. Anything which can be shared with UML should go here.
11764 include $(srctree)/arch/x86/Makefile_32.cpu
11765 KBUILD_CFLAGS += $(cflags-y)
11766-
11767- # temporary until string.h is fixed
11768- KBUILD_CFLAGS += -ffreestanding
11769 else
11770 BITS := 64
11771 UTS_MACHINE := x86_64
11772 CHECKFLAGS += -D__x86_64__ -m64
11773
11774+ biarch := $(call cc-option,-m64)
11775 KBUILD_AFLAGS += -m64
11776 KBUILD_CFLAGS += -m64
11777
11778@@ -89,6 +87,9 @@ else
11779 KBUILD_CFLAGS += -maccumulate-outgoing-args
11780 endif
11781
11782+# temporary until string.h is fixed
11783+KBUILD_CFLAGS += -ffreestanding
11784+
11785 ifdef CONFIG_CC_STACKPROTECTOR
11786 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11787 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11788@@ -247,3 +248,12 @@ define archhelp
11789 echo ' FDINITRD=file initrd for the booted kernel'
11790 echo ' kvmconfig - Enable additional options for guest kernel support'
11791 endef
11792+
11793+define OLD_LD
11794+
11795+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11796+*** Please upgrade your binutils to 2.18 or newer
11797+endef
11798+
11799+archprepare:
11800+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11801diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11802index d9c1195..a26ca0d 100644
11803--- a/arch/x86/boot/Makefile
11804+++ b/arch/x86/boot/Makefile
11805@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
11806 $(call cc-option, -fno-unit-at-a-time)) \
11807 $(call cc-option, -fno-stack-protector) \
11808 $(call cc-option, -mpreferred-stack-boundary=2)
11809+ifdef CONSTIFY_PLUGIN
11810+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11811+endif
11812 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11813 GCOV_PROFILE := n
11814
11815diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11816index 878e4b9..20537ab 100644
11817--- a/arch/x86/boot/bitops.h
11818+++ b/arch/x86/boot/bitops.h
11819@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11820 u8 v;
11821 const u32 *p = (const u32 *)addr;
11822
11823- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11824+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11825 return v;
11826 }
11827
11828@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11829
11830 static inline void set_bit(int nr, void *addr)
11831 {
11832- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11833+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11834 }
11835
11836 #endif /* BOOT_BITOPS_H */
11837diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11838index ef72bae..353a184 100644
11839--- a/arch/x86/boot/boot.h
11840+++ b/arch/x86/boot/boot.h
11841@@ -85,7 +85,7 @@ static inline void io_delay(void)
11842 static inline u16 ds(void)
11843 {
11844 u16 seg;
11845- asm("movw %%ds,%0" : "=rm" (seg));
11846+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11847 return seg;
11848 }
11849
11850@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11851 static inline int memcmp(const void *s1, const void *s2, size_t len)
11852 {
11853 u8 diff;
11854- asm("repe; cmpsb; setnz %0"
11855+ asm volatile("repe; cmpsb; setnz %0"
11856 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11857 return diff;
11858 }
11859diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11860index c8a6792..2402765 100644
11861--- a/arch/x86/boot/compressed/Makefile
11862+++ b/arch/x86/boot/compressed/Makefile
11863@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
11864 KBUILD_CFLAGS += -mno-mmx -mno-sse
11865 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11866 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11867+ifdef CONSTIFY_PLUGIN
11868+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11869+endif
11870
11871 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11872 GCOV_PROFILE := n
11873diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11874index a53440e..c3dbf1e 100644
11875--- a/arch/x86/boot/compressed/efi_stub_32.S
11876+++ b/arch/x86/boot/compressed/efi_stub_32.S
11877@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11878 * parameter 2, ..., param n. To make things easy, we save the return
11879 * address of efi_call_phys in a global variable.
11880 */
11881- popl %ecx
11882- movl %ecx, saved_return_addr(%edx)
11883- /* get the function pointer into ECX*/
11884- popl %ecx
11885- movl %ecx, efi_rt_function_ptr(%edx)
11886+ popl saved_return_addr(%edx)
11887+ popl efi_rt_function_ptr(%edx)
11888
11889 /*
11890 * 3. Call the physical function.
11891 */
11892- call *%ecx
11893+ call *efi_rt_function_ptr(%edx)
11894
11895 /*
11896 * 4. Balance the stack. And because EAX contain the return value,
11897@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11898 1: popl %edx
11899 subl $1b, %edx
11900
11901- movl efi_rt_function_ptr(%edx), %ecx
11902- pushl %ecx
11903+ pushl efi_rt_function_ptr(%edx)
11904
11905 /*
11906 * 10. Push the saved return address onto the stack and return.
11907 */
11908- movl saved_return_addr(%edx), %ecx
11909- pushl %ecx
11910- ret
11911+ jmpl *saved_return_addr(%edx)
11912 ENDPROC(efi_call_phys)
11913 .previous
11914
11915diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11916index 5d6f689..9d06730 100644
11917--- a/arch/x86/boot/compressed/head_32.S
11918+++ b/arch/x86/boot/compressed/head_32.S
11919@@ -118,7 +118,7 @@ preferred_addr:
11920 notl %eax
11921 andl %eax, %ebx
11922 #else
11923- movl $LOAD_PHYSICAL_ADDR, %ebx
11924+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11925 #endif
11926
11927 /* Target address to relocate to for decompression */
11928diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11929index c337422..2c5be72 100644
11930--- a/arch/x86/boot/compressed/head_64.S
11931+++ b/arch/x86/boot/compressed/head_64.S
11932@@ -95,7 +95,7 @@ ENTRY(startup_32)
11933 notl %eax
11934 andl %eax, %ebx
11935 #else
11936- movl $LOAD_PHYSICAL_ADDR, %ebx
11937+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11938 #endif
11939
11940 /* Target address to relocate to for decompression */
11941@@ -270,7 +270,7 @@ preferred_addr:
11942 notq %rax
11943 andq %rax, %rbp
11944 #else
11945- movq $LOAD_PHYSICAL_ADDR, %rbp
11946+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11947 #endif
11948
11949 /* Target address to relocate to for decompression */
11950@@ -362,8 +362,8 @@ gdt:
11951 .long gdt
11952 .word 0
11953 .quad 0x0000000000000000 /* NULL descriptor */
11954- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11955- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11956+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11957+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11958 .quad 0x0080890000000000 /* TS descriptor */
11959 .quad 0x0000000000000000 /* TS continued */
11960 gdt_end:
11961diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11962index 434f077..b6b4b38 100644
11963--- a/arch/x86/boot/compressed/misc.c
11964+++ b/arch/x86/boot/compressed/misc.c
11965@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
11966 * Calculate the delta between where vmlinux was linked to load
11967 * and where it was actually loaded.
11968 */
11969- delta = min_addr - LOAD_PHYSICAL_ADDR;
11970+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
11971 if (!delta) {
11972 debug_putstr("No relocation needed... ");
11973 return;
11974@@ -380,7 +380,7 @@ static void parse_elf(void *output)
11975 case PT_LOAD:
11976 #ifdef CONFIG_RELOCATABLE
11977 dest = output;
11978- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11979+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11980 #else
11981 dest = (void *)(phdr->p_paddr);
11982 #endif
11983@@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11984 error("Destination address too large");
11985 #endif
11986 #ifndef CONFIG_RELOCATABLE
11987- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11988+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11989 error("Wrong destination address");
11990 #endif
11991
11992diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11993index 4d3ff03..e4972ff 100644
11994--- a/arch/x86/boot/cpucheck.c
11995+++ b/arch/x86/boot/cpucheck.c
11996@@ -74,7 +74,7 @@ static int has_fpu(void)
11997 u16 fcw = -1, fsw = -1;
11998 u32 cr0;
11999
12000- asm("movl %%cr0,%0" : "=r" (cr0));
12001+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12002 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12003 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12004 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12005@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12006 {
12007 u32 f0, f1;
12008
12009- asm("pushfl ; "
12010+ asm volatile("pushfl ; "
12011 "pushfl ; "
12012 "popl %0 ; "
12013 "movl %0,%1 ; "
12014@@ -115,7 +115,7 @@ static void get_flags(void)
12015 set_bit(X86_FEATURE_FPU, cpu.flags);
12016
12017 if (has_eflag(X86_EFLAGS_ID)) {
12018- asm("cpuid"
12019+ asm volatile("cpuid"
12020 : "=a" (max_intel_level),
12021 "=b" (cpu_vendor[0]),
12022 "=d" (cpu_vendor[1]),
12023@@ -124,7 +124,7 @@ static void get_flags(void)
12024
12025 if (max_intel_level >= 0x00000001 &&
12026 max_intel_level <= 0x0000ffff) {
12027- asm("cpuid"
12028+ asm volatile("cpuid"
12029 : "=a" (tfms),
12030 "=c" (cpu.flags[4]),
12031 "=d" (cpu.flags[0])
12032@@ -136,7 +136,7 @@ static void get_flags(void)
12033 cpu.model += ((tfms >> 16) & 0xf) << 4;
12034 }
12035
12036- asm("cpuid"
12037+ asm volatile("cpuid"
12038 : "=a" (max_amd_level)
12039 : "a" (0x80000000)
12040 : "ebx", "ecx", "edx");
12041@@ -144,7 +144,7 @@ static void get_flags(void)
12042 if (max_amd_level >= 0x80000001 &&
12043 max_amd_level <= 0x8000ffff) {
12044 u32 eax = 0x80000001;
12045- asm("cpuid"
12046+ asm volatile("cpuid"
12047 : "+a" (eax),
12048 "=c" (cpu.flags[6]),
12049 "=d" (cpu.flags[1])
12050@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12051 u32 ecx = MSR_K7_HWCR;
12052 u32 eax, edx;
12053
12054- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12055+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12056 eax &= ~(1 << 15);
12057- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12058+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12059
12060 get_flags(); /* Make sure it really did something */
12061 err = check_flags();
12062@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12063 u32 ecx = MSR_VIA_FCR;
12064 u32 eax, edx;
12065
12066- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12067+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12068 eax |= (1<<1)|(1<<7);
12069- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12070+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12071
12072 set_bit(X86_FEATURE_CX8, cpu.flags);
12073 err = check_flags();
12074@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12075 u32 eax, edx;
12076 u32 level = 1;
12077
12078- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12079- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12080- asm("cpuid"
12081+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12082+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12083+ asm volatile("cpuid"
12084 : "+a" (level), "=d" (cpu.flags[0])
12085 : : "ecx", "ebx");
12086- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12087+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12088
12089 err = check_flags();
12090 }
12091diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12092index 9ec06a1..2c25e79 100644
12093--- a/arch/x86/boot/header.S
12094+++ b/arch/x86/boot/header.S
12095@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12096 # single linked list of
12097 # struct setup_data
12098
12099-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12100+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12101
12102 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12103+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12104+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12105+#else
12106 #define VO_INIT_SIZE (VO__end - VO__text)
12107+#endif
12108 #if ZO_INIT_SIZE > VO_INIT_SIZE
12109 #define INIT_SIZE ZO_INIT_SIZE
12110 #else
12111diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12112index db75d07..8e6d0af 100644
12113--- a/arch/x86/boot/memory.c
12114+++ b/arch/x86/boot/memory.c
12115@@ -19,7 +19,7 @@
12116
12117 static int detect_memory_e820(void)
12118 {
12119- int count = 0;
12120+ unsigned int count = 0;
12121 struct biosregs ireg, oreg;
12122 struct e820entry *desc = boot_params.e820_map;
12123 static struct e820entry buf; /* static so it is zeroed */
12124diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12125index 11e8c6e..fdbb1ed 100644
12126--- a/arch/x86/boot/video-vesa.c
12127+++ b/arch/x86/boot/video-vesa.c
12128@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12129
12130 boot_params.screen_info.vesapm_seg = oreg.es;
12131 boot_params.screen_info.vesapm_off = oreg.di;
12132+ boot_params.screen_info.vesapm_size = oreg.cx;
12133 }
12134
12135 /*
12136diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12137index 43eda28..5ab5fdb 100644
12138--- a/arch/x86/boot/video.c
12139+++ b/arch/x86/boot/video.c
12140@@ -96,7 +96,7 @@ static void store_mode_params(void)
12141 static unsigned int get_entry(void)
12142 {
12143 char entry_buf[4];
12144- int i, len = 0;
12145+ unsigned int i, len = 0;
12146 int key;
12147 unsigned int v;
12148
12149diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12150index 9105655..41779c1 100644
12151--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12152+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12153@@ -8,6 +8,8 @@
12154 * including this sentence is retained in full.
12155 */
12156
12157+#include <asm/alternative-asm.h>
12158+
12159 .extern crypto_ft_tab
12160 .extern crypto_it_tab
12161 .extern crypto_fl_tab
12162@@ -70,6 +72,8 @@
12163 je B192; \
12164 leaq 32(r9),r9;
12165
12166+#define ret pax_force_retaddr; ret
12167+
12168 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12169 movq r1,r2; \
12170 movq r3,r4; \
12171diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12172index 477e9d7..c92c7d8 100644
12173--- a/arch/x86/crypto/aesni-intel_asm.S
12174+++ b/arch/x86/crypto/aesni-intel_asm.S
12175@@ -31,6 +31,7 @@
12176
12177 #include <linux/linkage.h>
12178 #include <asm/inst.h>
12179+#include <asm/alternative-asm.h>
12180
12181 #ifdef __x86_64__
12182 .data
12183@@ -205,7 +206,7 @@ enc: .octa 0x2
12184 * num_initial_blocks = b mod 4
12185 * encrypt the initial num_initial_blocks blocks and apply ghash on
12186 * the ciphertext
12187-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12188+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12189 * are clobbered
12190 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12191 */
12192@@ -214,8 +215,8 @@ enc: .octa 0x2
12193 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12194 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12195 mov arg7, %r10 # %r10 = AAD
12196- mov arg8, %r12 # %r12 = aadLen
12197- mov %r12, %r11
12198+ mov arg8, %r15 # %r15 = aadLen
12199+ mov %r15, %r11
12200 pxor %xmm\i, %xmm\i
12201 _get_AAD_loop\num_initial_blocks\operation:
12202 movd (%r10), \TMP1
12203@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12204 psrldq $4, %xmm\i
12205 pxor \TMP1, %xmm\i
12206 add $4, %r10
12207- sub $4, %r12
12208+ sub $4, %r15
12209 jne _get_AAD_loop\num_initial_blocks\operation
12210 cmp $16, %r11
12211 je _get_AAD_loop2_done\num_initial_blocks\operation
12212- mov $16, %r12
12213+ mov $16, %r15
12214 _get_AAD_loop2\num_initial_blocks\operation:
12215 psrldq $4, %xmm\i
12216- sub $4, %r12
12217- cmp %r11, %r12
12218+ sub $4, %r15
12219+ cmp %r11, %r15
12220 jne _get_AAD_loop2\num_initial_blocks\operation
12221 _get_AAD_loop2_done\num_initial_blocks\operation:
12222 movdqa SHUF_MASK(%rip), %xmm14
12223@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12224 * num_initial_blocks = b mod 4
12225 * encrypt the initial num_initial_blocks blocks and apply ghash on
12226 * the ciphertext
12227-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12228+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12229 * are clobbered
12230 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12231 */
12232@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12233 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12234 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12235 mov arg7, %r10 # %r10 = AAD
12236- mov arg8, %r12 # %r12 = aadLen
12237- mov %r12, %r11
12238+ mov arg8, %r15 # %r15 = aadLen
12239+ mov %r15, %r11
12240 pxor %xmm\i, %xmm\i
12241 _get_AAD_loop\num_initial_blocks\operation:
12242 movd (%r10), \TMP1
12243@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12244 psrldq $4, %xmm\i
12245 pxor \TMP1, %xmm\i
12246 add $4, %r10
12247- sub $4, %r12
12248+ sub $4, %r15
12249 jne _get_AAD_loop\num_initial_blocks\operation
12250 cmp $16, %r11
12251 je _get_AAD_loop2_done\num_initial_blocks\operation
12252- mov $16, %r12
12253+ mov $16, %r15
12254 _get_AAD_loop2\num_initial_blocks\operation:
12255 psrldq $4, %xmm\i
12256- sub $4, %r12
12257- cmp %r11, %r12
12258+ sub $4, %r15
12259+ cmp %r11, %r15
12260 jne _get_AAD_loop2\num_initial_blocks\operation
12261 _get_AAD_loop2_done\num_initial_blocks\operation:
12262 movdqa SHUF_MASK(%rip), %xmm14
12263@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12264 *
12265 *****************************************************************************/
12266 ENTRY(aesni_gcm_dec)
12267- push %r12
12268+ push %r15
12269 push %r13
12270 push %r14
12271 mov %rsp, %r14
12272@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12273 */
12274 sub $VARIABLE_OFFSET, %rsp
12275 and $~63, %rsp # align rsp to 64 bytes
12276- mov %arg6, %r12
12277- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12278+ mov %arg6, %r15
12279+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12280 movdqa SHUF_MASK(%rip), %xmm2
12281 PSHUFB_XMM %xmm2, %xmm13
12282
12283@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12284 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12285 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12286 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12287- mov %r13, %r12
12288- and $(3<<4), %r12
12289+ mov %r13, %r15
12290+ and $(3<<4), %r15
12291 jz _initial_num_blocks_is_0_decrypt
12292- cmp $(2<<4), %r12
12293+ cmp $(2<<4), %r15
12294 jb _initial_num_blocks_is_1_decrypt
12295 je _initial_num_blocks_is_2_decrypt
12296 _initial_num_blocks_is_3_decrypt:
12297@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12298 sub $16, %r11
12299 add %r13, %r11
12300 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12301- lea SHIFT_MASK+16(%rip), %r12
12302- sub %r13, %r12
12303+ lea SHIFT_MASK+16(%rip), %r15
12304+ sub %r13, %r15
12305 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12306 # (%r13 is the number of bytes in plaintext mod 16)
12307- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12308+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12309 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12310
12311 movdqa %xmm1, %xmm2
12312 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12313- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12314+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12315 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12316 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12317 pand %xmm1, %xmm2
12318@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12319 sub $1, %r13
12320 jne _less_than_8_bytes_left_decrypt
12321 _multiple_of_16_bytes_decrypt:
12322- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12323- shl $3, %r12 # convert into number of bits
12324- movd %r12d, %xmm15 # len(A) in %xmm15
12325+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12326+ shl $3, %r15 # convert into number of bits
12327+ movd %r15d, %xmm15 # len(A) in %xmm15
12328 shl $3, %arg4 # len(C) in bits (*128)
12329 MOVQ_R64_XMM %arg4, %xmm1
12330 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12331@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12332 mov %r14, %rsp
12333 pop %r14
12334 pop %r13
12335- pop %r12
12336+ pop %r15
12337+ pax_force_retaddr
12338 ret
12339 ENDPROC(aesni_gcm_dec)
12340
12341@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12342 * poly = x^128 + x^127 + x^126 + x^121 + 1
12343 ***************************************************************************/
12344 ENTRY(aesni_gcm_enc)
12345- push %r12
12346+ push %r15
12347 push %r13
12348 push %r14
12349 mov %rsp, %r14
12350@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12351 #
12352 sub $VARIABLE_OFFSET, %rsp
12353 and $~63, %rsp
12354- mov %arg6, %r12
12355- movdqu (%r12), %xmm13
12356+ mov %arg6, %r15
12357+ movdqu (%r15), %xmm13
12358 movdqa SHUF_MASK(%rip), %xmm2
12359 PSHUFB_XMM %xmm2, %xmm13
12360
12361@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12362 movdqa %xmm13, HashKey(%rsp)
12363 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12364 and $-16, %r13
12365- mov %r13, %r12
12366+ mov %r13, %r15
12367
12368 # Encrypt first few blocks
12369
12370- and $(3<<4), %r12
12371+ and $(3<<4), %r15
12372 jz _initial_num_blocks_is_0_encrypt
12373- cmp $(2<<4), %r12
12374+ cmp $(2<<4), %r15
12375 jb _initial_num_blocks_is_1_encrypt
12376 je _initial_num_blocks_is_2_encrypt
12377 _initial_num_blocks_is_3_encrypt:
12378@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12379 sub $16, %r11
12380 add %r13, %r11
12381 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12382- lea SHIFT_MASK+16(%rip), %r12
12383- sub %r13, %r12
12384+ lea SHIFT_MASK+16(%rip), %r15
12385+ sub %r13, %r15
12386 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12387 # (%r13 is the number of bytes in plaintext mod 16)
12388- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12389+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12390 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12391 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12392- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12393+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12394 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12395 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12396 movdqa SHUF_MASK(%rip), %xmm10
12397@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12398 sub $1, %r13
12399 jne _less_than_8_bytes_left_encrypt
12400 _multiple_of_16_bytes_encrypt:
12401- mov arg8, %r12 # %r12 = addLen (number of bytes)
12402- shl $3, %r12
12403- movd %r12d, %xmm15 # len(A) in %xmm15
12404+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12405+ shl $3, %r15
12406+ movd %r15d, %xmm15 # len(A) in %xmm15
12407 shl $3, %arg4 # len(C) in bits (*128)
12408 MOVQ_R64_XMM %arg4, %xmm1
12409 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12410@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12411 mov %r14, %rsp
12412 pop %r14
12413 pop %r13
12414- pop %r12
12415+ pop %r15
12416+ pax_force_retaddr
12417 ret
12418 ENDPROC(aesni_gcm_enc)
12419
12420@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12421 pxor %xmm1, %xmm0
12422 movaps %xmm0, (TKEYP)
12423 add $0x10, TKEYP
12424+ pax_force_retaddr
12425 ret
12426 ENDPROC(_key_expansion_128)
12427 ENDPROC(_key_expansion_256a)
12428@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12429 shufps $0b01001110, %xmm2, %xmm1
12430 movaps %xmm1, 0x10(TKEYP)
12431 add $0x20, TKEYP
12432+ pax_force_retaddr
12433 ret
12434 ENDPROC(_key_expansion_192a)
12435
12436@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12437
12438 movaps %xmm0, (TKEYP)
12439 add $0x10, TKEYP
12440+ pax_force_retaddr
12441 ret
12442 ENDPROC(_key_expansion_192b)
12443
12444@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12445 pxor %xmm1, %xmm2
12446 movaps %xmm2, (TKEYP)
12447 add $0x10, TKEYP
12448+ pax_force_retaddr
12449 ret
12450 ENDPROC(_key_expansion_256b)
12451
12452@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12453 #ifndef __x86_64__
12454 popl KEYP
12455 #endif
12456+ pax_force_retaddr
12457 ret
12458 ENDPROC(aesni_set_key)
12459
12460@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12461 popl KLEN
12462 popl KEYP
12463 #endif
12464+ pax_force_retaddr
12465 ret
12466 ENDPROC(aesni_enc)
12467
12468@@ -1974,6 +1983,7 @@ _aesni_enc1:
12469 AESENC KEY STATE
12470 movaps 0x70(TKEYP), KEY
12471 AESENCLAST KEY STATE
12472+ pax_force_retaddr
12473 ret
12474 ENDPROC(_aesni_enc1)
12475
12476@@ -2083,6 +2093,7 @@ _aesni_enc4:
12477 AESENCLAST KEY STATE2
12478 AESENCLAST KEY STATE3
12479 AESENCLAST KEY STATE4
12480+ pax_force_retaddr
12481 ret
12482 ENDPROC(_aesni_enc4)
12483
12484@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12485 popl KLEN
12486 popl KEYP
12487 #endif
12488+ pax_force_retaddr
12489 ret
12490 ENDPROC(aesni_dec)
12491
12492@@ -2164,6 +2176,7 @@ _aesni_dec1:
12493 AESDEC KEY STATE
12494 movaps 0x70(TKEYP), KEY
12495 AESDECLAST KEY STATE
12496+ pax_force_retaddr
12497 ret
12498 ENDPROC(_aesni_dec1)
12499
12500@@ -2273,6 +2286,7 @@ _aesni_dec4:
12501 AESDECLAST KEY STATE2
12502 AESDECLAST KEY STATE3
12503 AESDECLAST KEY STATE4
12504+ pax_force_retaddr
12505 ret
12506 ENDPROC(_aesni_dec4)
12507
12508@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12509 popl KEYP
12510 popl LEN
12511 #endif
12512+ pax_force_retaddr
12513 ret
12514 ENDPROC(aesni_ecb_enc)
12515
12516@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12517 popl KEYP
12518 popl LEN
12519 #endif
12520+ pax_force_retaddr
12521 ret
12522 ENDPROC(aesni_ecb_dec)
12523
12524@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12525 popl LEN
12526 popl IVP
12527 #endif
12528+ pax_force_retaddr
12529 ret
12530 ENDPROC(aesni_cbc_enc)
12531
12532@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12533 popl LEN
12534 popl IVP
12535 #endif
12536+ pax_force_retaddr
12537 ret
12538 ENDPROC(aesni_cbc_dec)
12539
12540@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12541 mov $1, TCTR_LOW
12542 MOVQ_R64_XMM TCTR_LOW INC
12543 MOVQ_R64_XMM CTR TCTR_LOW
12544+ pax_force_retaddr
12545 ret
12546 ENDPROC(_aesni_inc_init)
12547
12548@@ -2579,6 +2598,7 @@ _aesni_inc:
12549 .Linc_low:
12550 movaps CTR, IV
12551 PSHUFB_XMM BSWAP_MASK IV
12552+ pax_force_retaddr
12553 ret
12554 ENDPROC(_aesni_inc)
12555
12556@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12557 .Lctr_enc_ret:
12558 movups IV, (IVP)
12559 .Lctr_enc_just_ret:
12560+ pax_force_retaddr
12561 ret
12562 ENDPROC(aesni_ctr_enc)
12563
12564@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12565 pxor INC, STATE4
12566 movdqu STATE4, 0x70(OUTP)
12567
12568+ pax_force_retaddr
12569 ret
12570 ENDPROC(aesni_xts_crypt8)
12571
12572diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12573index 246c670..466e2d6 100644
12574--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12575+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12576@@ -21,6 +21,7 @@
12577 */
12578
12579 #include <linux/linkage.h>
12580+#include <asm/alternative-asm.h>
12581
12582 .file "blowfish-x86_64-asm.S"
12583 .text
12584@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12585 jnz .L__enc_xor;
12586
12587 write_block();
12588+ pax_force_retaddr
12589 ret;
12590 .L__enc_xor:
12591 xor_block();
12592+ pax_force_retaddr
12593 ret;
12594 ENDPROC(__blowfish_enc_blk)
12595
12596@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12597
12598 movq %r11, %rbp;
12599
12600+ pax_force_retaddr
12601 ret;
12602 ENDPROC(blowfish_dec_blk)
12603
12604@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12605
12606 popq %rbx;
12607 popq %rbp;
12608+ pax_force_retaddr
12609 ret;
12610
12611 .L__enc_xor4:
12612@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12613
12614 popq %rbx;
12615 popq %rbp;
12616+ pax_force_retaddr
12617 ret;
12618 ENDPROC(__blowfish_enc_blk_4way)
12619
12620@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12621 popq %rbx;
12622 popq %rbp;
12623
12624+ pax_force_retaddr
12625 ret;
12626 ENDPROC(blowfish_dec_blk_4way)
12627diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12628index ce71f92..1dce7ec 100644
12629--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12630+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12631@@ -16,6 +16,7 @@
12632 */
12633
12634 #include <linux/linkage.h>
12635+#include <asm/alternative-asm.h>
12636
12637 #define CAMELLIA_TABLE_BYTE_LEN 272
12638
12639@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12640 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12641 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12642 %rcx, (%r9));
12643+ pax_force_retaddr
12644 ret;
12645 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12646
12647@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12648 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12649 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12650 %rax, (%r9));
12651+ pax_force_retaddr
12652 ret;
12653 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12654
12655@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12656 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12657 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12658
12659+ pax_force_retaddr
12660 ret;
12661
12662 .align 8
12663@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12664 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12665 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12666
12667+ pax_force_retaddr
12668 ret;
12669
12670 .align 8
12671@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12672 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12673 %xmm8, %rsi);
12674
12675+ pax_force_retaddr
12676 ret;
12677 ENDPROC(camellia_ecb_enc_16way)
12678
12679@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12680 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12681 %xmm8, %rsi);
12682
12683+ pax_force_retaddr
12684 ret;
12685 ENDPROC(camellia_ecb_dec_16way)
12686
12687@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12688 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12689 %xmm8, %rsi);
12690
12691+ pax_force_retaddr
12692 ret;
12693 ENDPROC(camellia_cbc_dec_16way)
12694
12695@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12696 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12697 %xmm8, %rsi);
12698
12699+ pax_force_retaddr
12700 ret;
12701 ENDPROC(camellia_ctr_16way)
12702
12703@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12704 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12705 %xmm8, %rsi);
12706
12707+ pax_force_retaddr
12708 ret;
12709 ENDPROC(camellia_xts_crypt_16way)
12710
12711diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12712index 0e0b886..5a3123c 100644
12713--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12714+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12715@@ -11,6 +11,7 @@
12716 */
12717
12718 #include <linux/linkage.h>
12719+#include <asm/alternative-asm.h>
12720
12721 #define CAMELLIA_TABLE_BYTE_LEN 272
12722
12723@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12724 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12725 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12726 %rcx, (%r9));
12727+ pax_force_retaddr
12728 ret;
12729 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12730
12731@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12732 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12733 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12734 %rax, (%r9));
12735+ pax_force_retaddr
12736 ret;
12737 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12738
12739@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12740 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12741 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12742
12743+ pax_force_retaddr
12744 ret;
12745
12746 .align 8
12747@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12748 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12749 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12750
12751+ pax_force_retaddr
12752 ret;
12753
12754 .align 8
12755@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12756
12757 vzeroupper;
12758
12759+ pax_force_retaddr
12760 ret;
12761 ENDPROC(camellia_ecb_enc_32way)
12762
12763@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12764
12765 vzeroupper;
12766
12767+ pax_force_retaddr
12768 ret;
12769 ENDPROC(camellia_ecb_dec_32way)
12770
12771@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12772
12773 vzeroupper;
12774
12775+ pax_force_retaddr
12776 ret;
12777 ENDPROC(camellia_cbc_dec_32way)
12778
12779@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12780
12781 vzeroupper;
12782
12783+ pax_force_retaddr
12784 ret;
12785 ENDPROC(camellia_ctr_32way)
12786
12787@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12788
12789 vzeroupper;
12790
12791+ pax_force_retaddr
12792 ret;
12793 ENDPROC(camellia_xts_crypt_32way)
12794
12795diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12796index 310319c..db3d7b5 100644
12797--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12798+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12799@@ -21,6 +21,7 @@
12800 */
12801
12802 #include <linux/linkage.h>
12803+#include <asm/alternative-asm.h>
12804
12805 .file "camellia-x86_64-asm_64.S"
12806 .text
12807@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12808 enc_outunpack(mov, RT1);
12809
12810 movq RRBP, %rbp;
12811+ pax_force_retaddr
12812 ret;
12813
12814 .L__enc_xor:
12815 enc_outunpack(xor, RT1);
12816
12817 movq RRBP, %rbp;
12818+ pax_force_retaddr
12819 ret;
12820 ENDPROC(__camellia_enc_blk)
12821
12822@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12823 dec_outunpack();
12824
12825 movq RRBP, %rbp;
12826+ pax_force_retaddr
12827 ret;
12828 ENDPROC(camellia_dec_blk)
12829
12830@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12831
12832 movq RRBP, %rbp;
12833 popq %rbx;
12834+ pax_force_retaddr
12835 ret;
12836
12837 .L__enc2_xor:
12838@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12839
12840 movq RRBP, %rbp;
12841 popq %rbx;
12842+ pax_force_retaddr
12843 ret;
12844 ENDPROC(__camellia_enc_blk_2way)
12845
12846@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12847
12848 movq RRBP, %rbp;
12849 movq RXOR, %rbx;
12850+ pax_force_retaddr
12851 ret;
12852 ENDPROC(camellia_dec_blk_2way)
12853diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12854index c35fd5d..2d8c7db 100644
12855--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12856+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12857@@ -24,6 +24,7 @@
12858 */
12859
12860 #include <linux/linkage.h>
12861+#include <asm/alternative-asm.h>
12862
12863 .file "cast5-avx-x86_64-asm_64.S"
12864
12865@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12866 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12867 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12868
12869+ pax_force_retaddr
12870 ret;
12871 ENDPROC(__cast5_enc_blk16)
12872
12873@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12874 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12875 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12876
12877+ pax_force_retaddr
12878 ret;
12879
12880 .L__skip_dec:
12881@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12882 vmovdqu RR4, (6*4*4)(%r11);
12883 vmovdqu RL4, (7*4*4)(%r11);
12884
12885+ pax_force_retaddr
12886 ret;
12887 ENDPROC(cast5_ecb_enc_16way)
12888
12889@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12890 vmovdqu RR4, (6*4*4)(%r11);
12891 vmovdqu RL4, (7*4*4)(%r11);
12892
12893+ pax_force_retaddr
12894 ret;
12895 ENDPROC(cast5_ecb_dec_16way)
12896
12897@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
12898 * %rdx: src
12899 */
12900
12901- pushq %r12;
12902+ pushq %r14;
12903
12904 movq %rsi, %r11;
12905- movq %rdx, %r12;
12906+ movq %rdx, %r14;
12907
12908 vmovdqu (0*16)(%rdx), RL1;
12909 vmovdqu (1*16)(%rdx), RR1;
12910@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
12911 call __cast5_dec_blk16;
12912
12913 /* xor with src */
12914- vmovq (%r12), RX;
12915+ vmovq (%r14), RX;
12916 vpshufd $0x4f, RX, RX;
12917 vpxor RX, RR1, RR1;
12918- vpxor 0*16+8(%r12), RL1, RL1;
12919- vpxor 1*16+8(%r12), RR2, RR2;
12920- vpxor 2*16+8(%r12), RL2, RL2;
12921- vpxor 3*16+8(%r12), RR3, RR3;
12922- vpxor 4*16+8(%r12), RL3, RL3;
12923- vpxor 5*16+8(%r12), RR4, RR4;
12924- vpxor 6*16+8(%r12), RL4, RL4;
12925+ vpxor 0*16+8(%r14), RL1, RL1;
12926+ vpxor 1*16+8(%r14), RR2, RR2;
12927+ vpxor 2*16+8(%r14), RL2, RL2;
12928+ vpxor 3*16+8(%r14), RR3, RR3;
12929+ vpxor 4*16+8(%r14), RL3, RL3;
12930+ vpxor 5*16+8(%r14), RR4, RR4;
12931+ vpxor 6*16+8(%r14), RL4, RL4;
12932
12933 vmovdqu RR1, (0*16)(%r11);
12934 vmovdqu RL1, (1*16)(%r11);
12935@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
12936 vmovdqu RR4, (6*16)(%r11);
12937 vmovdqu RL4, (7*16)(%r11);
12938
12939- popq %r12;
12940+ popq %r14;
12941
12942+ pax_force_retaddr
12943 ret;
12944 ENDPROC(cast5_cbc_dec_16way)
12945
12946@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
12947 * %rcx: iv (big endian, 64bit)
12948 */
12949
12950- pushq %r12;
12951+ pushq %r14;
12952
12953 movq %rsi, %r11;
12954- movq %rdx, %r12;
12955+ movq %rdx, %r14;
12956
12957 vpcmpeqd RTMP, RTMP, RTMP;
12958 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
12959@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
12960 call __cast5_enc_blk16;
12961
12962 /* dst = src ^ iv */
12963- vpxor (0*16)(%r12), RR1, RR1;
12964- vpxor (1*16)(%r12), RL1, RL1;
12965- vpxor (2*16)(%r12), RR2, RR2;
12966- vpxor (3*16)(%r12), RL2, RL2;
12967- vpxor (4*16)(%r12), RR3, RR3;
12968- vpxor (5*16)(%r12), RL3, RL3;
12969- vpxor (6*16)(%r12), RR4, RR4;
12970- vpxor (7*16)(%r12), RL4, RL4;
12971+ vpxor (0*16)(%r14), RR1, RR1;
12972+ vpxor (1*16)(%r14), RL1, RL1;
12973+ vpxor (2*16)(%r14), RR2, RR2;
12974+ vpxor (3*16)(%r14), RL2, RL2;
12975+ vpxor (4*16)(%r14), RR3, RR3;
12976+ vpxor (5*16)(%r14), RL3, RL3;
12977+ vpxor (6*16)(%r14), RR4, RR4;
12978+ vpxor (7*16)(%r14), RL4, RL4;
12979 vmovdqu RR1, (0*16)(%r11);
12980 vmovdqu RL1, (1*16)(%r11);
12981 vmovdqu RR2, (2*16)(%r11);
12982@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
12983 vmovdqu RR4, (6*16)(%r11);
12984 vmovdqu RL4, (7*16)(%r11);
12985
12986- popq %r12;
12987+ popq %r14;
12988
12989+ pax_force_retaddr
12990 ret;
12991 ENDPROC(cast5_ctr_16way)
12992diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12993index e3531f8..e123f35 100644
12994--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12995+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12996@@ -24,6 +24,7 @@
12997 */
12998
12999 #include <linux/linkage.h>
13000+#include <asm/alternative-asm.h>
13001 #include "glue_helper-asm-avx.S"
13002
13003 .file "cast6-avx-x86_64-asm_64.S"
13004@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13005 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13006 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13007
13008+ pax_force_retaddr
13009 ret;
13010 ENDPROC(__cast6_enc_blk8)
13011
13012@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13013 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13014 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13015
13016+ pax_force_retaddr
13017 ret;
13018 ENDPROC(__cast6_dec_blk8)
13019
13020@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13021
13022 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13023
13024+ pax_force_retaddr
13025 ret;
13026 ENDPROC(cast6_ecb_enc_8way)
13027
13028@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13029
13030 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13031
13032+ pax_force_retaddr
13033 ret;
13034 ENDPROC(cast6_ecb_dec_8way)
13035
13036@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13037 * %rdx: src
13038 */
13039
13040- pushq %r12;
13041+ pushq %r14;
13042
13043 movq %rsi, %r11;
13044- movq %rdx, %r12;
13045+ movq %rdx, %r14;
13046
13047 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13048
13049 call __cast6_dec_blk8;
13050
13051- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13052+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13053
13054- popq %r12;
13055+ popq %r14;
13056
13057+ pax_force_retaddr
13058 ret;
13059 ENDPROC(cast6_cbc_dec_8way)
13060
13061@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13062 * %rcx: iv (little endian, 128bit)
13063 */
13064
13065- pushq %r12;
13066+ pushq %r14;
13067
13068 movq %rsi, %r11;
13069- movq %rdx, %r12;
13070+ movq %rdx, %r14;
13071
13072 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13073 RD2, RX, RKR, RKM);
13074
13075 call __cast6_enc_blk8;
13076
13077- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13078+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13079
13080- popq %r12;
13081+ popq %r14;
13082
13083+ pax_force_retaddr
13084 ret;
13085 ENDPROC(cast6_ctr_8way)
13086
13087@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13088 /* dst <= regs xor IVs(in dst) */
13089 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13090
13091+ pax_force_retaddr
13092 ret;
13093 ENDPROC(cast6_xts_enc_8way)
13094
13095@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13096 /* dst <= regs xor IVs(in dst) */
13097 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13098
13099+ pax_force_retaddr
13100 ret;
13101 ENDPROC(cast6_xts_dec_8way)
13102diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13103index dbc4339..de6e120 100644
13104--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13105+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13106@@ -45,6 +45,7 @@
13107
13108 #include <asm/inst.h>
13109 #include <linux/linkage.h>
13110+#include <asm/alternative-asm.h>
13111
13112 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13113
13114@@ -312,6 +313,7 @@ do_return:
13115 popq %rsi
13116 popq %rdi
13117 popq %rbx
13118+ pax_force_retaddr
13119 ret
13120
13121 ################################################################
13122diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13123index 586f41a..d02851e 100644
13124--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13125+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13126@@ -18,6 +18,7 @@
13127
13128 #include <linux/linkage.h>
13129 #include <asm/inst.h>
13130+#include <asm/alternative-asm.h>
13131
13132 .data
13133
13134@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13135 psrlq $1, T2
13136 pxor T2, T1
13137 pxor T1, DATA
13138+ pax_force_retaddr
13139 ret
13140 ENDPROC(__clmul_gf128mul_ble)
13141
13142@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13143 call __clmul_gf128mul_ble
13144 PSHUFB_XMM BSWAP DATA
13145 movups DATA, (%rdi)
13146+ pax_force_retaddr
13147 ret
13148 ENDPROC(clmul_ghash_mul)
13149
13150@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13151 PSHUFB_XMM BSWAP DATA
13152 movups DATA, (%rdi)
13153 .Lupdate_just_ret:
13154+ pax_force_retaddr
13155 ret
13156 ENDPROC(clmul_ghash_update)
13157
13158@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13159 pand .Lpoly, %xmm1
13160 pxor %xmm1, %xmm0
13161 movups %xmm0, (%rdi)
13162+ pax_force_retaddr
13163 ret
13164 ENDPROC(clmul_ghash_setkey)
13165diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13166index 9279e0b..c4b3d2c 100644
13167--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13168+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13169@@ -1,4 +1,5 @@
13170 #include <linux/linkage.h>
13171+#include <asm/alternative-asm.h>
13172
13173 # enter salsa20_encrypt_bytes
13174 ENTRY(salsa20_encrypt_bytes)
13175@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13176 add %r11,%rsp
13177 mov %rdi,%rax
13178 mov %rsi,%rdx
13179+ pax_force_retaddr
13180 ret
13181 # bytesatleast65:
13182 ._bytesatleast65:
13183@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13184 add %r11,%rsp
13185 mov %rdi,%rax
13186 mov %rsi,%rdx
13187+ pax_force_retaddr
13188 ret
13189 ENDPROC(salsa20_keysetup)
13190
13191@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13192 add %r11,%rsp
13193 mov %rdi,%rax
13194 mov %rsi,%rdx
13195+ pax_force_retaddr
13196 ret
13197 ENDPROC(salsa20_ivsetup)
13198diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13199index 2f202f4..d9164d6 100644
13200--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13201+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13202@@ -24,6 +24,7 @@
13203 */
13204
13205 #include <linux/linkage.h>
13206+#include <asm/alternative-asm.h>
13207 #include "glue_helper-asm-avx.S"
13208
13209 .file "serpent-avx-x86_64-asm_64.S"
13210@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13211 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13212 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13213
13214+ pax_force_retaddr
13215 ret;
13216 ENDPROC(__serpent_enc_blk8_avx)
13217
13218@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13219 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13220 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13221
13222+ pax_force_retaddr
13223 ret;
13224 ENDPROC(__serpent_dec_blk8_avx)
13225
13226@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13227
13228 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13229
13230+ pax_force_retaddr
13231 ret;
13232 ENDPROC(serpent_ecb_enc_8way_avx)
13233
13234@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13235
13236 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13237
13238+ pax_force_retaddr
13239 ret;
13240 ENDPROC(serpent_ecb_dec_8way_avx)
13241
13242@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13243
13244 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13245
13246+ pax_force_retaddr
13247 ret;
13248 ENDPROC(serpent_cbc_dec_8way_avx)
13249
13250@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13251
13252 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13253
13254+ pax_force_retaddr
13255 ret;
13256 ENDPROC(serpent_ctr_8way_avx)
13257
13258@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13259 /* dst <= regs xor IVs(in dst) */
13260 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13261
13262+ pax_force_retaddr
13263 ret;
13264 ENDPROC(serpent_xts_enc_8way_avx)
13265
13266@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13267 /* dst <= regs xor IVs(in dst) */
13268 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13269
13270+ pax_force_retaddr
13271 ret;
13272 ENDPROC(serpent_xts_dec_8way_avx)
13273diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13274index b222085..abd483c 100644
13275--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13276+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13277@@ -15,6 +15,7 @@
13278 */
13279
13280 #include <linux/linkage.h>
13281+#include <asm/alternative-asm.h>
13282 #include "glue_helper-asm-avx2.S"
13283
13284 .file "serpent-avx2-asm_64.S"
13285@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13286 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13287 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13288
13289+ pax_force_retaddr
13290 ret;
13291 ENDPROC(__serpent_enc_blk16)
13292
13293@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13294 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13295 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13296
13297+ pax_force_retaddr
13298 ret;
13299 ENDPROC(__serpent_dec_blk16)
13300
13301@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13302
13303 vzeroupper;
13304
13305+ pax_force_retaddr
13306 ret;
13307 ENDPROC(serpent_ecb_enc_16way)
13308
13309@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13310
13311 vzeroupper;
13312
13313+ pax_force_retaddr
13314 ret;
13315 ENDPROC(serpent_ecb_dec_16way)
13316
13317@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13318
13319 vzeroupper;
13320
13321+ pax_force_retaddr
13322 ret;
13323 ENDPROC(serpent_cbc_dec_16way)
13324
13325@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13326
13327 vzeroupper;
13328
13329+ pax_force_retaddr
13330 ret;
13331 ENDPROC(serpent_ctr_16way)
13332
13333@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13334
13335 vzeroupper;
13336
13337+ pax_force_retaddr
13338 ret;
13339 ENDPROC(serpent_xts_enc_16way)
13340
13341@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13342
13343 vzeroupper;
13344
13345+ pax_force_retaddr
13346 ret;
13347 ENDPROC(serpent_xts_dec_16way)
13348diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13349index acc066c..1559cc4 100644
13350--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13351+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13352@@ -25,6 +25,7 @@
13353 */
13354
13355 #include <linux/linkage.h>
13356+#include <asm/alternative-asm.h>
13357
13358 .file "serpent-sse2-x86_64-asm_64.S"
13359 .text
13360@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13361 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13362 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13363
13364+ pax_force_retaddr
13365 ret;
13366
13367 .L__enc_xor8:
13368 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13369 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13370
13371+ pax_force_retaddr
13372 ret;
13373 ENDPROC(__serpent_enc_blk_8way)
13374
13375@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13376 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13377 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13378
13379+ pax_force_retaddr
13380 ret;
13381 ENDPROC(serpent_dec_blk_8way)
13382diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13383index a410950..9dfe7ad 100644
13384--- a/arch/x86/crypto/sha1_ssse3_asm.S
13385+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13386@@ -29,6 +29,7 @@
13387 */
13388
13389 #include <linux/linkage.h>
13390+#include <asm/alternative-asm.h>
13391
13392 #define CTX %rdi // arg1
13393 #define BUF %rsi // arg2
13394@@ -75,9 +76,9 @@
13395
13396 push %rbx
13397 push %rbp
13398- push %r12
13399+ push %r14
13400
13401- mov %rsp, %r12
13402+ mov %rsp, %r14
13403 sub $64, %rsp # allocate workspace
13404 and $~15, %rsp # align stack
13405
13406@@ -99,11 +100,12 @@
13407 xor %rax, %rax
13408 rep stosq
13409
13410- mov %r12, %rsp # deallocate workspace
13411+ mov %r14, %rsp # deallocate workspace
13412
13413- pop %r12
13414+ pop %r14
13415 pop %rbp
13416 pop %rbx
13417+ pax_force_retaddr
13418 ret
13419
13420 ENDPROC(\name)
13421diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13422index 642f156..51a513c 100644
13423--- a/arch/x86/crypto/sha256-avx-asm.S
13424+++ b/arch/x86/crypto/sha256-avx-asm.S
13425@@ -49,6 +49,7 @@
13426
13427 #ifdef CONFIG_AS_AVX
13428 #include <linux/linkage.h>
13429+#include <asm/alternative-asm.h>
13430
13431 ## assume buffers not aligned
13432 #define VMOVDQ vmovdqu
13433@@ -460,6 +461,7 @@ done_hash:
13434 popq %r13
13435 popq %rbp
13436 popq %rbx
13437+ pax_force_retaddr
13438 ret
13439 ENDPROC(sha256_transform_avx)
13440
13441diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13442index 9e86944..3795e6a 100644
13443--- a/arch/x86/crypto/sha256-avx2-asm.S
13444+++ b/arch/x86/crypto/sha256-avx2-asm.S
13445@@ -50,6 +50,7 @@
13446
13447 #ifdef CONFIG_AS_AVX2
13448 #include <linux/linkage.h>
13449+#include <asm/alternative-asm.h>
13450
13451 ## assume buffers not aligned
13452 #define VMOVDQ vmovdqu
13453@@ -720,6 +721,7 @@ done_hash:
13454 popq %r12
13455 popq %rbp
13456 popq %rbx
13457+ pax_force_retaddr
13458 ret
13459 ENDPROC(sha256_transform_rorx)
13460
13461diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13462index f833b74..8c62a9e 100644
13463--- a/arch/x86/crypto/sha256-ssse3-asm.S
13464+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13465@@ -47,6 +47,7 @@
13466 ########################################################################
13467
13468 #include <linux/linkage.h>
13469+#include <asm/alternative-asm.h>
13470
13471 ## assume buffers not aligned
13472 #define MOVDQ movdqu
13473@@ -471,6 +472,7 @@ done_hash:
13474 popq %rbp
13475 popq %rbx
13476
13477+ pax_force_retaddr
13478 ret
13479 ENDPROC(sha256_transform_ssse3)
13480
13481diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13482index 974dde9..a823ff9 100644
13483--- a/arch/x86/crypto/sha512-avx-asm.S
13484+++ b/arch/x86/crypto/sha512-avx-asm.S
13485@@ -49,6 +49,7 @@
13486
13487 #ifdef CONFIG_AS_AVX
13488 #include <linux/linkage.h>
13489+#include <asm/alternative-asm.h>
13490
13491 .text
13492
13493@@ -364,6 +365,7 @@ updateblock:
13494 mov frame_RSPSAVE(%rsp), %rsp
13495
13496 nowork:
13497+ pax_force_retaddr
13498 ret
13499 ENDPROC(sha512_transform_avx)
13500
13501diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13502index 568b961..ed20c37 100644
13503--- a/arch/x86/crypto/sha512-avx2-asm.S
13504+++ b/arch/x86/crypto/sha512-avx2-asm.S
13505@@ -51,6 +51,7 @@
13506
13507 #ifdef CONFIG_AS_AVX2
13508 #include <linux/linkage.h>
13509+#include <asm/alternative-asm.h>
13510
13511 .text
13512
13513@@ -678,6 +679,7 @@ done_hash:
13514
13515 # Restore Stack Pointer
13516 mov frame_RSPSAVE(%rsp), %rsp
13517+ pax_force_retaddr
13518 ret
13519 ENDPROC(sha512_transform_rorx)
13520
13521diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13522index fb56855..6edd768 100644
13523--- a/arch/x86/crypto/sha512-ssse3-asm.S
13524+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13525@@ -48,6 +48,7 @@
13526 ########################################################################
13527
13528 #include <linux/linkage.h>
13529+#include <asm/alternative-asm.h>
13530
13531 .text
13532
13533@@ -363,6 +364,7 @@ updateblock:
13534 mov frame_RSPSAVE(%rsp), %rsp
13535
13536 nowork:
13537+ pax_force_retaddr
13538 ret
13539 ENDPROC(sha512_transform_ssse3)
13540
13541diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13542index 0505813..b067311 100644
13543--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13544+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13545@@ -24,6 +24,7 @@
13546 */
13547
13548 #include <linux/linkage.h>
13549+#include <asm/alternative-asm.h>
13550 #include "glue_helper-asm-avx.S"
13551
13552 .file "twofish-avx-x86_64-asm_64.S"
13553@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13554 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13555 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13556
13557+ pax_force_retaddr
13558 ret;
13559 ENDPROC(__twofish_enc_blk8)
13560
13561@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13562 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13563 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13564
13565+ pax_force_retaddr
13566 ret;
13567 ENDPROC(__twofish_dec_blk8)
13568
13569@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13570
13571 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13572
13573+ pax_force_retaddr
13574 ret;
13575 ENDPROC(twofish_ecb_enc_8way)
13576
13577@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13578
13579 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13580
13581+ pax_force_retaddr
13582 ret;
13583 ENDPROC(twofish_ecb_dec_8way)
13584
13585@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
13586 * %rdx: src
13587 */
13588
13589- pushq %r12;
13590+ pushq %r14;
13591
13592 movq %rsi, %r11;
13593- movq %rdx, %r12;
13594+ movq %rdx, %r14;
13595
13596 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13597
13598 call __twofish_dec_blk8;
13599
13600- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13601+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13602
13603- popq %r12;
13604+ popq %r14;
13605
13606+ pax_force_retaddr
13607 ret;
13608 ENDPROC(twofish_cbc_dec_8way)
13609
13610@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
13611 * %rcx: iv (little endian, 128bit)
13612 */
13613
13614- pushq %r12;
13615+ pushq %r14;
13616
13617 movq %rsi, %r11;
13618- movq %rdx, %r12;
13619+ movq %rdx, %r14;
13620
13621 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13622 RD2, RX0, RX1, RY0);
13623
13624 call __twofish_enc_blk8;
13625
13626- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13627+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13628
13629- popq %r12;
13630+ popq %r14;
13631
13632+ pax_force_retaddr
13633 ret;
13634 ENDPROC(twofish_ctr_8way)
13635
13636@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13637 /* dst <= regs xor IVs(in dst) */
13638 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13639
13640+ pax_force_retaddr
13641 ret;
13642 ENDPROC(twofish_xts_enc_8way)
13643
13644@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13645 /* dst <= regs xor IVs(in dst) */
13646 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13647
13648+ pax_force_retaddr
13649 ret;
13650 ENDPROC(twofish_xts_dec_8way)
13651diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13652index 1c3b7ce..02f578d 100644
13653--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13654+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13655@@ -21,6 +21,7 @@
13656 */
13657
13658 #include <linux/linkage.h>
13659+#include <asm/alternative-asm.h>
13660
13661 .file "twofish-x86_64-asm-3way.S"
13662 .text
13663@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13664 popq %r13;
13665 popq %r14;
13666 popq %r15;
13667+ pax_force_retaddr
13668 ret;
13669
13670 .L__enc_xor3:
13671@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13672 popq %r13;
13673 popq %r14;
13674 popq %r15;
13675+ pax_force_retaddr
13676 ret;
13677 ENDPROC(__twofish_enc_blk_3way)
13678
13679@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13680 popq %r13;
13681 popq %r14;
13682 popq %r15;
13683+ pax_force_retaddr
13684 ret;
13685 ENDPROC(twofish_dec_blk_3way)
13686diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13687index a039d21..524b8b2 100644
13688--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13689+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13690@@ -22,6 +22,7 @@
13691
13692 #include <linux/linkage.h>
13693 #include <asm/asm-offsets.h>
13694+#include <asm/alternative-asm.h>
13695
13696 #define a_offset 0
13697 #define b_offset 4
13698@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13699
13700 popq R1
13701 movq $1,%rax
13702+ pax_force_retaddr
13703 ret
13704 ENDPROC(twofish_enc_blk)
13705
13706@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13707
13708 popq R1
13709 movq $1,%rax
13710+ pax_force_retaddr
13711 ret
13712 ENDPROC(twofish_dec_blk)
13713diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13714index d21ff89..6da8e6e 100644
13715--- a/arch/x86/ia32/ia32_aout.c
13716+++ b/arch/x86/ia32/ia32_aout.c
13717@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
13718 unsigned long dump_start, dump_size;
13719 struct user32 dump;
13720
13721+ memset(&dump, 0, sizeof(dump));
13722+
13723 fs = get_fs();
13724 set_fs(KERNEL_DS);
13725 has_dumped = 1;
13726diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13727index 2206757..85cbcfa 100644
13728--- a/arch/x86/ia32/ia32_signal.c
13729+++ b/arch/x86/ia32/ia32_signal.c
13730@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
13731 if (__get_user(set.sig[0], &frame->sc.oldmask)
13732 || (_COMPAT_NSIG_WORDS > 1
13733 && __copy_from_user((((char *) &set.sig) + 4),
13734- &frame->extramask,
13735+ frame->extramask,
13736 sizeof(frame->extramask))))
13737 goto badframe;
13738
13739@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13740 sp -= frame_size;
13741 /* Align the stack pointer according to the i386 ABI,
13742 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13743- sp = ((sp + 4) & -16ul) - 4;
13744+ sp = ((sp - 12) & -16ul) - 4;
13745 return (void __user *) sp;
13746 }
13747
13748@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13749 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13750 sigreturn);
13751 else
13752- restorer = &frame->retcode;
13753+ restorer = frame->retcode;
13754 }
13755
13756 put_user_try {
13757@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13758 * These are actually not used anymore, but left because some
13759 * gdb versions depend on them as a marker.
13760 */
13761- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13762+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13763 } put_user_catch(err);
13764
13765 if (err)
13766@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13767 0xb8,
13768 __NR_ia32_rt_sigreturn,
13769 0x80cd,
13770- 0,
13771+ 0
13772 };
13773
13774 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13775@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13776
13777 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13778 restorer = ksig->ka.sa.sa_restorer;
13779+ else if (current->mm->context.vdso)
13780+ /* Return stub is in 32bit vsyscall page */
13781+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13782 else
13783- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13784- rt_sigreturn);
13785+ restorer = frame->retcode;
13786 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13787
13788 /*
13789 * Not actually used anymore, but left because some gdb
13790 * versions need it.
13791 */
13792- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13793+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13794 } put_user_catch(err);
13795
13796 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13797diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13798index 4299eb0..c0687a7 100644
13799--- a/arch/x86/ia32/ia32entry.S
13800+++ b/arch/x86/ia32/ia32entry.S
13801@@ -15,8 +15,10 @@
13802 #include <asm/irqflags.h>
13803 #include <asm/asm.h>
13804 #include <asm/smap.h>
13805+#include <asm/pgtable.h>
13806 #include <linux/linkage.h>
13807 #include <linux/err.h>
13808+#include <asm/alternative-asm.h>
13809
13810 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13811 #include <linux/elf-em.h>
13812@@ -62,12 +64,12 @@
13813 */
13814 .macro LOAD_ARGS32 offset, _r9=0
13815 .if \_r9
13816- movl \offset+16(%rsp),%r9d
13817+ movl \offset+R9(%rsp),%r9d
13818 .endif
13819- movl \offset+40(%rsp),%ecx
13820- movl \offset+48(%rsp),%edx
13821- movl \offset+56(%rsp),%esi
13822- movl \offset+64(%rsp),%edi
13823+ movl \offset+RCX(%rsp),%ecx
13824+ movl \offset+RDX(%rsp),%edx
13825+ movl \offset+RSI(%rsp),%esi
13826+ movl \offset+RDI(%rsp),%edi
13827 movl %eax,%eax /* zero extension */
13828 .endm
13829
13830@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13831 ENDPROC(native_irq_enable_sysexit)
13832 #endif
13833
13834+ .macro pax_enter_kernel_user
13835+ pax_set_fptr_mask
13836+#ifdef CONFIG_PAX_MEMORY_UDEREF
13837+ call pax_enter_kernel_user
13838+#endif
13839+ .endm
13840+
13841+ .macro pax_exit_kernel_user
13842+#ifdef CONFIG_PAX_MEMORY_UDEREF
13843+ call pax_exit_kernel_user
13844+#endif
13845+#ifdef CONFIG_PAX_RANDKSTACK
13846+ pushq %rax
13847+ pushq %r11
13848+ call pax_randomize_kstack
13849+ popq %r11
13850+ popq %rax
13851+#endif
13852+ .endm
13853+
13854+ .macro pax_erase_kstack
13855+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13856+ call pax_erase_kstack
13857+#endif
13858+ .endm
13859+
13860 /*
13861 * 32bit SYSENTER instruction entry.
13862 *
13863@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13864 CFI_REGISTER rsp,rbp
13865 SWAPGS_UNSAFE_STACK
13866 movq PER_CPU_VAR(kernel_stack), %rsp
13867- addq $(KERNEL_STACK_OFFSET),%rsp
13868- /*
13869- * No need to follow this irqs on/off section: the syscall
13870- * disabled irqs, here we enable it straight after entry:
13871- */
13872- ENABLE_INTERRUPTS(CLBR_NONE)
13873 movl %ebp,%ebp /* zero extension */
13874 pushq_cfi $__USER32_DS
13875 /*CFI_REL_OFFSET ss,0*/
13876@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13877 CFI_REL_OFFSET rsp,0
13878 pushfq_cfi
13879 /*CFI_REL_OFFSET rflags,0*/
13880- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13881- CFI_REGISTER rip,r10
13882+ orl $X86_EFLAGS_IF,(%rsp)
13883+ GET_THREAD_INFO(%r11)
13884+ movl TI_sysenter_return(%r11), %r11d
13885+ CFI_REGISTER rip,r11
13886 pushq_cfi $__USER32_CS
13887 /*CFI_REL_OFFSET cs,0*/
13888 movl %eax, %eax
13889- pushq_cfi %r10
13890+ pushq_cfi %r11
13891 CFI_REL_OFFSET rip,0
13892 pushq_cfi %rax
13893 cld
13894 SAVE_ARGS 0,1,0
13895+ pax_enter_kernel_user
13896+
13897+#ifdef CONFIG_PAX_RANDKSTACK
13898+ pax_erase_kstack
13899+#endif
13900+
13901+ /*
13902+ * No need to follow this irqs on/off section: the syscall
13903+ * disabled irqs, here we enable it straight after entry:
13904+ */
13905+ ENABLE_INTERRUPTS(CLBR_NONE)
13906 /* no need to do an access_ok check here because rbp has been
13907 32bit zero extended */
13908+
13909+#ifdef CONFIG_PAX_MEMORY_UDEREF
13910+ addq pax_user_shadow_base,%rbp
13911+ ASM_PAX_OPEN_USERLAND
13912+#endif
13913+
13914 ASM_STAC
13915 1: movl (%rbp),%ebp
13916 _ASM_EXTABLE(1b,ia32_badarg)
13917 ASM_CLAC
13918- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13919- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13920+
13921+#ifdef CONFIG_PAX_MEMORY_UDEREF
13922+ ASM_PAX_CLOSE_USERLAND
13923+#endif
13924+
13925+ GET_THREAD_INFO(%r11)
13926+ orl $TS_COMPAT,TI_status(%r11)
13927+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13928 CFI_REMEMBER_STATE
13929 jnz sysenter_tracesys
13930 cmpq $(IA32_NR_syscalls-1),%rax
13931@@ -162,15 +209,18 @@ sysenter_do_call:
13932 sysenter_dispatch:
13933 call *ia32_sys_call_table(,%rax,8)
13934 movq %rax,RAX-ARGOFFSET(%rsp)
13935+ GET_THREAD_INFO(%r11)
13936 DISABLE_INTERRUPTS(CLBR_NONE)
13937 TRACE_IRQS_OFF
13938- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13939+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13940 jnz sysexit_audit
13941 sysexit_from_sys_call:
13942- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13943+ pax_exit_kernel_user
13944+ pax_erase_kstack
13945+ andl $~TS_COMPAT,TI_status(%r11)
13946 /* clear IF, that popfq doesn't enable interrupts early */
13947- andl $~0x200,EFLAGS-R11(%rsp)
13948- movl RIP-R11(%rsp),%edx /* User %eip */
13949+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
13950+ movl RIP(%rsp),%edx /* User %eip */
13951 CFI_REGISTER rip,rdx
13952 RESTORE_ARGS 0,24,0,0,0,0
13953 xorq %r8,%r8
13954@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13955 movl %eax,%esi /* 2nd arg: syscall number */
13956 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13957 call __audit_syscall_entry
13958+
13959+ pax_erase_kstack
13960+
13961 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13962 cmpq $(IA32_NR_syscalls-1),%rax
13963 ja ia32_badsys
13964@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13965 .endm
13966
13967 .macro auditsys_exit exit
13968- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13969+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13970 jnz ia32_ret_from_sys_call
13971 TRACE_IRQS_ON
13972 ENABLE_INTERRUPTS(CLBR_NONE)
13973@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13974 1: setbe %al /* 1 if error, 0 if not */
13975 movzbl %al,%edi /* zero-extend that into %edi */
13976 call __audit_syscall_exit
13977+ GET_THREAD_INFO(%r11)
13978 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13979 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13980 DISABLE_INTERRUPTS(CLBR_NONE)
13981 TRACE_IRQS_OFF
13982- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13983+ testl %edi,TI_flags(%r11)
13984 jz \exit
13985 CLEAR_RREGS -ARGOFFSET
13986 jmp int_with_check
13987@@ -237,7 +291,7 @@ sysexit_audit:
13988
13989 sysenter_tracesys:
13990 #ifdef CONFIG_AUDITSYSCALL
13991- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13992+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13993 jz sysenter_auditsys
13994 #endif
13995 SAVE_REST
13996@@ -249,6 +303,9 @@ sysenter_tracesys:
13997 RESTORE_REST
13998 cmpq $(IA32_NR_syscalls-1),%rax
13999 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14000+
14001+ pax_erase_kstack
14002+
14003 jmp sysenter_do_call
14004 CFI_ENDPROC
14005 ENDPROC(ia32_sysenter_target)
14006@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14007 ENTRY(ia32_cstar_target)
14008 CFI_STARTPROC32 simple
14009 CFI_SIGNAL_FRAME
14010- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14011+ CFI_DEF_CFA rsp,0
14012 CFI_REGISTER rip,rcx
14013 /*CFI_REGISTER rflags,r11*/
14014 SWAPGS_UNSAFE_STACK
14015 movl %esp,%r8d
14016 CFI_REGISTER rsp,r8
14017 movq PER_CPU_VAR(kernel_stack),%rsp
14018+ SAVE_ARGS 8*6,0,0
14019+ pax_enter_kernel_user
14020+
14021+#ifdef CONFIG_PAX_RANDKSTACK
14022+ pax_erase_kstack
14023+#endif
14024+
14025 /*
14026 * No need to follow this irqs on/off section: the syscall
14027 * disabled irqs and here we enable it straight after entry:
14028 */
14029 ENABLE_INTERRUPTS(CLBR_NONE)
14030- SAVE_ARGS 8,0,0
14031 movl %eax,%eax /* zero extension */
14032 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14033 movq %rcx,RIP-ARGOFFSET(%rsp)
14034@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14035 /* no need to do an access_ok check here because r8 has been
14036 32bit zero extended */
14037 /* hardware stack frame is complete now */
14038+
14039+#ifdef CONFIG_PAX_MEMORY_UDEREF
14040+ ASM_PAX_OPEN_USERLAND
14041+ movq pax_user_shadow_base,%r8
14042+ addq RSP-ARGOFFSET(%rsp),%r8
14043+#endif
14044+
14045 ASM_STAC
14046 1: movl (%r8),%r9d
14047 _ASM_EXTABLE(1b,ia32_badarg)
14048 ASM_CLAC
14049- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14050- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14051+
14052+#ifdef CONFIG_PAX_MEMORY_UDEREF
14053+ ASM_PAX_CLOSE_USERLAND
14054+#endif
14055+
14056+ GET_THREAD_INFO(%r11)
14057+ orl $TS_COMPAT,TI_status(%r11)
14058+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14059 CFI_REMEMBER_STATE
14060 jnz cstar_tracesys
14061 cmpq $IA32_NR_syscalls-1,%rax
14062@@ -319,13 +395,16 @@ cstar_do_call:
14063 cstar_dispatch:
14064 call *ia32_sys_call_table(,%rax,8)
14065 movq %rax,RAX-ARGOFFSET(%rsp)
14066+ GET_THREAD_INFO(%r11)
14067 DISABLE_INTERRUPTS(CLBR_NONE)
14068 TRACE_IRQS_OFF
14069- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14070+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14071 jnz sysretl_audit
14072 sysretl_from_sys_call:
14073- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14074- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14075+ pax_exit_kernel_user
14076+ pax_erase_kstack
14077+ andl $~TS_COMPAT,TI_status(%r11)
14078+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14079 movl RIP-ARGOFFSET(%rsp),%ecx
14080 CFI_REGISTER rip,rcx
14081 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14082@@ -352,7 +431,7 @@ sysretl_audit:
14083
14084 cstar_tracesys:
14085 #ifdef CONFIG_AUDITSYSCALL
14086- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14087+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14088 jz cstar_auditsys
14089 #endif
14090 xchgl %r9d,%ebp
14091@@ -366,11 +445,19 @@ cstar_tracesys:
14092 xchgl %ebp,%r9d
14093 cmpq $(IA32_NR_syscalls-1),%rax
14094 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14095+
14096+ pax_erase_kstack
14097+
14098 jmp cstar_do_call
14099 END(ia32_cstar_target)
14100
14101 ia32_badarg:
14102 ASM_CLAC
14103+
14104+#ifdef CONFIG_PAX_MEMORY_UDEREF
14105+ ASM_PAX_CLOSE_USERLAND
14106+#endif
14107+
14108 movq $-EFAULT,%rax
14109 jmp ia32_sysret
14110 CFI_ENDPROC
14111@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14112 CFI_REL_OFFSET rip,RIP-RIP
14113 PARAVIRT_ADJUST_EXCEPTION_FRAME
14114 SWAPGS
14115- /*
14116- * No need to follow this irqs on/off section: the syscall
14117- * disabled irqs and here we enable it straight after entry:
14118- */
14119- ENABLE_INTERRUPTS(CLBR_NONE)
14120 movl %eax,%eax
14121 pushq_cfi %rax
14122 cld
14123 /* note the registers are not zero extended to the sf.
14124 this could be a problem. */
14125 SAVE_ARGS 0,1,0
14126- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14127- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14128+ pax_enter_kernel_user
14129+
14130+#ifdef CONFIG_PAX_RANDKSTACK
14131+ pax_erase_kstack
14132+#endif
14133+
14134+ /*
14135+ * No need to follow this irqs on/off section: the syscall
14136+ * disabled irqs and here we enable it straight after entry:
14137+ */
14138+ ENABLE_INTERRUPTS(CLBR_NONE)
14139+ GET_THREAD_INFO(%r11)
14140+ orl $TS_COMPAT,TI_status(%r11)
14141+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14142 jnz ia32_tracesys
14143 cmpq $(IA32_NR_syscalls-1),%rax
14144 ja ia32_badsys
14145@@ -442,6 +536,9 @@ ia32_tracesys:
14146 RESTORE_REST
14147 cmpq $(IA32_NR_syscalls-1),%rax
14148 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14149+
14150+ pax_erase_kstack
14151+
14152 jmp ia32_do_call
14153 END(ia32_syscall)
14154
14155diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14156index 8e0ceec..af13504 100644
14157--- a/arch/x86/ia32/sys_ia32.c
14158+++ b/arch/x86/ia32/sys_ia32.c
14159@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14160 */
14161 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14162 {
14163- typeof(ubuf->st_uid) uid = 0;
14164- typeof(ubuf->st_gid) gid = 0;
14165+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14166+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14167 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14168 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14169 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14170diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14171index 372231c..51b537d 100644
14172--- a/arch/x86/include/asm/alternative-asm.h
14173+++ b/arch/x86/include/asm/alternative-asm.h
14174@@ -18,6 +18,45 @@
14175 .endm
14176 #endif
14177
14178+#ifdef KERNEXEC_PLUGIN
14179+ .macro pax_force_retaddr_bts rip=0
14180+ btsq $63,\rip(%rsp)
14181+ .endm
14182+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14183+ .macro pax_force_retaddr rip=0, reload=0
14184+ btsq $63,\rip(%rsp)
14185+ .endm
14186+ .macro pax_force_fptr ptr
14187+ btsq $63,\ptr
14188+ .endm
14189+ .macro pax_set_fptr_mask
14190+ .endm
14191+#endif
14192+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14193+ .macro pax_force_retaddr rip=0, reload=0
14194+ .if \reload
14195+ pax_set_fptr_mask
14196+ .endif
14197+ orq %r12,\rip(%rsp)
14198+ .endm
14199+ .macro pax_force_fptr ptr
14200+ orq %r12,\ptr
14201+ .endm
14202+ .macro pax_set_fptr_mask
14203+ movabs $0x8000000000000000,%r12
14204+ .endm
14205+#endif
14206+#else
14207+ .macro pax_force_retaddr rip=0, reload=0
14208+ .endm
14209+ .macro pax_force_fptr ptr
14210+ .endm
14211+ .macro pax_force_retaddr_bts rip=0
14212+ .endm
14213+ .macro pax_set_fptr_mask
14214+ .endm
14215+#endif
14216+
14217 .macro altinstruction_entry orig alt feature orig_len alt_len
14218 .long \orig - .
14219 .long \alt - .
14220diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14221index 0a3f9c9..c9d081d 100644
14222--- a/arch/x86/include/asm/alternative.h
14223+++ b/arch/x86/include/asm/alternative.h
14224@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14225 ".pushsection .discard,\"aw\",@progbits\n" \
14226 DISCARD_ENTRY(1) \
14227 ".popsection\n" \
14228- ".pushsection .altinstr_replacement, \"ax\"\n" \
14229+ ".pushsection .altinstr_replacement, \"a\"\n" \
14230 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14231 ".popsection"
14232
14233@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14234 DISCARD_ENTRY(1) \
14235 DISCARD_ENTRY(2) \
14236 ".popsection\n" \
14237- ".pushsection .altinstr_replacement, \"ax\"\n" \
14238+ ".pushsection .altinstr_replacement, \"a\"\n" \
14239 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14240 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14241 ".popsection"
14242diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14243index 1d2091a..f5074c1 100644
14244--- a/arch/x86/include/asm/apic.h
14245+++ b/arch/x86/include/asm/apic.h
14246@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14247
14248 #ifdef CONFIG_X86_LOCAL_APIC
14249
14250-extern unsigned int apic_verbosity;
14251+extern int apic_verbosity;
14252 extern int local_apic_timer_c2_ok;
14253
14254 extern int disable_apic;
14255diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14256index 20370c6..a2eb9b0 100644
14257--- a/arch/x86/include/asm/apm.h
14258+++ b/arch/x86/include/asm/apm.h
14259@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14260 __asm__ __volatile__(APM_DO_ZERO_SEGS
14261 "pushl %%edi\n\t"
14262 "pushl %%ebp\n\t"
14263- "lcall *%%cs:apm_bios_entry\n\t"
14264+ "lcall *%%ss:apm_bios_entry\n\t"
14265 "setc %%al\n\t"
14266 "popl %%ebp\n\t"
14267 "popl %%edi\n\t"
14268@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14269 __asm__ __volatile__(APM_DO_ZERO_SEGS
14270 "pushl %%edi\n\t"
14271 "pushl %%ebp\n\t"
14272- "lcall *%%cs:apm_bios_entry\n\t"
14273+ "lcall *%%ss:apm_bios_entry\n\t"
14274 "setc %%bl\n\t"
14275 "popl %%ebp\n\t"
14276 "popl %%edi\n\t"
14277diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14278index b17f4f4..9620151 100644
14279--- a/arch/x86/include/asm/atomic.h
14280+++ b/arch/x86/include/asm/atomic.h
14281@@ -23,7 +23,18 @@
14282 */
14283 static inline int atomic_read(const atomic_t *v)
14284 {
14285- return (*(volatile int *)&(v)->counter);
14286+ return (*(volatile const int *)&(v)->counter);
14287+}
14288+
14289+/**
14290+ * atomic_read_unchecked - read atomic variable
14291+ * @v: pointer of type atomic_unchecked_t
14292+ *
14293+ * Atomically reads the value of @v.
14294+ */
14295+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14296+{
14297+ return (*(volatile const int *)&(v)->counter);
14298 }
14299
14300 /**
14301@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14302 }
14303
14304 /**
14305+ * atomic_set_unchecked - set atomic variable
14306+ * @v: pointer of type atomic_unchecked_t
14307+ * @i: required value
14308+ *
14309+ * Atomically sets the value of @v to @i.
14310+ */
14311+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14312+{
14313+ v->counter = i;
14314+}
14315+
14316+/**
14317 * atomic_add - add integer to atomic variable
14318 * @i: integer value to add
14319 * @v: pointer of type atomic_t
14320@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14321 */
14322 static inline void atomic_add(int i, atomic_t *v)
14323 {
14324- asm volatile(LOCK_PREFIX "addl %1,%0"
14325+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14326+
14327+#ifdef CONFIG_PAX_REFCOUNT
14328+ "jno 0f\n"
14329+ LOCK_PREFIX "subl %1,%0\n"
14330+ "int $4\n0:\n"
14331+ _ASM_EXTABLE(0b, 0b)
14332+#endif
14333+
14334+ : "+m" (v->counter)
14335+ : "ir" (i));
14336+}
14337+
14338+/**
14339+ * atomic_add_unchecked - add integer to atomic variable
14340+ * @i: integer value to add
14341+ * @v: pointer of type atomic_unchecked_t
14342+ *
14343+ * Atomically adds @i to @v.
14344+ */
14345+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14346+{
14347+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14348 : "+m" (v->counter)
14349 : "ir" (i));
14350 }
14351@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14352 */
14353 static inline void atomic_sub(int i, atomic_t *v)
14354 {
14355- asm volatile(LOCK_PREFIX "subl %1,%0"
14356+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14357+
14358+#ifdef CONFIG_PAX_REFCOUNT
14359+ "jno 0f\n"
14360+ LOCK_PREFIX "addl %1,%0\n"
14361+ "int $4\n0:\n"
14362+ _ASM_EXTABLE(0b, 0b)
14363+#endif
14364+
14365+ : "+m" (v->counter)
14366+ : "ir" (i));
14367+}
14368+
14369+/**
14370+ * atomic_sub_unchecked - subtract integer from atomic variable
14371+ * @i: integer value to subtract
14372+ * @v: pointer of type atomic_unchecked_t
14373+ *
14374+ * Atomically subtracts @i from @v.
14375+ */
14376+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14377+{
14378+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14379 : "+m" (v->counter)
14380 : "ir" (i));
14381 }
14382@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14383 */
14384 static inline int atomic_sub_and_test(int i, atomic_t *v)
14385 {
14386- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14387+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14388 }
14389
14390 /**
14391@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14392 */
14393 static inline void atomic_inc(atomic_t *v)
14394 {
14395- asm volatile(LOCK_PREFIX "incl %0"
14396+ asm volatile(LOCK_PREFIX "incl %0\n"
14397+
14398+#ifdef CONFIG_PAX_REFCOUNT
14399+ "jno 0f\n"
14400+ LOCK_PREFIX "decl %0\n"
14401+ "int $4\n0:\n"
14402+ _ASM_EXTABLE(0b, 0b)
14403+#endif
14404+
14405+ : "+m" (v->counter));
14406+}
14407+
14408+/**
14409+ * atomic_inc_unchecked - increment atomic variable
14410+ * @v: pointer of type atomic_unchecked_t
14411+ *
14412+ * Atomically increments @v by 1.
14413+ */
14414+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14415+{
14416+ asm volatile(LOCK_PREFIX "incl %0\n"
14417 : "+m" (v->counter));
14418 }
14419
14420@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14421 */
14422 static inline void atomic_dec(atomic_t *v)
14423 {
14424- asm volatile(LOCK_PREFIX "decl %0"
14425+ asm volatile(LOCK_PREFIX "decl %0\n"
14426+
14427+#ifdef CONFIG_PAX_REFCOUNT
14428+ "jno 0f\n"
14429+ LOCK_PREFIX "incl %0\n"
14430+ "int $4\n0:\n"
14431+ _ASM_EXTABLE(0b, 0b)
14432+#endif
14433+
14434+ : "+m" (v->counter));
14435+}
14436+
14437+/**
14438+ * atomic_dec_unchecked - decrement atomic variable
14439+ * @v: pointer of type atomic_unchecked_t
14440+ *
14441+ * Atomically decrements @v by 1.
14442+ */
14443+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14444+{
14445+ asm volatile(LOCK_PREFIX "decl %0\n"
14446 : "+m" (v->counter));
14447 }
14448
14449@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14450 */
14451 static inline int atomic_dec_and_test(atomic_t *v)
14452 {
14453- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14454+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14455 }
14456
14457 /**
14458@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14459 */
14460 static inline int atomic_inc_and_test(atomic_t *v)
14461 {
14462- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14463+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14464+}
14465+
14466+/**
14467+ * atomic_inc_and_test_unchecked - increment and test
14468+ * @v: pointer of type atomic_unchecked_t
14469+ *
14470+ * Atomically increments @v by 1
14471+ * and returns true if the result is zero, or false for all
14472+ * other cases.
14473+ */
14474+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14475+{
14476+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14477 }
14478
14479 /**
14480@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14481 */
14482 static inline int atomic_add_negative(int i, atomic_t *v)
14483 {
14484- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14485+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14486 }
14487
14488 /**
14489@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14490 */
14491 static inline int atomic_add_return(int i, atomic_t *v)
14492 {
14493+ return i + xadd_check_overflow(&v->counter, i);
14494+}
14495+
14496+/**
14497+ * atomic_add_return_unchecked - add integer and return
14498+ * @i: integer value to add
14499+ * @v: pointer of type atomic_unchecked_t
14500+ *
14501+ * Atomically adds @i to @v and returns @i + @v
14502+ */
14503+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14504+{
14505 return i + xadd(&v->counter, i);
14506 }
14507
14508@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14509 }
14510
14511 #define atomic_inc_return(v) (atomic_add_return(1, v))
14512+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14513+{
14514+ return atomic_add_return_unchecked(1, v);
14515+}
14516 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14517
14518-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14519+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14520+{
14521+ return cmpxchg(&v->counter, old, new);
14522+}
14523+
14524+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14525 {
14526 return cmpxchg(&v->counter, old, new);
14527 }
14528@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14529 return xchg(&v->counter, new);
14530 }
14531
14532+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14533+{
14534+ return xchg(&v->counter, new);
14535+}
14536+
14537 /**
14538 * __atomic_add_unless - add unless the number is already a given value
14539 * @v: pointer of type atomic_t
14540@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
14541 * Atomically adds @a to @v, so long as @v was not already @u.
14542 * Returns the old value of @v.
14543 */
14544-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14545+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
14546 {
14547- int c, old;
14548+ int c, old, new;
14549 c = atomic_read(v);
14550 for (;;) {
14551- if (unlikely(c == (u)))
14552+ if (unlikely(c == u))
14553 break;
14554- old = atomic_cmpxchg((v), c, c + (a));
14555+
14556+ asm volatile("addl %2,%0\n"
14557+
14558+#ifdef CONFIG_PAX_REFCOUNT
14559+ "jno 0f\n"
14560+ "subl %2,%0\n"
14561+ "int $4\n0:\n"
14562+ _ASM_EXTABLE(0b, 0b)
14563+#endif
14564+
14565+ : "=r" (new)
14566+ : "0" (c), "ir" (a));
14567+
14568+ old = atomic_cmpxchg(v, c, new);
14569 if (likely(old == c))
14570 break;
14571 c = old;
14572@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14573 }
14574
14575 /**
14576+ * atomic_inc_not_zero_hint - increment if not null
14577+ * @v: pointer of type atomic_t
14578+ * @hint: probable value of the atomic before the increment
14579+ *
14580+ * This version of atomic_inc_not_zero() gives a hint of probable
14581+ * value of the atomic. This helps processor to not read the memory
14582+ * before doing the atomic read/modify/write cycle, lowering
14583+ * number of bus transactions on some arches.
14584+ *
14585+ * Returns: 0 if increment was not done, 1 otherwise.
14586+ */
14587+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14588+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14589+{
14590+ int val, c = hint, new;
14591+
14592+ /* sanity test, should be removed by compiler if hint is a constant */
14593+ if (!hint)
14594+ return __atomic_add_unless(v, 1, 0);
14595+
14596+ do {
14597+ asm volatile("incl %0\n"
14598+
14599+#ifdef CONFIG_PAX_REFCOUNT
14600+ "jno 0f\n"
14601+ "decl %0\n"
14602+ "int $4\n0:\n"
14603+ _ASM_EXTABLE(0b, 0b)
14604+#endif
14605+
14606+ : "=r" (new)
14607+ : "0" (c));
14608+
14609+ val = atomic_cmpxchg(v, c, new);
14610+ if (val == c)
14611+ return 1;
14612+ c = val;
14613+ } while (c);
14614+
14615+ return 0;
14616+}
14617+
14618+/**
14619 * atomic_inc_short - increment of a short integer
14620 * @v: pointer to type int
14621 *
14622@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14623 #endif
14624
14625 /* These are x86-specific, used by some header files */
14626-#define atomic_clear_mask(mask, addr) \
14627- asm volatile(LOCK_PREFIX "andl %0,%1" \
14628- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14629+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14630+{
14631+ asm volatile(LOCK_PREFIX "andl %1,%0"
14632+ : "+m" (v->counter)
14633+ : "r" (~(mask))
14634+ : "memory");
14635+}
14636
14637-#define atomic_set_mask(mask, addr) \
14638- asm volatile(LOCK_PREFIX "orl %0,%1" \
14639- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14640- : "memory")
14641+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14642+{
14643+ asm volatile(LOCK_PREFIX "andl %1,%0"
14644+ : "+m" (v->counter)
14645+ : "r" (~(mask))
14646+ : "memory");
14647+}
14648+
14649+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14650+{
14651+ asm volatile(LOCK_PREFIX "orl %1,%0"
14652+ : "+m" (v->counter)
14653+ : "r" (mask)
14654+ : "memory");
14655+}
14656+
14657+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14658+{
14659+ asm volatile(LOCK_PREFIX "orl %1,%0"
14660+ : "+m" (v->counter)
14661+ : "r" (mask)
14662+ : "memory");
14663+}
14664
14665 /* Atomic operations are already serializing on x86 */
14666 #define smp_mb__before_atomic_dec() barrier()
14667diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14668index b154de7..bf18a5a 100644
14669--- a/arch/x86/include/asm/atomic64_32.h
14670+++ b/arch/x86/include/asm/atomic64_32.h
14671@@ -12,6 +12,14 @@ typedef struct {
14672 u64 __aligned(8) counter;
14673 } atomic64_t;
14674
14675+#ifdef CONFIG_PAX_REFCOUNT
14676+typedef struct {
14677+ u64 __aligned(8) counter;
14678+} atomic64_unchecked_t;
14679+#else
14680+typedef atomic64_t atomic64_unchecked_t;
14681+#endif
14682+
14683 #define ATOMIC64_INIT(val) { (val) }
14684
14685 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14686@@ -37,21 +45,31 @@ typedef struct {
14687 ATOMIC64_DECL_ONE(sym##_386)
14688
14689 ATOMIC64_DECL_ONE(add_386);
14690+ATOMIC64_DECL_ONE(add_unchecked_386);
14691 ATOMIC64_DECL_ONE(sub_386);
14692+ATOMIC64_DECL_ONE(sub_unchecked_386);
14693 ATOMIC64_DECL_ONE(inc_386);
14694+ATOMIC64_DECL_ONE(inc_unchecked_386);
14695 ATOMIC64_DECL_ONE(dec_386);
14696+ATOMIC64_DECL_ONE(dec_unchecked_386);
14697 #endif
14698
14699 #define alternative_atomic64(f, out, in...) \
14700 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14701
14702 ATOMIC64_DECL(read);
14703+ATOMIC64_DECL(read_unchecked);
14704 ATOMIC64_DECL(set);
14705+ATOMIC64_DECL(set_unchecked);
14706 ATOMIC64_DECL(xchg);
14707 ATOMIC64_DECL(add_return);
14708+ATOMIC64_DECL(add_return_unchecked);
14709 ATOMIC64_DECL(sub_return);
14710+ATOMIC64_DECL(sub_return_unchecked);
14711 ATOMIC64_DECL(inc_return);
14712+ATOMIC64_DECL(inc_return_unchecked);
14713 ATOMIC64_DECL(dec_return);
14714+ATOMIC64_DECL(dec_return_unchecked);
14715 ATOMIC64_DECL(dec_if_positive);
14716 ATOMIC64_DECL(inc_not_zero);
14717 ATOMIC64_DECL(add_unless);
14718@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14719 }
14720
14721 /**
14722+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14723+ * @p: pointer to type atomic64_unchecked_t
14724+ * @o: expected value
14725+ * @n: new value
14726+ *
14727+ * Atomically sets @v to @n if it was equal to @o and returns
14728+ * the old value.
14729+ */
14730+
14731+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14732+{
14733+ return cmpxchg64(&v->counter, o, n);
14734+}
14735+
14736+/**
14737 * atomic64_xchg - xchg atomic64 variable
14738 * @v: pointer to type atomic64_t
14739 * @n: value to assign
14740@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14741 }
14742
14743 /**
14744+ * atomic64_set_unchecked - set atomic64 variable
14745+ * @v: pointer to type atomic64_unchecked_t
14746+ * @n: value to assign
14747+ *
14748+ * Atomically sets the value of @v to @n.
14749+ */
14750+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14751+{
14752+ unsigned high = (unsigned)(i >> 32);
14753+ unsigned low = (unsigned)i;
14754+ alternative_atomic64(set, /* no output */,
14755+ "S" (v), "b" (low), "c" (high)
14756+ : "eax", "edx", "memory");
14757+}
14758+
14759+/**
14760 * atomic64_read - read atomic64 variable
14761 * @v: pointer to type atomic64_t
14762 *
14763@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14764 }
14765
14766 /**
14767+ * atomic64_read_unchecked - read atomic64 variable
14768+ * @v: pointer to type atomic64_unchecked_t
14769+ *
14770+ * Atomically reads the value of @v and returns it.
14771+ */
14772+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
14773+{
14774+ long long r;
14775+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14776+ return r;
14777+ }
14778+
14779+/**
14780 * atomic64_add_return - add and return
14781 * @i: integer value to add
14782 * @v: pointer to type atomic64_t
14783@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14784 return i;
14785 }
14786
14787+/**
14788+ * atomic64_add_return_unchecked - add and return
14789+ * @i: integer value to add
14790+ * @v: pointer to type atomic64_unchecked_t
14791+ *
14792+ * Atomically adds @i to @v and returns @i + *@v
14793+ */
14794+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14795+{
14796+ alternative_atomic64(add_return_unchecked,
14797+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14798+ ASM_NO_INPUT_CLOBBER("memory"));
14799+ return i;
14800+}
14801+
14802 /*
14803 * Other variants with different arithmetic operators:
14804 */
14805@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14806 return a;
14807 }
14808
14809+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14810+{
14811+ long long a;
14812+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14813+ "S" (v) : "memory", "ecx");
14814+ return a;
14815+}
14816+
14817 static inline long long atomic64_dec_return(atomic64_t *v)
14818 {
14819 long long a;
14820@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14821 }
14822
14823 /**
14824+ * atomic64_add_unchecked - add integer to atomic64 variable
14825+ * @i: integer value to add
14826+ * @v: pointer to type atomic64_unchecked_t
14827+ *
14828+ * Atomically adds @i to @v.
14829+ */
14830+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14831+{
14832+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14833+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14834+ ASM_NO_INPUT_CLOBBER("memory"));
14835+ return i;
14836+}
14837+
14838+/**
14839 * atomic64_sub - subtract the atomic64 variable
14840 * @i: integer value to subtract
14841 * @v: pointer to type atomic64_t
14842diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14843index 46e9052..ae45136 100644
14844--- a/arch/x86/include/asm/atomic64_64.h
14845+++ b/arch/x86/include/asm/atomic64_64.h
14846@@ -18,7 +18,19 @@
14847 */
14848 static inline long atomic64_read(const atomic64_t *v)
14849 {
14850- return (*(volatile long *)&(v)->counter);
14851+ return (*(volatile const long *)&(v)->counter);
14852+}
14853+
14854+/**
14855+ * atomic64_read_unchecked - read atomic64 variable
14856+ * @v: pointer of type atomic64_unchecked_t
14857+ *
14858+ * Atomically reads the value of @v.
14859+ * Doesn't imply a read memory barrier.
14860+ */
14861+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
14862+{
14863+ return (*(volatile const long *)&(v)->counter);
14864 }
14865
14866 /**
14867@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14868 }
14869
14870 /**
14871+ * atomic64_set_unchecked - set atomic64 variable
14872+ * @v: pointer to type atomic64_unchecked_t
14873+ * @i: required value
14874+ *
14875+ * Atomically sets the value of @v to @i.
14876+ */
14877+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14878+{
14879+ v->counter = i;
14880+}
14881+
14882+/**
14883 * atomic64_add - add integer to atomic64 variable
14884 * @i: integer value to add
14885 * @v: pointer to type atomic64_t
14886@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14887 */
14888 static inline void atomic64_add(long i, atomic64_t *v)
14889 {
14890+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14891+
14892+#ifdef CONFIG_PAX_REFCOUNT
14893+ "jno 0f\n"
14894+ LOCK_PREFIX "subq %1,%0\n"
14895+ "int $4\n0:\n"
14896+ _ASM_EXTABLE(0b, 0b)
14897+#endif
14898+
14899+ : "=m" (v->counter)
14900+ : "er" (i), "m" (v->counter));
14901+}
14902+
14903+/**
14904+ * atomic64_add_unchecked - add integer to atomic64 variable
14905+ * @i: integer value to add
14906+ * @v: pointer to type atomic64_unchecked_t
14907+ *
14908+ * Atomically adds @i to @v.
14909+ */
14910+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14911+{
14912 asm volatile(LOCK_PREFIX "addq %1,%0"
14913 : "=m" (v->counter)
14914 : "er" (i), "m" (v->counter));
14915@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14916 */
14917 static inline void atomic64_sub(long i, atomic64_t *v)
14918 {
14919- asm volatile(LOCK_PREFIX "subq %1,%0"
14920+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14921+
14922+#ifdef CONFIG_PAX_REFCOUNT
14923+ "jno 0f\n"
14924+ LOCK_PREFIX "addq %1,%0\n"
14925+ "int $4\n0:\n"
14926+ _ASM_EXTABLE(0b, 0b)
14927+#endif
14928+
14929+ : "=m" (v->counter)
14930+ : "er" (i), "m" (v->counter));
14931+}
14932+
14933+/**
14934+ * atomic64_sub_unchecked - subtract the atomic64 variable
14935+ * @i: integer value to subtract
14936+ * @v: pointer to type atomic64_unchecked_t
14937+ *
14938+ * Atomically subtracts @i from @v.
14939+ */
14940+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14941+{
14942+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14943 : "=m" (v->counter)
14944 : "er" (i), "m" (v->counter));
14945 }
14946@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
14947 */
14948 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14949 {
14950- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
14951+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
14952 }
14953
14954 /**
14955@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14956 */
14957 static inline void atomic64_inc(atomic64_t *v)
14958 {
14959+ asm volatile(LOCK_PREFIX "incq %0\n"
14960+
14961+#ifdef CONFIG_PAX_REFCOUNT
14962+ "jno 0f\n"
14963+ LOCK_PREFIX "decq %0\n"
14964+ "int $4\n0:\n"
14965+ _ASM_EXTABLE(0b, 0b)
14966+#endif
14967+
14968+ : "=m" (v->counter)
14969+ : "m" (v->counter));
14970+}
14971+
14972+/**
14973+ * atomic64_inc_unchecked - increment atomic64 variable
14974+ * @v: pointer to type atomic64_unchecked_t
14975+ *
14976+ * Atomically increments @v by 1.
14977+ */
14978+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14979+{
14980 asm volatile(LOCK_PREFIX "incq %0"
14981 : "=m" (v->counter)
14982 : "m" (v->counter));
14983@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
14984 */
14985 static inline void atomic64_dec(atomic64_t *v)
14986 {
14987- asm volatile(LOCK_PREFIX "decq %0"
14988+ asm volatile(LOCK_PREFIX "decq %0\n"
14989+
14990+#ifdef CONFIG_PAX_REFCOUNT
14991+ "jno 0f\n"
14992+ LOCK_PREFIX "incq %0\n"
14993+ "int $4\n0:\n"
14994+ _ASM_EXTABLE(0b, 0b)
14995+#endif
14996+
14997+ : "=m" (v->counter)
14998+ : "m" (v->counter));
14999+}
15000+
15001+/**
15002+ * atomic64_dec_unchecked - decrement atomic64 variable
15003+ * @v: pointer to type atomic64_t
15004+ *
15005+ * Atomically decrements @v by 1.
15006+ */
15007+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15008+{
15009+ asm volatile(LOCK_PREFIX "decq %0\n"
15010 : "=m" (v->counter)
15011 : "m" (v->counter));
15012 }
15013@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15014 */
15015 static inline int atomic64_dec_and_test(atomic64_t *v)
15016 {
15017- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15018+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15019 }
15020
15021 /**
15022@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15023 */
15024 static inline int atomic64_inc_and_test(atomic64_t *v)
15025 {
15026- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15027+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15028 }
15029
15030 /**
15031@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15032 */
15033 static inline int atomic64_add_negative(long i, atomic64_t *v)
15034 {
15035- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15036+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15037 }
15038
15039 /**
15040@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15041 */
15042 static inline long atomic64_add_return(long i, atomic64_t *v)
15043 {
15044+ return i + xadd_check_overflow(&v->counter, i);
15045+}
15046+
15047+/**
15048+ * atomic64_add_return_unchecked - add and return
15049+ * @i: integer value to add
15050+ * @v: pointer to type atomic64_unchecked_t
15051+ *
15052+ * Atomically adds @i to @v and returns @i + @v
15053+ */
15054+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15055+{
15056 return i + xadd(&v->counter, i);
15057 }
15058
15059@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15060 }
15061
15062 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15063+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15064+{
15065+ return atomic64_add_return_unchecked(1, v);
15066+}
15067 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15068
15069 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15070@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15071 return cmpxchg(&v->counter, old, new);
15072 }
15073
15074+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15075+{
15076+ return cmpxchg(&v->counter, old, new);
15077+}
15078+
15079 static inline long atomic64_xchg(atomic64_t *v, long new)
15080 {
15081 return xchg(&v->counter, new);
15082@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15083 */
15084 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15085 {
15086- long c, old;
15087+ long c, old, new;
15088 c = atomic64_read(v);
15089 for (;;) {
15090- if (unlikely(c == (u)))
15091+ if (unlikely(c == u))
15092 break;
15093- old = atomic64_cmpxchg((v), c, c + (a));
15094+
15095+ asm volatile("add %2,%0\n"
15096+
15097+#ifdef CONFIG_PAX_REFCOUNT
15098+ "jno 0f\n"
15099+ "sub %2,%0\n"
15100+ "int $4\n0:\n"
15101+ _ASM_EXTABLE(0b, 0b)
15102+#endif
15103+
15104+ : "=r" (new)
15105+ : "0" (c), "ir" (a));
15106+
15107+ old = atomic64_cmpxchg(v, c, new);
15108 if (likely(old == c))
15109 break;
15110 c = old;
15111 }
15112- return c != (u);
15113+ return c != u;
15114 }
15115
15116 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15117diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15118index 9fc1af7..fc71228 100644
15119--- a/arch/x86/include/asm/bitops.h
15120+++ b/arch/x86/include/asm/bitops.h
15121@@ -49,7 +49,7 @@
15122 * a mask operation on a byte.
15123 */
15124 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15125-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15126+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15127 #define CONST_MASK(nr) (1 << ((nr) & 7))
15128
15129 /**
15130@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15131 */
15132 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15133 {
15134- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15135+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15136 }
15137
15138 /**
15139@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15140 */
15141 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15142 {
15143- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15144+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15145 }
15146
15147 /**
15148@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15149 */
15150 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15151 {
15152- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15153+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15154 }
15155
15156 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15157@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15158 *
15159 * Undefined if no bit exists, so code should check against 0 first.
15160 */
15161-static inline unsigned long __ffs(unsigned long word)
15162+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15163 {
15164 asm("rep; bsf %1,%0"
15165 : "=r" (word)
15166@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15167 *
15168 * Undefined if no zero exists, so code should check against ~0UL first.
15169 */
15170-static inline unsigned long ffz(unsigned long word)
15171+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15172 {
15173 asm("rep; bsf %1,%0"
15174 : "=r" (word)
15175@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15176 *
15177 * Undefined if no set bit exists, so code should check against 0 first.
15178 */
15179-static inline unsigned long __fls(unsigned long word)
15180+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15181 {
15182 asm("bsr %1,%0"
15183 : "=r" (word)
15184@@ -436,7 +436,7 @@ static inline int ffs(int x)
15185 * set bit if value is nonzero. The last (most significant) bit is
15186 * at position 32.
15187 */
15188-static inline int fls(int x)
15189+static inline int __intentional_overflow(-1) fls(int x)
15190 {
15191 int r;
15192
15193@@ -478,7 +478,7 @@ static inline int fls(int x)
15194 * at position 64.
15195 */
15196 #ifdef CONFIG_X86_64
15197-static __always_inline int fls64(__u64 x)
15198+static __always_inline long fls64(__u64 x)
15199 {
15200 int bitpos = -1;
15201 /*
15202diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15203index 4fa687a..60f2d39 100644
15204--- a/arch/x86/include/asm/boot.h
15205+++ b/arch/x86/include/asm/boot.h
15206@@ -6,10 +6,15 @@
15207 #include <uapi/asm/boot.h>
15208
15209 /* Physical address where kernel should be loaded. */
15210-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15211+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15212 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15213 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15214
15215+#ifndef __ASSEMBLY__
15216+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15217+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15218+#endif
15219+
15220 /* Minimum kernel alignment, as a power of two */
15221 #ifdef CONFIG_X86_64
15222 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15223diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15224index 48f99f1..d78ebf9 100644
15225--- a/arch/x86/include/asm/cache.h
15226+++ b/arch/x86/include/asm/cache.h
15227@@ -5,12 +5,13 @@
15228
15229 /* L1 cache line size */
15230 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15231-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15232+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15233
15234 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15235+#define __read_only __attribute__((__section__(".data..read_only")))
15236
15237 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15238-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15239+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15240
15241 #ifdef CONFIG_X86_VSMP
15242 #ifdef CONFIG_SMP
15243diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15244index 9863ee3..4a1f8e1 100644
15245--- a/arch/x86/include/asm/cacheflush.h
15246+++ b/arch/x86/include/asm/cacheflush.h
15247@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15248 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15249
15250 if (pg_flags == _PGMT_DEFAULT)
15251- return -1;
15252+ return ~0UL;
15253 else if (pg_flags == _PGMT_WC)
15254 return _PAGE_CACHE_WC;
15255 else if (pg_flags == _PGMT_UC_MINUS)
15256diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15257index cb4c73b..c473c29 100644
15258--- a/arch/x86/include/asm/calling.h
15259+++ b/arch/x86/include/asm/calling.h
15260@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15261 #define RSP 152
15262 #define SS 160
15263
15264-#define ARGOFFSET R11
15265-#define SWFRAME ORIG_RAX
15266+#define ARGOFFSET R15
15267
15268 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15269- subq $9*8+\addskip, %rsp
15270- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15271- movq_cfi rdi, 8*8
15272- movq_cfi rsi, 7*8
15273- movq_cfi rdx, 6*8
15274+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15275+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15276+ movq_cfi rdi, RDI
15277+ movq_cfi rsi, RSI
15278+ movq_cfi rdx, RDX
15279
15280 .if \save_rcx
15281- movq_cfi rcx, 5*8
15282+ movq_cfi rcx, RCX
15283 .endif
15284
15285- movq_cfi rax, 4*8
15286+ movq_cfi rax, RAX
15287
15288 .if \save_r891011
15289- movq_cfi r8, 3*8
15290- movq_cfi r9, 2*8
15291- movq_cfi r10, 1*8
15292- movq_cfi r11, 0*8
15293+ movq_cfi r8, R8
15294+ movq_cfi r9, R9
15295+ movq_cfi r10, R10
15296+ movq_cfi r11, R11
15297 .endif
15298
15299+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15300+ movq_cfi r12, R12
15301+#endif
15302+
15303 .endm
15304
15305-#define ARG_SKIP (9*8)
15306+#define ARG_SKIP ORIG_RAX
15307
15308 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15309 rstor_r8910=1, rstor_rdx=1
15310+
15311+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15312+ movq_cfi_restore R12, r12
15313+#endif
15314+
15315 .if \rstor_r11
15316- movq_cfi_restore 0*8, r11
15317+ movq_cfi_restore R11, r11
15318 .endif
15319
15320 .if \rstor_r8910
15321- movq_cfi_restore 1*8, r10
15322- movq_cfi_restore 2*8, r9
15323- movq_cfi_restore 3*8, r8
15324+ movq_cfi_restore R10, r10
15325+ movq_cfi_restore R9, r9
15326+ movq_cfi_restore R8, r8
15327 .endif
15328
15329 .if \rstor_rax
15330- movq_cfi_restore 4*8, rax
15331+ movq_cfi_restore RAX, rax
15332 .endif
15333
15334 .if \rstor_rcx
15335- movq_cfi_restore 5*8, rcx
15336+ movq_cfi_restore RCX, rcx
15337 .endif
15338
15339 .if \rstor_rdx
15340- movq_cfi_restore 6*8, rdx
15341+ movq_cfi_restore RDX, rdx
15342 .endif
15343
15344- movq_cfi_restore 7*8, rsi
15345- movq_cfi_restore 8*8, rdi
15346+ movq_cfi_restore RSI, rsi
15347+ movq_cfi_restore RDI, rdi
15348
15349- .if ARG_SKIP+\addskip > 0
15350- addq $ARG_SKIP+\addskip, %rsp
15351- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15352+ .if ORIG_RAX+\addskip > 0
15353+ addq $ORIG_RAX+\addskip, %rsp
15354+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15355 .endif
15356 .endm
15357
15358- .macro LOAD_ARGS offset, skiprax=0
15359- movq \offset(%rsp), %r11
15360- movq \offset+8(%rsp), %r10
15361- movq \offset+16(%rsp), %r9
15362- movq \offset+24(%rsp), %r8
15363- movq \offset+40(%rsp), %rcx
15364- movq \offset+48(%rsp), %rdx
15365- movq \offset+56(%rsp), %rsi
15366- movq \offset+64(%rsp), %rdi
15367+ .macro LOAD_ARGS skiprax=0
15368+ movq R11(%rsp), %r11
15369+ movq R10(%rsp), %r10
15370+ movq R9(%rsp), %r9
15371+ movq R8(%rsp), %r8
15372+ movq RCX(%rsp), %rcx
15373+ movq RDX(%rsp), %rdx
15374+ movq RSI(%rsp), %rsi
15375+ movq RDI(%rsp), %rdi
15376 .if \skiprax
15377 .else
15378- movq \offset+72(%rsp), %rax
15379+ movq RAX(%rsp), %rax
15380 .endif
15381 .endm
15382
15383-#define REST_SKIP (6*8)
15384-
15385 .macro SAVE_REST
15386- subq $REST_SKIP, %rsp
15387- CFI_ADJUST_CFA_OFFSET REST_SKIP
15388- movq_cfi rbx, 5*8
15389- movq_cfi rbp, 4*8
15390- movq_cfi r12, 3*8
15391- movq_cfi r13, 2*8
15392- movq_cfi r14, 1*8
15393- movq_cfi r15, 0*8
15394+ movq_cfi rbx, RBX
15395+ movq_cfi rbp, RBP
15396+
15397+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15398+ movq_cfi r12, R12
15399+#endif
15400+
15401+ movq_cfi r13, R13
15402+ movq_cfi r14, R14
15403+ movq_cfi r15, R15
15404 .endm
15405
15406 .macro RESTORE_REST
15407- movq_cfi_restore 0*8, r15
15408- movq_cfi_restore 1*8, r14
15409- movq_cfi_restore 2*8, r13
15410- movq_cfi_restore 3*8, r12
15411- movq_cfi_restore 4*8, rbp
15412- movq_cfi_restore 5*8, rbx
15413- addq $REST_SKIP, %rsp
15414- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15415+ movq_cfi_restore R15, r15
15416+ movq_cfi_restore R14, r14
15417+ movq_cfi_restore R13, r13
15418+
15419+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15420+ movq_cfi_restore R12, r12
15421+#endif
15422+
15423+ movq_cfi_restore RBP, rbp
15424+ movq_cfi_restore RBX, rbx
15425 .endm
15426
15427 .macro SAVE_ALL
15428diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15429index f50de69..2b0a458 100644
15430--- a/arch/x86/include/asm/checksum_32.h
15431+++ b/arch/x86/include/asm/checksum_32.h
15432@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15433 int len, __wsum sum,
15434 int *src_err_ptr, int *dst_err_ptr);
15435
15436+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15437+ int len, __wsum sum,
15438+ int *src_err_ptr, int *dst_err_ptr);
15439+
15440+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15441+ int len, __wsum sum,
15442+ int *src_err_ptr, int *dst_err_ptr);
15443+
15444 /*
15445 * Note: when you get a NULL pointer exception here this means someone
15446 * passed in an incorrect kernel address to one of these functions.
15447@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15448
15449 might_sleep();
15450 stac();
15451- ret = csum_partial_copy_generic((__force void *)src, dst,
15452+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15453 len, sum, err_ptr, NULL);
15454 clac();
15455
15456@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15457 might_sleep();
15458 if (access_ok(VERIFY_WRITE, dst, len)) {
15459 stac();
15460- ret = csum_partial_copy_generic(src, (__force void *)dst,
15461+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15462 len, sum, NULL, err_ptr);
15463 clac();
15464 return ret;
15465diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15466index d47786a..ce1b05d 100644
15467--- a/arch/x86/include/asm/cmpxchg.h
15468+++ b/arch/x86/include/asm/cmpxchg.h
15469@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15470 __compiletime_error("Bad argument size for cmpxchg");
15471 extern void __xadd_wrong_size(void)
15472 __compiletime_error("Bad argument size for xadd");
15473+extern void __xadd_check_overflow_wrong_size(void)
15474+ __compiletime_error("Bad argument size for xadd_check_overflow");
15475 extern void __add_wrong_size(void)
15476 __compiletime_error("Bad argument size for add");
15477+extern void __add_check_overflow_wrong_size(void)
15478+ __compiletime_error("Bad argument size for add_check_overflow");
15479
15480 /*
15481 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15482@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15483 __ret; \
15484 })
15485
15486+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15487+ ({ \
15488+ __typeof__ (*(ptr)) __ret = (arg); \
15489+ switch (sizeof(*(ptr))) { \
15490+ case __X86_CASE_L: \
15491+ asm volatile (lock #op "l %0, %1\n" \
15492+ "jno 0f\n" \
15493+ "mov %0,%1\n" \
15494+ "int $4\n0:\n" \
15495+ _ASM_EXTABLE(0b, 0b) \
15496+ : "+r" (__ret), "+m" (*(ptr)) \
15497+ : : "memory", "cc"); \
15498+ break; \
15499+ case __X86_CASE_Q: \
15500+ asm volatile (lock #op "q %q0, %1\n" \
15501+ "jno 0f\n" \
15502+ "mov %0,%1\n" \
15503+ "int $4\n0:\n" \
15504+ _ASM_EXTABLE(0b, 0b) \
15505+ : "+r" (__ret), "+m" (*(ptr)) \
15506+ : : "memory", "cc"); \
15507+ break; \
15508+ default: \
15509+ __ ## op ## _check_overflow_wrong_size(); \
15510+ } \
15511+ __ret; \
15512+ })
15513+
15514 /*
15515 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15516 * Since this is generally used to protect other memory information, we
15517@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15518 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15519 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15520
15521+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15522+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15523+
15524 #define __add(ptr, inc, lock) \
15525 ({ \
15526 __typeof__ (*(ptr)) __ret = (inc); \
15527diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15528index 59c6c40..5e0b22c 100644
15529--- a/arch/x86/include/asm/compat.h
15530+++ b/arch/x86/include/asm/compat.h
15531@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15532 typedef u32 compat_uint_t;
15533 typedef u32 compat_ulong_t;
15534 typedef u64 __attribute__((aligned(4))) compat_u64;
15535-typedef u32 compat_uptr_t;
15536+typedef u32 __user compat_uptr_t;
15537
15538 struct compat_timespec {
15539 compat_time_t tv_sec;
15540diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15541index 89270b4..f0abf8e 100644
15542--- a/arch/x86/include/asm/cpufeature.h
15543+++ b/arch/x86/include/asm/cpufeature.h
15544@@ -203,7 +203,7 @@
15545 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15546 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15547 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15548-
15549+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15550
15551 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15552 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15553@@ -211,7 +211,7 @@
15554 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15555 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15556 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15557-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15558+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15559 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15560 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15561 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15562@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15563 #undef cpu_has_centaur_mcr
15564 #define cpu_has_centaur_mcr 0
15565
15566+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15567 #endif /* CONFIG_X86_64 */
15568
15569 #if __GNUC__ >= 4
15570@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15571
15572 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15573 t_warn:
15574- warn_pre_alternatives();
15575+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15576+ warn_pre_alternatives();
15577 return false;
15578 #endif
15579
15580@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15581 ".section .discard,\"aw\",@progbits\n"
15582 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15583 ".previous\n"
15584- ".section .altinstr_replacement,\"ax\"\n"
15585+ ".section .altinstr_replacement,\"a\"\n"
15586 "3: movb $1,%0\n"
15587 "4:\n"
15588 ".previous\n"
15589@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15590 " .byte 2b - 1b\n" /* src len */
15591 " .byte 4f - 3f\n" /* repl len */
15592 ".previous\n"
15593- ".section .altinstr_replacement,\"ax\"\n"
15594+ ".section .altinstr_replacement,\"a\"\n"
15595 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15596 "4:\n"
15597 ".previous\n"
15598@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15599 ".section .discard,\"aw\",@progbits\n"
15600 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15601 ".previous\n"
15602- ".section .altinstr_replacement,\"ax\"\n"
15603+ ".section .altinstr_replacement,\"a\"\n"
15604 "3: movb $0,%0\n"
15605 "4:\n"
15606 ".previous\n"
15607@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15608 ".section .discard,\"aw\",@progbits\n"
15609 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15610 ".previous\n"
15611- ".section .altinstr_replacement,\"ax\"\n"
15612+ ".section .altinstr_replacement,\"a\"\n"
15613 "5: movb $1,%0\n"
15614 "6:\n"
15615 ".previous\n"
15616diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15617index 50d033a..37deb26 100644
15618--- a/arch/x86/include/asm/desc.h
15619+++ b/arch/x86/include/asm/desc.h
15620@@ -4,6 +4,7 @@
15621 #include <asm/desc_defs.h>
15622 #include <asm/ldt.h>
15623 #include <asm/mmu.h>
15624+#include <asm/pgtable.h>
15625
15626 #include <linux/smp.h>
15627 #include <linux/percpu.h>
15628@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15629
15630 desc->type = (info->read_exec_only ^ 1) << 1;
15631 desc->type |= info->contents << 2;
15632+ desc->type |= info->seg_not_present ^ 1;
15633
15634 desc->s = 1;
15635 desc->dpl = 0x3;
15636@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15637 }
15638
15639 extern struct desc_ptr idt_descr;
15640-extern gate_desc idt_table[];
15641-extern struct desc_ptr debug_idt_descr;
15642-extern gate_desc debug_idt_table[];
15643-
15644-struct gdt_page {
15645- struct desc_struct gdt[GDT_ENTRIES];
15646-} __attribute__((aligned(PAGE_SIZE)));
15647-
15648-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15649+extern gate_desc idt_table[IDT_ENTRIES];
15650+extern const struct desc_ptr debug_idt_descr;
15651+extern gate_desc debug_idt_table[IDT_ENTRIES];
15652
15653+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15654 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15655 {
15656- return per_cpu(gdt_page, cpu).gdt;
15657+ return cpu_gdt_table[cpu];
15658 }
15659
15660 #ifdef CONFIG_X86_64
15661@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15662 unsigned long base, unsigned dpl, unsigned flags,
15663 unsigned short seg)
15664 {
15665- gate->a = (seg << 16) | (base & 0xffff);
15666- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15667+ gate->gate.offset_low = base;
15668+ gate->gate.seg = seg;
15669+ gate->gate.reserved = 0;
15670+ gate->gate.type = type;
15671+ gate->gate.s = 0;
15672+ gate->gate.dpl = dpl;
15673+ gate->gate.p = 1;
15674+ gate->gate.offset_high = base >> 16;
15675 }
15676
15677 #endif
15678@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15679
15680 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15681 {
15682+ pax_open_kernel();
15683 memcpy(&idt[entry], gate, sizeof(*gate));
15684+ pax_close_kernel();
15685 }
15686
15687 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15688 {
15689+ pax_open_kernel();
15690 memcpy(&ldt[entry], desc, 8);
15691+ pax_close_kernel();
15692 }
15693
15694 static inline void
15695@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15696 default: size = sizeof(*gdt); break;
15697 }
15698
15699+ pax_open_kernel();
15700 memcpy(&gdt[entry], desc, size);
15701+ pax_close_kernel();
15702 }
15703
15704 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15705@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15706
15707 static inline void native_load_tr_desc(void)
15708 {
15709+ pax_open_kernel();
15710 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15711+ pax_close_kernel();
15712 }
15713
15714 static inline void native_load_gdt(const struct desc_ptr *dtr)
15715@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15716 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15717 unsigned int i;
15718
15719+ pax_open_kernel();
15720 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15721 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15722+ pax_close_kernel();
15723 }
15724
15725 #define _LDT_empty(info) \
15726@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15727 preempt_enable();
15728 }
15729
15730-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15731+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15732 {
15733 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15734 }
15735@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15736 }
15737
15738 #ifdef CONFIG_X86_64
15739-static inline void set_nmi_gate(int gate, void *addr)
15740+static inline void set_nmi_gate(int gate, const void *addr)
15741 {
15742 gate_desc s;
15743
15744@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
15745 #endif
15746
15747 #ifdef CONFIG_TRACING
15748-extern struct desc_ptr trace_idt_descr;
15749-extern gate_desc trace_idt_table[];
15750+extern const struct desc_ptr trace_idt_descr;
15751+extern gate_desc trace_idt_table[IDT_ENTRIES];
15752 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15753 {
15754 write_idt_entry(trace_idt_table, entry, gate);
15755 }
15756
15757-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
15758+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
15759 unsigned dpl, unsigned ist, unsigned seg)
15760 {
15761 gate_desc s;
15762@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15763 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
15764 #endif
15765
15766-static inline void _set_gate(int gate, unsigned type, void *addr,
15767+static inline void _set_gate(int gate, unsigned type, const void *addr,
15768 unsigned dpl, unsigned ist, unsigned seg)
15769 {
15770 gate_desc s;
15771@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15772 #define set_intr_gate(n, addr) \
15773 do { \
15774 BUG_ON((unsigned)n > 0xFF); \
15775- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
15776+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
15777 __KERNEL_CS); \
15778- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
15779+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
15780 0, 0, __KERNEL_CS); \
15781 } while (0)
15782
15783@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
15784 /*
15785 * This routine sets up an interrupt gate at directory privilege level 3.
15786 */
15787-static inline void set_system_intr_gate(unsigned int n, void *addr)
15788+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15789 {
15790 BUG_ON((unsigned)n > 0xFF);
15791 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15792 }
15793
15794-static inline void set_system_trap_gate(unsigned int n, void *addr)
15795+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15796 {
15797 BUG_ON((unsigned)n > 0xFF);
15798 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15799 }
15800
15801-static inline void set_trap_gate(unsigned int n, void *addr)
15802+static inline void set_trap_gate(unsigned int n, const void *addr)
15803 {
15804 BUG_ON((unsigned)n > 0xFF);
15805 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15806@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15807 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15808 {
15809 BUG_ON((unsigned)n > 0xFF);
15810- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15811+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15812 }
15813
15814-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15815+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15816 {
15817 BUG_ON((unsigned)n > 0xFF);
15818 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15819 }
15820
15821-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15822+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15823 {
15824 BUG_ON((unsigned)n > 0xFF);
15825 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15826@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
15827 else
15828 load_idt((const struct desc_ptr *)&idt_descr);
15829 }
15830+
15831+#ifdef CONFIG_X86_32
15832+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15833+{
15834+ struct desc_struct d;
15835+
15836+ if (likely(limit))
15837+ limit = (limit - 1UL) >> PAGE_SHIFT;
15838+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15839+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15840+}
15841+#endif
15842+
15843 #endif /* _ASM_X86_DESC_H */
15844diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15845index 278441f..b95a174 100644
15846--- a/arch/x86/include/asm/desc_defs.h
15847+++ b/arch/x86/include/asm/desc_defs.h
15848@@ -31,6 +31,12 @@ struct desc_struct {
15849 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15850 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15851 };
15852+ struct {
15853+ u16 offset_low;
15854+ u16 seg;
15855+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15856+ unsigned offset_high: 16;
15857+ } gate;
15858 };
15859 } __attribute__((packed));
15860
15861diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15862index ced283a..ffe04cc 100644
15863--- a/arch/x86/include/asm/div64.h
15864+++ b/arch/x86/include/asm/div64.h
15865@@ -39,7 +39,7 @@
15866 __mod; \
15867 })
15868
15869-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15870+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15871 {
15872 union {
15873 u64 v64;
15874diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15875index 9c999c1..3860cb8 100644
15876--- a/arch/x86/include/asm/elf.h
15877+++ b/arch/x86/include/asm/elf.h
15878@@ -243,7 +243,25 @@ extern int force_personality32;
15879 the loader. We need to make sure that it is out of the way of the program
15880 that it will "exec", and that there is sufficient room for the brk. */
15881
15882+#ifdef CONFIG_PAX_SEGMEXEC
15883+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15884+#else
15885 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15886+#endif
15887+
15888+#ifdef CONFIG_PAX_ASLR
15889+#ifdef CONFIG_X86_32
15890+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15891+
15892+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15893+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15894+#else
15895+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15896+
15897+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15898+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15899+#endif
15900+#endif
15901
15902 /* This yields a mask that user programs can use to figure out what
15903 instruction set this CPU supports. This could be done in user space,
15904@@ -296,16 +314,12 @@ do { \
15905
15906 #define ARCH_DLINFO \
15907 do { \
15908- if (vdso_enabled) \
15909- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15910- (unsigned long)current->mm->context.vdso); \
15911+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15912 } while (0)
15913
15914 #define ARCH_DLINFO_X32 \
15915 do { \
15916- if (vdso_enabled) \
15917- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15918- (unsigned long)current->mm->context.vdso); \
15919+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15920 } while (0)
15921
15922 #define AT_SYSINFO 32
15923@@ -320,7 +334,7 @@ else \
15924
15925 #endif /* !CONFIG_X86_32 */
15926
15927-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15928+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15929
15930 #define VDSO_ENTRY \
15931 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15932@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15933 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15934 #define compat_arch_setup_additional_pages syscall32_setup_pages
15935
15936-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15937-#define arch_randomize_brk arch_randomize_brk
15938-
15939 /*
15940 * True on X86_32 or when emulating IA32 on X86_64
15941 */
15942diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15943index 77a99ac..39ff7f5 100644
15944--- a/arch/x86/include/asm/emergency-restart.h
15945+++ b/arch/x86/include/asm/emergency-restart.h
15946@@ -1,6 +1,6 @@
15947 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15948 #define _ASM_X86_EMERGENCY_RESTART_H
15949
15950-extern void machine_emergency_restart(void);
15951+extern void machine_emergency_restart(void) __noreturn;
15952
15953 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15954diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
15955index d3d7469..677ef72 100644
15956--- a/arch/x86/include/asm/floppy.h
15957+++ b/arch/x86/include/asm/floppy.h
15958@@ -229,18 +229,18 @@ static struct fd_routine_l {
15959 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
15960 } fd_routine[] = {
15961 {
15962- request_dma,
15963- free_dma,
15964- get_dma_residue,
15965- dma_mem_alloc,
15966- hard_dma_setup
15967+ ._request_dma = request_dma,
15968+ ._free_dma = free_dma,
15969+ ._get_dma_residue = get_dma_residue,
15970+ ._dma_mem_alloc = dma_mem_alloc,
15971+ ._dma_setup = hard_dma_setup
15972 },
15973 {
15974- vdma_request_dma,
15975- vdma_nop,
15976- vdma_get_dma_residue,
15977- vdma_mem_alloc,
15978- vdma_dma_setup
15979+ ._request_dma = vdma_request_dma,
15980+ ._free_dma = vdma_nop,
15981+ ._get_dma_residue = vdma_get_dma_residue,
15982+ ._dma_mem_alloc = vdma_mem_alloc,
15983+ ._dma_setup = vdma_dma_setup
15984 }
15985 };
15986
15987diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15988index cea1c76..6c0d79b 100644
15989--- a/arch/x86/include/asm/fpu-internal.h
15990+++ b/arch/x86/include/asm/fpu-internal.h
15991@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15992 #define user_insn(insn, output, input...) \
15993 ({ \
15994 int err; \
15995+ pax_open_userland(); \
15996 asm volatile(ASM_STAC "\n" \
15997- "1:" #insn "\n\t" \
15998+ "1:" \
15999+ __copyuser_seg \
16000+ #insn "\n\t" \
16001 "2: " ASM_CLAC "\n" \
16002 ".section .fixup,\"ax\"\n" \
16003 "3: movl $-1,%[err]\n" \
16004@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16005 _ASM_EXTABLE(1b, 3b) \
16006 : [err] "=r" (err), output \
16007 : "0"(0), input); \
16008+ pax_close_userland(); \
16009 err; \
16010 })
16011
16012@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16013 "fnclex\n\t"
16014 "emms\n\t"
16015 "fildl %P[addr]" /* set F?P to defined value */
16016- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16017+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16018 }
16019
16020 return fpu_restore_checking(&tsk->thread.fpu);
16021diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16022index be27ba1..04a8801 100644
16023--- a/arch/x86/include/asm/futex.h
16024+++ b/arch/x86/include/asm/futex.h
16025@@ -12,6 +12,7 @@
16026 #include <asm/smap.h>
16027
16028 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16029+ typecheck(u32 __user *, uaddr); \
16030 asm volatile("\t" ASM_STAC "\n" \
16031 "1:\t" insn "\n" \
16032 "2:\t" ASM_CLAC "\n" \
16033@@ -20,15 +21,16 @@
16034 "\tjmp\t2b\n" \
16035 "\t.previous\n" \
16036 _ASM_EXTABLE(1b, 3b) \
16037- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16038+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16039 : "i" (-EFAULT), "0" (oparg), "1" (0))
16040
16041 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16042+ typecheck(u32 __user *, uaddr); \
16043 asm volatile("\t" ASM_STAC "\n" \
16044 "1:\tmovl %2, %0\n" \
16045 "\tmovl\t%0, %3\n" \
16046 "\t" insn "\n" \
16047- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16048+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16049 "\tjnz\t1b\n" \
16050 "3:\t" ASM_CLAC "\n" \
16051 "\t.section .fixup,\"ax\"\n" \
16052@@ -38,7 +40,7 @@
16053 _ASM_EXTABLE(1b, 4b) \
16054 _ASM_EXTABLE(2b, 4b) \
16055 : "=&a" (oldval), "=&r" (ret), \
16056- "+m" (*uaddr), "=&r" (tem) \
16057+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16058 : "r" (oparg), "i" (-EFAULT), "1" (0))
16059
16060 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16061@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16062
16063 pagefault_disable();
16064
16065+ pax_open_userland();
16066 switch (op) {
16067 case FUTEX_OP_SET:
16068- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16069+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16070 break;
16071 case FUTEX_OP_ADD:
16072- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16073+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16074 uaddr, oparg);
16075 break;
16076 case FUTEX_OP_OR:
16077@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16078 default:
16079 ret = -ENOSYS;
16080 }
16081+ pax_close_userland();
16082
16083 pagefault_enable();
16084
16085@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16086 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16087 return -EFAULT;
16088
16089+ pax_open_userland();
16090 asm volatile("\t" ASM_STAC "\n"
16091- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16092+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16093 "2:\t" ASM_CLAC "\n"
16094 "\t.section .fixup, \"ax\"\n"
16095 "3:\tmov %3, %0\n"
16096 "\tjmp 2b\n"
16097 "\t.previous\n"
16098 _ASM_EXTABLE(1b, 3b)
16099- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16100+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16101 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16102 : "memory"
16103 );
16104+ pax_close_userland();
16105
16106 *uval = oldval;
16107 return ret;
16108diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16109index cba45d9..86344ba 100644
16110--- a/arch/x86/include/asm/hw_irq.h
16111+++ b/arch/x86/include/asm/hw_irq.h
16112@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16113 extern void enable_IO_APIC(void);
16114
16115 /* Statistics */
16116-extern atomic_t irq_err_count;
16117-extern atomic_t irq_mis_count;
16118+extern atomic_unchecked_t irq_err_count;
16119+extern atomic_unchecked_t irq_mis_count;
16120
16121 /* EISA */
16122 extern void eisa_set_level_irq(unsigned int irq);
16123diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16124index a203659..9889f1c 100644
16125--- a/arch/x86/include/asm/i8259.h
16126+++ b/arch/x86/include/asm/i8259.h
16127@@ -62,7 +62,7 @@ struct legacy_pic {
16128 void (*init)(int auto_eoi);
16129 int (*irq_pending)(unsigned int irq);
16130 void (*make_irq)(unsigned int irq);
16131-};
16132+} __do_const;
16133
16134 extern struct legacy_pic *legacy_pic;
16135 extern struct legacy_pic null_legacy_pic;
16136diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16137index 34f69cb..6d95446 100644
16138--- a/arch/x86/include/asm/io.h
16139+++ b/arch/x86/include/asm/io.h
16140@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16141 "m" (*(volatile type __force *)addr) barrier); }
16142
16143 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16144-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16145-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16146+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16147+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16148
16149 build_mmio_read(__readb, "b", unsigned char, "=q", )
16150-build_mmio_read(__readw, "w", unsigned short, "=r", )
16151-build_mmio_read(__readl, "l", unsigned int, "=r", )
16152+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16153+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16154
16155 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16156 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16157@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16158 return ioremap_nocache(offset, size);
16159 }
16160
16161-extern void iounmap(volatile void __iomem *addr);
16162+extern void iounmap(const volatile void __iomem *addr);
16163
16164 extern void set_iounmap_nonlazy(void);
16165
16166@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16167
16168 #include <linux/vmalloc.h>
16169
16170+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16171+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16172+{
16173+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16174+}
16175+
16176+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16177+{
16178+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16179+}
16180+
16181 /*
16182 * Convert a virtual cached pointer to an uncached pointer
16183 */
16184diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16185index bba3cf8..06bc8da 100644
16186--- a/arch/x86/include/asm/irqflags.h
16187+++ b/arch/x86/include/asm/irqflags.h
16188@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16189 sti; \
16190 sysexit
16191
16192+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16193+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16194+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16195+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16196+
16197 #else
16198 #define INTERRUPT_RETURN iret
16199 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16200diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16201index 9454c16..e4100e3 100644
16202--- a/arch/x86/include/asm/kprobes.h
16203+++ b/arch/x86/include/asm/kprobes.h
16204@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16205 #define RELATIVEJUMP_SIZE 5
16206 #define RELATIVECALL_OPCODE 0xe8
16207 #define RELATIVE_ADDR_SIZE 4
16208-#define MAX_STACK_SIZE 64
16209-#define MIN_STACK_SIZE(ADDR) \
16210- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16211- THREAD_SIZE - (unsigned long)(ADDR))) \
16212- ? (MAX_STACK_SIZE) \
16213- : (((unsigned long)current_thread_info()) + \
16214- THREAD_SIZE - (unsigned long)(ADDR)))
16215+#define MAX_STACK_SIZE 64UL
16216+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16217
16218 #define flush_insn_slot(p) do { } while (0)
16219
16220diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16221index 4ad6560..75c7bdd 100644
16222--- a/arch/x86/include/asm/local.h
16223+++ b/arch/x86/include/asm/local.h
16224@@ -10,33 +10,97 @@ typedef struct {
16225 atomic_long_t a;
16226 } local_t;
16227
16228+typedef struct {
16229+ atomic_long_unchecked_t a;
16230+} local_unchecked_t;
16231+
16232 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16233
16234 #define local_read(l) atomic_long_read(&(l)->a)
16235+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16236 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16237+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16238
16239 static inline void local_inc(local_t *l)
16240 {
16241- asm volatile(_ASM_INC "%0"
16242+ asm volatile(_ASM_INC "%0\n"
16243+
16244+#ifdef CONFIG_PAX_REFCOUNT
16245+ "jno 0f\n"
16246+ _ASM_DEC "%0\n"
16247+ "int $4\n0:\n"
16248+ _ASM_EXTABLE(0b, 0b)
16249+#endif
16250+
16251+ : "+m" (l->a.counter));
16252+}
16253+
16254+static inline void local_inc_unchecked(local_unchecked_t *l)
16255+{
16256+ asm volatile(_ASM_INC "%0\n"
16257 : "+m" (l->a.counter));
16258 }
16259
16260 static inline void local_dec(local_t *l)
16261 {
16262- asm volatile(_ASM_DEC "%0"
16263+ asm volatile(_ASM_DEC "%0\n"
16264+
16265+#ifdef CONFIG_PAX_REFCOUNT
16266+ "jno 0f\n"
16267+ _ASM_INC "%0\n"
16268+ "int $4\n0:\n"
16269+ _ASM_EXTABLE(0b, 0b)
16270+#endif
16271+
16272+ : "+m" (l->a.counter));
16273+}
16274+
16275+static inline void local_dec_unchecked(local_unchecked_t *l)
16276+{
16277+ asm volatile(_ASM_DEC "%0\n"
16278 : "+m" (l->a.counter));
16279 }
16280
16281 static inline void local_add(long i, local_t *l)
16282 {
16283- asm volatile(_ASM_ADD "%1,%0"
16284+ asm volatile(_ASM_ADD "%1,%0\n"
16285+
16286+#ifdef CONFIG_PAX_REFCOUNT
16287+ "jno 0f\n"
16288+ _ASM_SUB "%1,%0\n"
16289+ "int $4\n0:\n"
16290+ _ASM_EXTABLE(0b, 0b)
16291+#endif
16292+
16293+ : "+m" (l->a.counter)
16294+ : "ir" (i));
16295+}
16296+
16297+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16298+{
16299+ asm volatile(_ASM_ADD "%1,%0\n"
16300 : "+m" (l->a.counter)
16301 : "ir" (i));
16302 }
16303
16304 static inline void local_sub(long i, local_t *l)
16305 {
16306- asm volatile(_ASM_SUB "%1,%0"
16307+ asm volatile(_ASM_SUB "%1,%0\n"
16308+
16309+#ifdef CONFIG_PAX_REFCOUNT
16310+ "jno 0f\n"
16311+ _ASM_ADD "%1,%0\n"
16312+ "int $4\n0:\n"
16313+ _ASM_EXTABLE(0b, 0b)
16314+#endif
16315+
16316+ : "+m" (l->a.counter)
16317+ : "ir" (i));
16318+}
16319+
16320+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16321+{
16322+ asm volatile(_ASM_SUB "%1,%0\n"
16323 : "+m" (l->a.counter)
16324 : "ir" (i));
16325 }
16326@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16327 */
16328 static inline int local_sub_and_test(long i, local_t *l)
16329 {
16330- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16331+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16332 }
16333
16334 /**
16335@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16336 */
16337 static inline int local_dec_and_test(local_t *l)
16338 {
16339- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16340+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16341 }
16342
16343 /**
16344@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16345 */
16346 static inline int local_inc_and_test(local_t *l)
16347 {
16348- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16349+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16350 }
16351
16352 /**
16353@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16354 */
16355 static inline int local_add_negative(long i, local_t *l)
16356 {
16357- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16358+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16359 }
16360
16361 /**
16362@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16363 static inline long local_add_return(long i, local_t *l)
16364 {
16365 long __i = i;
16366+ asm volatile(_ASM_XADD "%0, %1\n"
16367+
16368+#ifdef CONFIG_PAX_REFCOUNT
16369+ "jno 0f\n"
16370+ _ASM_MOV "%0,%1\n"
16371+ "int $4\n0:\n"
16372+ _ASM_EXTABLE(0b, 0b)
16373+#endif
16374+
16375+ : "+r" (i), "+m" (l->a.counter)
16376+ : : "memory");
16377+ return i + __i;
16378+}
16379+
16380+/**
16381+ * local_add_return_unchecked - add and return
16382+ * @i: integer value to add
16383+ * @l: pointer to type local_unchecked_t
16384+ *
16385+ * Atomically adds @i to @l and returns @i + @l
16386+ */
16387+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16388+{
16389+ long __i = i;
16390 asm volatile(_ASM_XADD "%0, %1;"
16391 : "+r" (i), "+m" (l->a.counter)
16392 : : "memory");
16393@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16394
16395 #define local_cmpxchg(l, o, n) \
16396 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16397+#define local_cmpxchg_unchecked(l, o, n) \
16398+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16399 /* Always has a lock prefix */
16400 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16401
16402diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16403new file mode 100644
16404index 0000000..2bfd3ba
16405--- /dev/null
16406+++ b/arch/x86/include/asm/mman.h
16407@@ -0,0 +1,15 @@
16408+#ifndef _X86_MMAN_H
16409+#define _X86_MMAN_H
16410+
16411+#include <uapi/asm/mman.h>
16412+
16413+#ifdef __KERNEL__
16414+#ifndef __ASSEMBLY__
16415+#ifdef CONFIG_X86_32
16416+#define arch_mmap_check i386_mmap_check
16417+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16418+#endif
16419+#endif
16420+#endif
16421+
16422+#endif /* X86_MMAN_H */
16423diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16424index 5f55e69..e20bfb1 100644
16425--- a/arch/x86/include/asm/mmu.h
16426+++ b/arch/x86/include/asm/mmu.h
16427@@ -9,7 +9,7 @@
16428 * we put the segment information here.
16429 */
16430 typedef struct {
16431- void *ldt;
16432+ struct desc_struct *ldt;
16433 int size;
16434
16435 #ifdef CONFIG_X86_64
16436@@ -18,7 +18,19 @@ typedef struct {
16437 #endif
16438
16439 struct mutex lock;
16440- void *vdso;
16441+ unsigned long vdso;
16442+
16443+#ifdef CONFIG_X86_32
16444+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16445+ unsigned long user_cs_base;
16446+ unsigned long user_cs_limit;
16447+
16448+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16449+ cpumask_t cpu_user_cs_mask;
16450+#endif
16451+
16452+#endif
16453+#endif
16454 } mm_context_t;
16455
16456 #ifdef CONFIG_SMP
16457diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16458index be12c53..4d24039 100644
16459--- a/arch/x86/include/asm/mmu_context.h
16460+++ b/arch/x86/include/asm/mmu_context.h
16461@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16462
16463 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16464 {
16465+
16466+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16467+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16468+ unsigned int i;
16469+ pgd_t *pgd;
16470+
16471+ pax_open_kernel();
16472+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16473+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16474+ set_pgd_batched(pgd+i, native_make_pgd(0));
16475+ pax_close_kernel();
16476+ }
16477+#endif
16478+
16479 #ifdef CONFIG_SMP
16480 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16481 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16482@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16483 struct task_struct *tsk)
16484 {
16485 unsigned cpu = smp_processor_id();
16486+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16487+ int tlbstate = TLBSTATE_OK;
16488+#endif
16489
16490 if (likely(prev != next)) {
16491 #ifdef CONFIG_SMP
16492+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16493+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16494+#endif
16495 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16496 this_cpu_write(cpu_tlbstate.active_mm, next);
16497 #endif
16498 cpumask_set_cpu(cpu, mm_cpumask(next));
16499
16500 /* Re-load page tables */
16501+#ifdef CONFIG_PAX_PER_CPU_PGD
16502+ pax_open_kernel();
16503+
16504+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16505+ if (static_cpu_has(X86_FEATURE_PCID))
16506+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16507+ else
16508+#endif
16509+
16510+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16511+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16512+ pax_close_kernel();
16513+ 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));
16514+
16515+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16516+ if (static_cpu_has(X86_FEATURE_PCID)) {
16517+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16518+ u64 descriptor[2];
16519+ descriptor[0] = PCID_USER;
16520+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16521+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16522+ descriptor[0] = PCID_KERNEL;
16523+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16524+ }
16525+ } else {
16526+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16527+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16528+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16529+ else
16530+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16531+ }
16532+ } else
16533+#endif
16534+
16535+ load_cr3(get_cpu_pgd(cpu, kernel));
16536+#else
16537 load_cr3(next->pgd);
16538+#endif
16539
16540 /* Stop flush ipis for the previous mm */
16541 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16542@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16543 /* Load the LDT, if the LDT is different: */
16544 if (unlikely(prev->context.ldt != next->context.ldt))
16545 load_LDT_nolock(&next->context);
16546+
16547+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16548+ if (!(__supported_pte_mask & _PAGE_NX)) {
16549+ smp_mb__before_clear_bit();
16550+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16551+ smp_mb__after_clear_bit();
16552+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16553+ }
16554+#endif
16555+
16556+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16557+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16558+ prev->context.user_cs_limit != next->context.user_cs_limit))
16559+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16560+#ifdef CONFIG_SMP
16561+ else if (unlikely(tlbstate != TLBSTATE_OK))
16562+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16563+#endif
16564+#endif
16565+
16566 }
16567+ else {
16568+
16569+#ifdef CONFIG_PAX_PER_CPU_PGD
16570+ pax_open_kernel();
16571+
16572+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16573+ if (static_cpu_has(X86_FEATURE_PCID))
16574+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16575+ else
16576+#endif
16577+
16578+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16579+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16580+ pax_close_kernel();
16581+ 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));
16582+
16583+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16584+ if (static_cpu_has(X86_FEATURE_PCID)) {
16585+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16586+ u64 descriptor[2];
16587+ descriptor[0] = PCID_USER;
16588+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16589+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16590+ descriptor[0] = PCID_KERNEL;
16591+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16592+ }
16593+ } else {
16594+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16595+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16596+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16597+ else
16598+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16599+ }
16600+ } else
16601+#endif
16602+
16603+ load_cr3(get_cpu_pgd(cpu, kernel));
16604+#endif
16605+
16606 #ifdef CONFIG_SMP
16607- else {
16608 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16609 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16610
16611@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16612 * tlb flush IPI delivery. We must reload CR3
16613 * to make sure to use no freed page tables.
16614 */
16615+
16616+#ifndef CONFIG_PAX_PER_CPU_PGD
16617 load_cr3(next->pgd);
16618+#endif
16619+
16620 load_LDT_nolock(&next->context);
16621+
16622+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16623+ if (!(__supported_pte_mask & _PAGE_NX))
16624+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16625+#endif
16626+
16627+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16628+#ifdef CONFIG_PAX_PAGEEXEC
16629+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16630+#endif
16631+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16632+#endif
16633+
16634 }
16635+#endif
16636 }
16637-#endif
16638 }
16639
16640 #define activate_mm(prev, next) \
16641diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16642index e3b7819..b257c64 100644
16643--- a/arch/x86/include/asm/module.h
16644+++ b/arch/x86/include/asm/module.h
16645@@ -5,6 +5,7 @@
16646
16647 #ifdef CONFIG_X86_64
16648 /* X86_64 does not define MODULE_PROC_FAMILY */
16649+#define MODULE_PROC_FAMILY ""
16650 #elif defined CONFIG_M486
16651 #define MODULE_PROC_FAMILY "486 "
16652 #elif defined CONFIG_M586
16653@@ -57,8 +58,20 @@
16654 #error unknown processor family
16655 #endif
16656
16657-#ifdef CONFIG_X86_32
16658-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16659+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16660+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16661+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16662+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16663+#else
16664+#define MODULE_PAX_KERNEXEC ""
16665 #endif
16666
16667+#ifdef CONFIG_PAX_MEMORY_UDEREF
16668+#define MODULE_PAX_UDEREF "UDEREF "
16669+#else
16670+#define MODULE_PAX_UDEREF ""
16671+#endif
16672+
16673+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16674+
16675 #endif /* _ASM_X86_MODULE_H */
16676diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16677index 86f9301..b365cda 100644
16678--- a/arch/x86/include/asm/nmi.h
16679+++ b/arch/x86/include/asm/nmi.h
16680@@ -40,11 +40,11 @@ struct nmiaction {
16681 nmi_handler_t handler;
16682 unsigned long flags;
16683 const char *name;
16684-};
16685+} __do_const;
16686
16687 #define register_nmi_handler(t, fn, fg, n, init...) \
16688 ({ \
16689- static struct nmiaction init fn##_na = { \
16690+ static const struct nmiaction init fn##_na = { \
16691 .handler = (fn), \
16692 .name = (n), \
16693 .flags = (fg), \
16694@@ -52,7 +52,7 @@ struct nmiaction {
16695 __register_nmi_handler((t), &fn##_na); \
16696 })
16697
16698-int __register_nmi_handler(unsigned int, struct nmiaction *);
16699+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16700
16701 void unregister_nmi_handler(unsigned int, const char *);
16702
16703diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16704index c878924..21f4889 100644
16705--- a/arch/x86/include/asm/page.h
16706+++ b/arch/x86/include/asm/page.h
16707@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16708 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16709
16710 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16711+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16712
16713 #define __boot_va(x) __va(x)
16714 #define __boot_pa(x) __pa(x)
16715diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16716index 0f1ddee..e2fc3d1 100644
16717--- a/arch/x86/include/asm/page_64.h
16718+++ b/arch/x86/include/asm/page_64.h
16719@@ -7,9 +7,9 @@
16720
16721 /* duplicated to the one in bootmem.h */
16722 extern unsigned long max_pfn;
16723-extern unsigned long phys_base;
16724+extern const unsigned long phys_base;
16725
16726-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16727+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16728 {
16729 unsigned long y = x - __START_KERNEL_map;
16730
16731diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16732index 401f350..dee5d13 100644
16733--- a/arch/x86/include/asm/paravirt.h
16734+++ b/arch/x86/include/asm/paravirt.h
16735@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16736 return (pmd_t) { ret };
16737 }
16738
16739-static inline pmdval_t pmd_val(pmd_t pmd)
16740+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16741 {
16742 pmdval_t ret;
16743
16744@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16745 val);
16746 }
16747
16748+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16749+{
16750+ pgdval_t val = native_pgd_val(pgd);
16751+
16752+ if (sizeof(pgdval_t) > sizeof(long))
16753+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16754+ val, (u64)val >> 32);
16755+ else
16756+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16757+ val);
16758+}
16759+
16760 static inline void pgd_clear(pgd_t *pgdp)
16761 {
16762 set_pgd(pgdp, __pgd(0));
16763@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16764 pv_mmu_ops.set_fixmap(idx, phys, flags);
16765 }
16766
16767+#ifdef CONFIG_PAX_KERNEXEC
16768+static inline unsigned long pax_open_kernel(void)
16769+{
16770+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16771+}
16772+
16773+static inline unsigned long pax_close_kernel(void)
16774+{
16775+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16776+}
16777+#else
16778+static inline unsigned long pax_open_kernel(void) { return 0; }
16779+static inline unsigned long pax_close_kernel(void) { return 0; }
16780+#endif
16781+
16782 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16783
16784 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16785@@ -906,7 +933,7 @@ extern void default_banner(void);
16786
16787 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16788 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16789-#define PARA_INDIRECT(addr) *%cs:addr
16790+#define PARA_INDIRECT(addr) *%ss:addr
16791 #endif
16792
16793 #define INTERRUPT_RETURN \
16794@@ -981,6 +1008,21 @@ extern void default_banner(void);
16795 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16796 CLBR_NONE, \
16797 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16798+
16799+#define GET_CR0_INTO_RDI \
16800+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16801+ mov %rax,%rdi
16802+
16803+#define SET_RDI_INTO_CR0 \
16804+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16805+
16806+#define GET_CR3_INTO_RDI \
16807+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16808+ mov %rax,%rdi
16809+
16810+#define SET_RDI_INTO_CR3 \
16811+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16812+
16813 #endif /* CONFIG_X86_32 */
16814
16815 #endif /* __ASSEMBLY__ */
16816diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16817index aab8f67..0fb0ee4 100644
16818--- a/arch/x86/include/asm/paravirt_types.h
16819+++ b/arch/x86/include/asm/paravirt_types.h
16820@@ -84,7 +84,7 @@ struct pv_init_ops {
16821 */
16822 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16823 unsigned long addr, unsigned len);
16824-};
16825+} __no_const __no_randomize_layout;
16826
16827
16828 struct pv_lazy_ops {
16829@@ -92,13 +92,13 @@ struct pv_lazy_ops {
16830 void (*enter)(void);
16831 void (*leave)(void);
16832 void (*flush)(void);
16833-};
16834+} __no_randomize_layout;
16835
16836 struct pv_time_ops {
16837 unsigned long long (*sched_clock)(void);
16838 unsigned long long (*steal_clock)(int cpu);
16839 unsigned long (*get_tsc_khz)(void);
16840-};
16841+} __no_const __no_randomize_layout;
16842
16843 struct pv_cpu_ops {
16844 /* hooks for various privileged instructions */
16845@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16846
16847 void (*start_context_switch)(struct task_struct *prev);
16848 void (*end_context_switch)(struct task_struct *next);
16849-};
16850+} __no_const __no_randomize_layout;
16851
16852 struct pv_irq_ops {
16853 /*
16854@@ -215,7 +215,7 @@ struct pv_irq_ops {
16855 #ifdef CONFIG_X86_64
16856 void (*adjust_exception_frame)(void);
16857 #endif
16858-};
16859+} __no_randomize_layout;
16860
16861 struct pv_apic_ops {
16862 #ifdef CONFIG_X86_LOCAL_APIC
16863@@ -223,7 +223,7 @@ struct pv_apic_ops {
16864 unsigned long start_eip,
16865 unsigned long start_esp);
16866 #endif
16867-};
16868+} __no_const __no_randomize_layout;
16869
16870 struct pv_mmu_ops {
16871 unsigned long (*read_cr2)(void);
16872@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16873 struct paravirt_callee_save make_pud;
16874
16875 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16876+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16877 #endif /* PAGETABLE_LEVELS == 4 */
16878 #endif /* PAGETABLE_LEVELS >= 3 */
16879
16880@@ -324,7 +325,13 @@ struct pv_mmu_ops {
16881 an mfn. We can tell which is which from the index. */
16882 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16883 phys_addr_t phys, pgprot_t flags);
16884-};
16885+
16886+#ifdef CONFIG_PAX_KERNEXEC
16887+ unsigned long (*pax_open_kernel)(void);
16888+ unsigned long (*pax_close_kernel)(void);
16889+#endif
16890+
16891+} __no_randomize_layout;
16892
16893 struct arch_spinlock;
16894 #ifdef CONFIG_SMP
16895@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
16896 struct pv_lock_ops {
16897 struct paravirt_callee_save lock_spinning;
16898 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
16899-};
16900+} __no_randomize_layout;
16901
16902 /* This contains all the paravirt structures: we get a convenient
16903 * number for each function using the offset which we use to indicate
16904- * what to patch. */
16905+ * what to patch.
16906+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
16907+ */
16908+
16909 struct paravirt_patch_template {
16910 struct pv_init_ops pv_init_ops;
16911 struct pv_time_ops pv_time_ops;
16912@@ -349,7 +359,7 @@ struct paravirt_patch_template {
16913 struct pv_apic_ops pv_apic_ops;
16914 struct pv_mmu_ops pv_mmu_ops;
16915 struct pv_lock_ops pv_lock_ops;
16916-};
16917+} __no_randomize_layout;
16918
16919 extern struct pv_info pv_info;
16920 extern struct pv_init_ops pv_init_ops;
16921diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16922index c4412e9..90e88c5 100644
16923--- a/arch/x86/include/asm/pgalloc.h
16924+++ b/arch/x86/include/asm/pgalloc.h
16925@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16926 pmd_t *pmd, pte_t *pte)
16927 {
16928 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16929+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16930+}
16931+
16932+static inline void pmd_populate_user(struct mm_struct *mm,
16933+ pmd_t *pmd, pte_t *pte)
16934+{
16935+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16936 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16937 }
16938
16939@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16940
16941 #ifdef CONFIG_X86_PAE
16942 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16943+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16944+{
16945+ pud_populate(mm, pudp, pmd);
16946+}
16947 #else /* !CONFIG_X86_PAE */
16948 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16949 {
16950 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16951 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16952 }
16953+
16954+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16955+{
16956+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16957+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16958+}
16959 #endif /* CONFIG_X86_PAE */
16960
16961 #if PAGETABLE_LEVELS > 3
16962@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16963 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16964 }
16965
16966+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16967+{
16968+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16969+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16970+}
16971+
16972 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16973 {
16974 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16975diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16976index 3bf2dd0..23d2a9f 100644
16977--- a/arch/x86/include/asm/pgtable-2level.h
16978+++ b/arch/x86/include/asm/pgtable-2level.h
16979@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16980
16981 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16982 {
16983+ pax_open_kernel();
16984 *pmdp = pmd;
16985+ pax_close_kernel();
16986 }
16987
16988 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16989diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16990index 81bb91b..9392125 100644
16991--- a/arch/x86/include/asm/pgtable-3level.h
16992+++ b/arch/x86/include/asm/pgtable-3level.h
16993@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16994
16995 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16996 {
16997+ pax_open_kernel();
16998 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16999+ pax_close_kernel();
17000 }
17001
17002 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17003 {
17004+ pax_open_kernel();
17005 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17006+ pax_close_kernel();
17007 }
17008
17009 /*
17010diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17011index bbc8b12..f228861 100644
17012--- a/arch/x86/include/asm/pgtable.h
17013+++ b/arch/x86/include/asm/pgtable.h
17014@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17015
17016 #ifndef __PAGETABLE_PUD_FOLDED
17017 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17018+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17019 #define pgd_clear(pgd) native_pgd_clear(pgd)
17020 #endif
17021
17022@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17023
17024 #define arch_end_context_switch(prev) do {} while(0)
17025
17026+#define pax_open_kernel() native_pax_open_kernel()
17027+#define pax_close_kernel() native_pax_close_kernel()
17028 #endif /* CONFIG_PARAVIRT */
17029
17030+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17031+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17032+
17033+#ifdef CONFIG_PAX_KERNEXEC
17034+static inline unsigned long native_pax_open_kernel(void)
17035+{
17036+ unsigned long cr0;
17037+
17038+ preempt_disable();
17039+ barrier();
17040+ cr0 = read_cr0() ^ X86_CR0_WP;
17041+ BUG_ON(cr0 & X86_CR0_WP);
17042+ write_cr0(cr0);
17043+ return cr0 ^ X86_CR0_WP;
17044+}
17045+
17046+static inline unsigned long native_pax_close_kernel(void)
17047+{
17048+ unsigned long cr0;
17049+
17050+ cr0 = read_cr0() ^ X86_CR0_WP;
17051+ BUG_ON(!(cr0 & X86_CR0_WP));
17052+ write_cr0(cr0);
17053+ barrier();
17054+ preempt_enable_no_resched();
17055+ return cr0 ^ X86_CR0_WP;
17056+}
17057+#else
17058+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17059+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17060+#endif
17061+
17062 /*
17063 * The following only work if pte_present() is true.
17064 * Undefined behaviour if not..
17065 */
17066+static inline int pte_user(pte_t pte)
17067+{
17068+ return pte_val(pte) & _PAGE_USER;
17069+}
17070+
17071 static inline int pte_dirty(pte_t pte)
17072 {
17073 return pte_flags(pte) & _PAGE_DIRTY;
17074@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17075 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17076 }
17077
17078+static inline unsigned long pgd_pfn(pgd_t pgd)
17079+{
17080+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17081+}
17082+
17083 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17084
17085 static inline int pmd_large(pmd_t pte)
17086@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17087 return pte_clear_flags(pte, _PAGE_RW);
17088 }
17089
17090+static inline pte_t pte_mkread(pte_t pte)
17091+{
17092+ return __pte(pte_val(pte) | _PAGE_USER);
17093+}
17094+
17095 static inline pte_t pte_mkexec(pte_t pte)
17096 {
17097- return pte_clear_flags(pte, _PAGE_NX);
17098+#ifdef CONFIG_X86_PAE
17099+ if (__supported_pte_mask & _PAGE_NX)
17100+ return pte_clear_flags(pte, _PAGE_NX);
17101+ else
17102+#endif
17103+ return pte_set_flags(pte, _PAGE_USER);
17104+}
17105+
17106+static inline pte_t pte_exprotect(pte_t pte)
17107+{
17108+#ifdef CONFIG_X86_PAE
17109+ if (__supported_pte_mask & _PAGE_NX)
17110+ return pte_set_flags(pte, _PAGE_NX);
17111+ else
17112+#endif
17113+ return pte_clear_flags(pte, _PAGE_USER);
17114 }
17115
17116 static inline pte_t pte_mkdirty(pte_t pte)
17117@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17118 #endif
17119
17120 #ifndef __ASSEMBLY__
17121+
17122+#ifdef CONFIG_PAX_PER_CPU_PGD
17123+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17124+enum cpu_pgd_type {kernel = 0, user = 1};
17125+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17126+{
17127+ return cpu_pgd[cpu][type];
17128+}
17129+#endif
17130+
17131 #include <linux/mm_types.h>
17132 #include <linux/mmdebug.h>
17133 #include <linux/log2.h>
17134@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17135 * Currently stuck as a macro due to indirect forward reference to
17136 * linux/mmzone.h's __section_mem_map_addr() definition:
17137 */
17138-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17139+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17140
17141 /* Find an entry in the second-level page table.. */
17142 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17143@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17144 * Currently stuck as a macro due to indirect forward reference to
17145 * linux/mmzone.h's __section_mem_map_addr() definition:
17146 */
17147-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17148+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17149
17150 /* to find an entry in a page-table-directory. */
17151 static inline unsigned long pud_index(unsigned long address)
17152@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17153
17154 static inline int pgd_bad(pgd_t pgd)
17155 {
17156- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17157+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17158 }
17159
17160 static inline int pgd_none(pgd_t pgd)
17161@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17162 * pgd_offset() returns a (pgd_t *)
17163 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17164 */
17165-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17166+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17167+
17168+#ifdef CONFIG_PAX_PER_CPU_PGD
17169+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17170+#endif
17171+
17172 /*
17173 * a shortcut which implies the use of the kernel's pgd, instead
17174 * of a process's
17175@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17176 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17177 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17178
17179+#ifdef CONFIG_X86_32
17180+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17181+#else
17182+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17183+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17184+
17185+#ifdef CONFIG_PAX_MEMORY_UDEREF
17186+#ifdef __ASSEMBLY__
17187+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17188+#else
17189+extern unsigned long pax_user_shadow_base;
17190+extern pgdval_t clone_pgd_mask;
17191+#endif
17192+#endif
17193+
17194+#endif
17195+
17196 #ifndef __ASSEMBLY__
17197
17198 extern int direct_gbpages;
17199@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17200 * dst and src can be on the same page, but the range must not overlap,
17201 * and must not cross a page boundary.
17202 */
17203-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17204+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17205 {
17206- memcpy(dst, src, count * sizeof(pgd_t));
17207+ pax_open_kernel();
17208+ while (count--)
17209+ *dst++ = *src++;
17210+ pax_close_kernel();
17211 }
17212
17213+#ifdef CONFIG_PAX_PER_CPU_PGD
17214+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17215+#endif
17216+
17217+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17218+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17219+#else
17220+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17221+#endif
17222+
17223 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17224 static inline int page_level_shift(enum pg_level level)
17225 {
17226diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17227index 9ee3221..b979c6b 100644
17228--- a/arch/x86/include/asm/pgtable_32.h
17229+++ b/arch/x86/include/asm/pgtable_32.h
17230@@ -25,9 +25,6 @@
17231 struct mm_struct;
17232 struct vm_area_struct;
17233
17234-extern pgd_t swapper_pg_dir[1024];
17235-extern pgd_t initial_page_table[1024];
17236-
17237 static inline void pgtable_cache_init(void) { }
17238 static inline void check_pgt_cache(void) { }
17239 void paging_init(void);
17240@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17241 # include <asm/pgtable-2level.h>
17242 #endif
17243
17244+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17245+extern pgd_t initial_page_table[PTRS_PER_PGD];
17246+#ifdef CONFIG_X86_PAE
17247+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17248+#endif
17249+
17250 #if defined(CONFIG_HIGHPTE)
17251 #define pte_offset_map(dir, address) \
17252 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17253@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17254 /* Clear a kernel PTE and flush it from the TLB */
17255 #define kpte_clear_flush(ptep, vaddr) \
17256 do { \
17257+ pax_open_kernel(); \
17258 pte_clear(&init_mm, (vaddr), (ptep)); \
17259+ pax_close_kernel(); \
17260 __flush_tlb_one((vaddr)); \
17261 } while (0)
17262
17263 #endif /* !__ASSEMBLY__ */
17264
17265+#define HAVE_ARCH_UNMAPPED_AREA
17266+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17267+
17268 /*
17269 * kern_addr_valid() is (1) for FLATMEM and (0) for
17270 * SPARSEMEM and DISCONTIGMEM
17271diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17272index ed5903b..c7fe163 100644
17273--- a/arch/x86/include/asm/pgtable_32_types.h
17274+++ b/arch/x86/include/asm/pgtable_32_types.h
17275@@ -8,7 +8,7 @@
17276 */
17277 #ifdef CONFIG_X86_PAE
17278 # include <asm/pgtable-3level_types.h>
17279-# define PMD_SIZE (1UL << PMD_SHIFT)
17280+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17281 # define PMD_MASK (~(PMD_SIZE - 1))
17282 #else
17283 # include <asm/pgtable-2level_types.h>
17284@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17285 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17286 #endif
17287
17288+#ifdef CONFIG_PAX_KERNEXEC
17289+#ifndef __ASSEMBLY__
17290+extern unsigned char MODULES_EXEC_VADDR[];
17291+extern unsigned char MODULES_EXEC_END[];
17292+#endif
17293+#include <asm/boot.h>
17294+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17295+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17296+#else
17297+#define ktla_ktva(addr) (addr)
17298+#define ktva_ktla(addr) (addr)
17299+#endif
17300+
17301 #define MODULES_VADDR VMALLOC_START
17302 #define MODULES_END VMALLOC_END
17303 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17304diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17305index e22c1db..23a625a 100644
17306--- a/arch/x86/include/asm/pgtable_64.h
17307+++ b/arch/x86/include/asm/pgtable_64.h
17308@@ -16,10 +16,14 @@
17309
17310 extern pud_t level3_kernel_pgt[512];
17311 extern pud_t level3_ident_pgt[512];
17312+extern pud_t level3_vmalloc_start_pgt[512];
17313+extern pud_t level3_vmalloc_end_pgt[512];
17314+extern pud_t level3_vmemmap_pgt[512];
17315+extern pud_t level2_vmemmap_pgt[512];
17316 extern pmd_t level2_kernel_pgt[512];
17317 extern pmd_t level2_fixmap_pgt[512];
17318-extern pmd_t level2_ident_pgt[512];
17319-extern pgd_t init_level4_pgt[];
17320+extern pmd_t level2_ident_pgt[512*2];
17321+extern pgd_t init_level4_pgt[512];
17322
17323 #define swapper_pg_dir init_level4_pgt
17324
17325@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17326
17327 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17328 {
17329+ pax_open_kernel();
17330 *pmdp = pmd;
17331+ pax_close_kernel();
17332 }
17333
17334 static inline void native_pmd_clear(pmd_t *pmd)
17335@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17336
17337 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17338 {
17339+ pax_open_kernel();
17340 *pudp = pud;
17341+ pax_close_kernel();
17342 }
17343
17344 static inline void native_pud_clear(pud_t *pud)
17345@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17346
17347 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17348 {
17349+ pax_open_kernel();
17350+ *pgdp = pgd;
17351+ pax_close_kernel();
17352+}
17353+
17354+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17355+{
17356 *pgdp = pgd;
17357 }
17358
17359diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17360index 2d88344..4679fc3 100644
17361--- a/arch/x86/include/asm/pgtable_64_types.h
17362+++ b/arch/x86/include/asm/pgtable_64_types.h
17363@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17364 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17365 #define MODULES_END _AC(0xffffffffff000000, UL)
17366 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17367+#define MODULES_EXEC_VADDR MODULES_VADDR
17368+#define MODULES_EXEC_END MODULES_END
17369+
17370+#define ktla_ktva(addr) (addr)
17371+#define ktva_ktla(addr) (addr)
17372
17373 #define EARLY_DYNAMIC_PAGE_TABLES 64
17374
17375diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17376index 0ecac25..7a15e09 100644
17377--- a/arch/x86/include/asm/pgtable_types.h
17378+++ b/arch/x86/include/asm/pgtable_types.h
17379@@ -16,13 +16,12 @@
17380 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17381 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17382 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17383-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17384+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17385 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17386 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17387 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17388-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17389-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17390-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17391+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17392+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17393 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17394
17395 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17396@@ -40,7 +39,6 @@
17397 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17398 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17399 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17400-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17401 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17402 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17403 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17404@@ -87,8 +85,10 @@
17405
17406 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17407 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17408-#else
17409+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17410 #define _PAGE_NX (_AT(pteval_t, 0))
17411+#else
17412+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17413 #endif
17414
17415 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17416@@ -146,6 +146,9 @@
17417 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17418 _PAGE_ACCESSED)
17419
17420+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17421+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17422+
17423 #define __PAGE_KERNEL_EXEC \
17424 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17425 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17426@@ -156,7 +159,7 @@
17427 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17428 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17429 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17430-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17431+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17432 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17433 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17434 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17435@@ -218,8 +221,8 @@
17436 * bits are combined, this will alow user to access the high address mapped
17437 * VDSO in the presence of CONFIG_COMPAT_VDSO
17438 */
17439-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17440-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17441+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17442+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17443 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17444 #endif
17445
17446@@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17447 {
17448 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17449 }
17450+#endif
17451
17452+#if PAGETABLE_LEVELS == 3
17453+#include <asm-generic/pgtable-nopud.h>
17454+#endif
17455+
17456+#if PAGETABLE_LEVELS == 2
17457+#include <asm-generic/pgtable-nopmd.h>
17458+#endif
17459+
17460+#ifndef __ASSEMBLY__
17461 #if PAGETABLE_LEVELS > 3
17462 typedef struct { pudval_t pud; } pud_t;
17463
17464@@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17465 return pud.pud;
17466 }
17467 #else
17468-#include <asm-generic/pgtable-nopud.h>
17469-
17470 static inline pudval_t native_pud_val(pud_t pud)
17471 {
17472 return native_pgd_val(pud.pgd);
17473@@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17474 return pmd.pmd;
17475 }
17476 #else
17477-#include <asm-generic/pgtable-nopmd.h>
17478-
17479 static inline pmdval_t native_pmd_val(pmd_t pmd)
17480 {
17481 return native_pgd_val(pmd.pud.pgd);
17482@@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
17483
17484 extern pteval_t __supported_pte_mask;
17485 extern void set_nx(void);
17486-extern int nx_enabled;
17487
17488 #define pgprot_writecombine pgprot_writecombine
17489 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17490diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17491index c8b0519..fd29e73 100644
17492--- a/arch/x86/include/asm/preempt.h
17493+++ b/arch/x86/include/asm/preempt.h
17494@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17495 */
17496 static __always_inline bool __preempt_count_dec_and_test(void)
17497 {
17498- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17499+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17500 }
17501
17502 /*
17503diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17504index 7b034a4..4fe3e3f 100644
17505--- a/arch/x86/include/asm/processor.h
17506+++ b/arch/x86/include/asm/processor.h
17507@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17508 /* Index into per_cpu list: */
17509 u16 cpu_index;
17510 u32 microcode;
17511-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17512+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17513
17514 #define X86_VENDOR_INTEL 0
17515 #define X86_VENDOR_CYRIX 1
17516@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17517 : "memory");
17518 }
17519
17520+/* invpcid (%rdx),%rax */
17521+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17522+
17523+#define INVPCID_SINGLE_ADDRESS 0UL
17524+#define INVPCID_SINGLE_CONTEXT 1UL
17525+#define INVPCID_ALL_GLOBAL 2UL
17526+#define INVPCID_ALL_MONGLOBAL 3UL
17527+
17528+#define PCID_KERNEL 0UL
17529+#define PCID_USER 1UL
17530+#define PCID_NOFLUSH (1UL << 63)
17531+
17532 static inline void load_cr3(pgd_t *pgdir)
17533 {
17534- write_cr3(__pa(pgdir));
17535+ write_cr3(__pa(pgdir) | PCID_KERNEL);
17536 }
17537
17538 #ifdef CONFIG_X86_32
17539@@ -283,7 +295,7 @@ struct tss_struct {
17540
17541 } ____cacheline_aligned;
17542
17543-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17544+extern struct tss_struct init_tss[NR_CPUS];
17545
17546 /*
17547 * Save the original ist values for checking stack pointers during debugging
17548@@ -453,6 +465,7 @@ struct thread_struct {
17549 unsigned short ds;
17550 unsigned short fsindex;
17551 unsigned short gsindex;
17552+ unsigned short ss;
17553 #endif
17554 #ifdef CONFIG_X86_32
17555 unsigned long ip;
17556@@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
17557 extern unsigned long mmu_cr4_features;
17558 extern u32 *trampoline_cr4_features;
17559
17560-static inline void set_in_cr4(unsigned long mask)
17561-{
17562- unsigned long cr4;
17563-
17564- mmu_cr4_features |= mask;
17565- if (trampoline_cr4_features)
17566- *trampoline_cr4_features = mmu_cr4_features;
17567- cr4 = read_cr4();
17568- cr4 |= mask;
17569- write_cr4(cr4);
17570-}
17571-
17572-static inline void clear_in_cr4(unsigned long mask)
17573-{
17574- unsigned long cr4;
17575-
17576- mmu_cr4_features &= ~mask;
17577- if (trampoline_cr4_features)
17578- *trampoline_cr4_features = mmu_cr4_features;
17579- cr4 = read_cr4();
17580- cr4 &= ~mask;
17581- write_cr4(cr4);
17582-}
17583+extern void set_in_cr4(unsigned long mask);
17584+extern void clear_in_cr4(unsigned long mask);
17585
17586 typedef struct {
17587 unsigned long seg;
17588@@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
17589 */
17590 #define TASK_SIZE PAGE_OFFSET
17591 #define TASK_SIZE_MAX TASK_SIZE
17592+
17593+#ifdef CONFIG_PAX_SEGMEXEC
17594+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17595+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17596+#else
17597 #define STACK_TOP TASK_SIZE
17598-#define STACK_TOP_MAX STACK_TOP
17599+#endif
17600+
17601+#define STACK_TOP_MAX TASK_SIZE
17602
17603 #define INIT_THREAD { \
17604- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17605+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17606 .vm86_info = NULL, \
17607 .sysenter_cs = __KERNEL_CS, \
17608 .io_bitmap_ptr = NULL, \
17609@@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
17610 */
17611 #define INIT_TSS { \
17612 .x86_tss = { \
17613- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17614+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17615 .ss0 = __KERNEL_DS, \
17616 .ss1 = __KERNEL_CS, \
17617 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17618@@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
17619 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17620
17621 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17622-#define KSTK_TOP(info) \
17623-({ \
17624- unsigned long *__ptr = (unsigned long *)(info); \
17625- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17626-})
17627+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17628
17629 /*
17630 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17631@@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17632 #define task_pt_regs(task) \
17633 ({ \
17634 struct pt_regs *__regs__; \
17635- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17636+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17637 __regs__ - 1; \
17638 })
17639
17640@@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17641 /*
17642 * User space process size. 47bits minus one guard page.
17643 */
17644-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17645+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17646
17647 /* This decides where the kernel will search for a free chunk of vm
17648 * space during mmap's.
17649 */
17650 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17651- 0xc0000000 : 0xFFFFe000)
17652+ 0xc0000000 : 0xFFFFf000)
17653
17654 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17655 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17656@@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17657 #define STACK_TOP_MAX TASK_SIZE_MAX
17658
17659 #define INIT_THREAD { \
17660- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17661+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17662 }
17663
17664 #define INIT_TSS { \
17665- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17666+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17667 }
17668
17669 /*
17670@@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17671 */
17672 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17673
17674+#ifdef CONFIG_PAX_SEGMEXEC
17675+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17676+#endif
17677+
17678 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17679
17680 /* Get/set a process' ability to use the timestamp counter instruction */
17681@@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17682 return 0;
17683 }
17684
17685-extern unsigned long arch_align_stack(unsigned long sp);
17686+#define arch_align_stack(x) ((x) & ~0xfUL)
17687 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17688
17689 void default_idle(void);
17690@@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
17691 #define xen_set_default_idle 0
17692 #endif
17693
17694-void stop_this_cpu(void *dummy);
17695+void stop_this_cpu(void *dummy) __noreturn;
17696 void df_debug(struct pt_regs *regs, long error_code);
17697 #endif /* _ASM_X86_PROCESSOR_H */
17698diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17699index 942a086..6c26446 100644
17700--- a/arch/x86/include/asm/ptrace.h
17701+++ b/arch/x86/include/asm/ptrace.h
17702@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17703 }
17704
17705 /*
17706- * user_mode_vm(regs) determines whether a register set came from user mode.
17707+ * user_mode(regs) determines whether a register set came from user mode.
17708 * This is true if V8086 mode was enabled OR if the register set was from
17709 * protected mode with RPL-3 CS value. This tricky test checks that with
17710 * one comparison. Many places in the kernel can bypass this full check
17711- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17712+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17713+ * be used.
17714 */
17715-static inline int user_mode(struct pt_regs *regs)
17716+static inline int user_mode_novm(struct pt_regs *regs)
17717 {
17718 #ifdef CONFIG_X86_32
17719 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17720 #else
17721- return !!(regs->cs & 3);
17722+ return !!(regs->cs & SEGMENT_RPL_MASK);
17723 #endif
17724 }
17725
17726-static inline int user_mode_vm(struct pt_regs *regs)
17727+static inline int user_mode(struct pt_regs *regs)
17728 {
17729 #ifdef CONFIG_X86_32
17730 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17731 USER_RPL;
17732 #else
17733- return user_mode(regs);
17734+ return user_mode_novm(regs);
17735 #endif
17736 }
17737
17738@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17739 #ifdef CONFIG_X86_64
17740 static inline bool user_64bit_mode(struct pt_regs *regs)
17741 {
17742+ unsigned long cs = regs->cs & 0xffff;
17743 #ifndef CONFIG_PARAVIRT
17744 /*
17745 * On non-paravirt systems, this is the only long mode CPL 3
17746 * selector. We do not allow long mode selectors in the LDT.
17747 */
17748- return regs->cs == __USER_CS;
17749+ return cs == __USER_CS;
17750 #else
17751 /* Headers are too twisted for this to go in paravirt.h. */
17752- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17753+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17754 #endif
17755 }
17756
17757@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17758 * Traps from the kernel do not save sp and ss.
17759 * Use the helper function to retrieve sp.
17760 */
17761- if (offset == offsetof(struct pt_regs, sp) &&
17762- regs->cs == __KERNEL_CS)
17763- return kernel_stack_pointer(regs);
17764+ if (offset == offsetof(struct pt_regs, sp)) {
17765+ unsigned long cs = regs->cs & 0xffff;
17766+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17767+ return kernel_stack_pointer(regs);
17768+ }
17769 #endif
17770 return *(unsigned long *)((unsigned long)regs + offset);
17771 }
17772diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17773index 9c6b890..5305f53 100644
17774--- a/arch/x86/include/asm/realmode.h
17775+++ b/arch/x86/include/asm/realmode.h
17776@@ -22,16 +22,14 @@ struct real_mode_header {
17777 #endif
17778 /* APM/BIOS reboot */
17779 u32 machine_real_restart_asm;
17780-#ifdef CONFIG_X86_64
17781 u32 machine_real_restart_seg;
17782-#endif
17783 };
17784
17785 /* This must match data at trampoline_32/64.S */
17786 struct trampoline_header {
17787 #ifdef CONFIG_X86_32
17788 u32 start;
17789- u16 gdt_pad;
17790+ u16 boot_cs;
17791 u16 gdt_limit;
17792 u32 gdt_base;
17793 #else
17794diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17795index a82c4f1..ac45053 100644
17796--- a/arch/x86/include/asm/reboot.h
17797+++ b/arch/x86/include/asm/reboot.h
17798@@ -6,13 +6,13 @@
17799 struct pt_regs;
17800
17801 struct machine_ops {
17802- void (*restart)(char *cmd);
17803- void (*halt)(void);
17804- void (*power_off)(void);
17805+ void (* __noreturn restart)(char *cmd);
17806+ void (* __noreturn halt)(void);
17807+ void (* __noreturn power_off)(void);
17808 void (*shutdown)(void);
17809 void (*crash_shutdown)(struct pt_regs *);
17810- void (*emergency_restart)(void);
17811-};
17812+ void (* __noreturn emergency_restart)(void);
17813+} __no_const;
17814
17815 extern struct machine_ops machine_ops;
17816
17817diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
17818index 8f7866a..e442f20 100644
17819--- a/arch/x86/include/asm/rmwcc.h
17820+++ b/arch/x86/include/asm/rmwcc.h
17821@@ -3,7 +3,34 @@
17822
17823 #ifdef CC_HAVE_ASM_GOTO
17824
17825-#define __GEN_RMWcc(fullop, var, cc, ...) \
17826+#ifdef CONFIG_PAX_REFCOUNT
17827+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17828+do { \
17829+ asm_volatile_goto (fullop \
17830+ ";jno 0f\n" \
17831+ fullantiop \
17832+ ";int $4\n0:\n" \
17833+ _ASM_EXTABLE(0b, 0b) \
17834+ ";j" cc " %l[cc_label]" \
17835+ : : "m" (var), ## __VA_ARGS__ \
17836+ : "memory" : cc_label); \
17837+ return 0; \
17838+cc_label: \
17839+ return 1; \
17840+} while (0)
17841+#else
17842+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17843+do { \
17844+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
17845+ : : "m" (var), ## __VA_ARGS__ \
17846+ : "memory" : cc_label); \
17847+ return 0; \
17848+cc_label: \
17849+ return 1; \
17850+} while (0)
17851+#endif
17852+
17853+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17854 do { \
17855 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
17856 : : "m" (var), ## __VA_ARGS__ \
17857@@ -13,15 +40,46 @@ cc_label: \
17858 return 1; \
17859 } while (0)
17860
17861-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17862- __GEN_RMWcc(op " " arg0, var, cc)
17863+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17864+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17865
17866-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17867- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
17868+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17869+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17870+
17871+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17872+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
17873+
17874+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17875+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
17876
17877 #else /* !CC_HAVE_ASM_GOTO */
17878
17879-#define __GEN_RMWcc(fullop, var, cc, ...) \
17880+#ifdef CONFIG_PAX_REFCOUNT
17881+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17882+do { \
17883+ char c; \
17884+ asm volatile (fullop \
17885+ ";jno 0f\n" \
17886+ fullantiop \
17887+ ";int $4\n0:\n" \
17888+ _ASM_EXTABLE(0b, 0b) \
17889+ "; set" cc " %1" \
17890+ : "+m" (var), "=qm" (c) \
17891+ : __VA_ARGS__ : "memory"); \
17892+ return c != 0; \
17893+} while (0)
17894+#else
17895+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17896+do { \
17897+ char c; \
17898+ asm volatile (fullop "; set" cc " %1" \
17899+ : "+m" (var), "=qm" (c) \
17900+ : __VA_ARGS__ : "memory"); \
17901+ return c != 0; \
17902+} while (0)
17903+#endif
17904+
17905+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17906 do { \
17907 char c; \
17908 asm volatile (fullop "; set" cc " %1" \
17909@@ -30,11 +88,17 @@ do { \
17910 return c != 0; \
17911 } while (0)
17912
17913-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17914- __GEN_RMWcc(op " " arg0, var, cc)
17915+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17916+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17917+
17918+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17919+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17920+
17921+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17922+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
17923
17924-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17925- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
17926+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17927+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
17928
17929 #endif /* CC_HAVE_ASM_GOTO */
17930
17931diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17932index cad82c9..2e5c5c1 100644
17933--- a/arch/x86/include/asm/rwsem.h
17934+++ b/arch/x86/include/asm/rwsem.h
17935@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17936 {
17937 asm volatile("# beginning down_read\n\t"
17938 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17939+
17940+#ifdef CONFIG_PAX_REFCOUNT
17941+ "jno 0f\n"
17942+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17943+ "int $4\n0:\n"
17944+ _ASM_EXTABLE(0b, 0b)
17945+#endif
17946+
17947 /* adds 0x00000001 */
17948 " jns 1f\n"
17949 " call call_rwsem_down_read_failed\n"
17950@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17951 "1:\n\t"
17952 " mov %1,%2\n\t"
17953 " add %3,%2\n\t"
17954+
17955+#ifdef CONFIG_PAX_REFCOUNT
17956+ "jno 0f\n"
17957+ "sub %3,%2\n"
17958+ "int $4\n0:\n"
17959+ _ASM_EXTABLE(0b, 0b)
17960+#endif
17961+
17962 " jle 2f\n\t"
17963 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17964 " jnz 1b\n\t"
17965@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17966 long tmp;
17967 asm volatile("# beginning down_write\n\t"
17968 LOCK_PREFIX " xadd %1,(%2)\n\t"
17969+
17970+#ifdef CONFIG_PAX_REFCOUNT
17971+ "jno 0f\n"
17972+ "mov %1,(%2)\n"
17973+ "int $4\n0:\n"
17974+ _ASM_EXTABLE(0b, 0b)
17975+#endif
17976+
17977 /* adds 0xffff0001, returns the old value */
17978 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17979 /* was the active mask 0 before? */
17980@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17981 long tmp;
17982 asm volatile("# beginning __up_read\n\t"
17983 LOCK_PREFIX " xadd %1,(%2)\n\t"
17984+
17985+#ifdef CONFIG_PAX_REFCOUNT
17986+ "jno 0f\n"
17987+ "mov %1,(%2)\n"
17988+ "int $4\n0:\n"
17989+ _ASM_EXTABLE(0b, 0b)
17990+#endif
17991+
17992 /* subtracts 1, returns the old value */
17993 " jns 1f\n\t"
17994 " call call_rwsem_wake\n" /* expects old value in %edx */
17995@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17996 long tmp;
17997 asm volatile("# beginning __up_write\n\t"
17998 LOCK_PREFIX " xadd %1,(%2)\n\t"
17999+
18000+#ifdef CONFIG_PAX_REFCOUNT
18001+ "jno 0f\n"
18002+ "mov %1,(%2)\n"
18003+ "int $4\n0:\n"
18004+ _ASM_EXTABLE(0b, 0b)
18005+#endif
18006+
18007 /* subtracts 0xffff0001, returns the old value */
18008 " jns 1f\n\t"
18009 " call call_rwsem_wake\n" /* expects old value in %edx */
18010@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18011 {
18012 asm volatile("# beginning __downgrade_write\n\t"
18013 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18014+
18015+#ifdef CONFIG_PAX_REFCOUNT
18016+ "jno 0f\n"
18017+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18018+ "int $4\n0:\n"
18019+ _ASM_EXTABLE(0b, 0b)
18020+#endif
18021+
18022 /*
18023 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18024 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18025@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18026 */
18027 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18028 {
18029- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18030+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18031+
18032+#ifdef CONFIG_PAX_REFCOUNT
18033+ "jno 0f\n"
18034+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18035+ "int $4\n0:\n"
18036+ _ASM_EXTABLE(0b, 0b)
18037+#endif
18038+
18039 : "+m" (sem->count)
18040 : "er" (delta));
18041 }
18042@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18043 */
18044 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18045 {
18046- return delta + xadd(&sem->count, delta);
18047+ return delta + xadd_check_overflow(&sem->count, delta);
18048 }
18049
18050 #endif /* __KERNEL__ */
18051diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18052index 6f1c3a8..7744f19 100644
18053--- a/arch/x86/include/asm/segment.h
18054+++ b/arch/x86/include/asm/segment.h
18055@@ -64,10 +64,15 @@
18056 * 26 - ESPFIX small SS
18057 * 27 - per-cpu [ offset to per-cpu data area ]
18058 * 28 - stack_canary-20 [ for stack protector ]
18059- * 29 - unused
18060- * 30 - unused
18061+ * 29 - PCI BIOS CS
18062+ * 30 - PCI BIOS DS
18063 * 31 - TSS for double fault handler
18064 */
18065+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18066+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18067+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18068+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18069+
18070 #define GDT_ENTRY_TLS_MIN 6
18071 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18072
18073@@ -79,6 +84,8 @@
18074
18075 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18076
18077+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18078+
18079 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18080
18081 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18082@@ -104,6 +111,12 @@
18083 #define __KERNEL_STACK_CANARY 0
18084 #endif
18085
18086+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18087+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18088+
18089+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18090+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18091+
18092 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18093
18094 /*
18095@@ -141,7 +154,7 @@
18096 */
18097
18098 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18099-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18100+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18101
18102
18103 #else
18104@@ -165,6 +178,8 @@
18105 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18106 #define __USER32_DS __USER_DS
18107
18108+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18109+
18110 #define GDT_ENTRY_TSS 8 /* needs two entries */
18111 #define GDT_ENTRY_LDT 10 /* needs two entries */
18112 #define GDT_ENTRY_TLS_MIN 12
18113@@ -173,6 +188,8 @@
18114 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18115 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18116
18117+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18118+
18119 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18120 #define FS_TLS 0
18121 #define GS_TLS 1
18122@@ -180,12 +197,14 @@
18123 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18124 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18125
18126-#define GDT_ENTRIES 16
18127+#define GDT_ENTRIES 17
18128
18129 #endif
18130
18131 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18132+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18133 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18134+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18135 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18136 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18137 #ifndef CONFIG_PARAVIRT
18138@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18139 {
18140 unsigned long __limit;
18141 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18142- return __limit + 1;
18143+ return __limit;
18144 }
18145
18146 #endif /* !__ASSEMBLY__ */
18147diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18148index 8d3120f..352b440 100644
18149--- a/arch/x86/include/asm/smap.h
18150+++ b/arch/x86/include/asm/smap.h
18151@@ -25,11 +25,40 @@
18152
18153 #include <asm/alternative-asm.h>
18154
18155+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18156+#define ASM_PAX_OPEN_USERLAND \
18157+ 661: jmp 663f; \
18158+ .pushsection .altinstr_replacement, "a" ; \
18159+ 662: pushq %rax; nop; \
18160+ .popsection ; \
18161+ .pushsection .altinstructions, "a" ; \
18162+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18163+ .popsection ; \
18164+ call __pax_open_userland; \
18165+ popq %rax; \
18166+ 663:
18167+
18168+#define ASM_PAX_CLOSE_USERLAND \
18169+ 661: jmp 663f; \
18170+ .pushsection .altinstr_replacement, "a" ; \
18171+ 662: pushq %rax; nop; \
18172+ .popsection; \
18173+ .pushsection .altinstructions, "a" ; \
18174+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18175+ .popsection; \
18176+ call __pax_close_userland; \
18177+ popq %rax; \
18178+ 663:
18179+#else
18180+#define ASM_PAX_OPEN_USERLAND
18181+#define ASM_PAX_CLOSE_USERLAND
18182+#endif
18183+
18184 #ifdef CONFIG_X86_SMAP
18185
18186 #define ASM_CLAC \
18187 661: ASM_NOP3 ; \
18188- .pushsection .altinstr_replacement, "ax" ; \
18189+ .pushsection .altinstr_replacement, "a" ; \
18190 662: __ASM_CLAC ; \
18191 .popsection ; \
18192 .pushsection .altinstructions, "a" ; \
18193@@ -38,7 +67,7 @@
18194
18195 #define ASM_STAC \
18196 661: ASM_NOP3 ; \
18197- .pushsection .altinstr_replacement, "ax" ; \
18198+ .pushsection .altinstr_replacement, "a" ; \
18199 662: __ASM_STAC ; \
18200 .popsection ; \
18201 .pushsection .altinstructions, "a" ; \
18202@@ -56,6 +85,37 @@
18203
18204 #include <asm/alternative.h>
18205
18206+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18207+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18208+
18209+extern void __pax_open_userland(void);
18210+static __always_inline unsigned long pax_open_userland(void)
18211+{
18212+
18213+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18214+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18215+ :
18216+ : [open] "i" (__pax_open_userland)
18217+ : "memory", "rax");
18218+#endif
18219+
18220+ return 0;
18221+}
18222+
18223+extern void __pax_close_userland(void);
18224+static __always_inline unsigned long pax_close_userland(void)
18225+{
18226+
18227+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18228+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18229+ :
18230+ : [close] "i" (__pax_close_userland)
18231+ : "memory", "rax");
18232+#endif
18233+
18234+ return 0;
18235+}
18236+
18237 #ifdef CONFIG_X86_SMAP
18238
18239 static __always_inline void clac(void)
18240diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18241index 4137890..03fa172 100644
18242--- a/arch/x86/include/asm/smp.h
18243+++ b/arch/x86/include/asm/smp.h
18244@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18245 /* cpus sharing the last level cache: */
18246 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18247 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18248-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18249+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18250
18251 static inline struct cpumask *cpu_sibling_mask(int cpu)
18252 {
18253@@ -79,7 +79,7 @@ struct smp_ops {
18254
18255 void (*send_call_func_ipi)(const struct cpumask *mask);
18256 void (*send_call_func_single_ipi)(int cpu);
18257-};
18258+} __no_const;
18259
18260 /* Globals due to paravirt */
18261 extern void set_cpu_sibling_map(int cpu);
18262@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18263 extern int safe_smp_processor_id(void);
18264
18265 #elif defined(CONFIG_X86_64_SMP)
18266-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18267-
18268-#define stack_smp_processor_id() \
18269-({ \
18270- struct thread_info *ti; \
18271- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18272- ti->cpu; \
18273-})
18274+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18275+#define stack_smp_processor_id() raw_smp_processor_id()
18276 #define safe_smp_processor_id() smp_processor_id()
18277
18278 #endif
18279diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18280index bf156de..1a782ab 100644
18281--- a/arch/x86/include/asm/spinlock.h
18282+++ b/arch/x86/include/asm/spinlock.h
18283@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18284 static inline void arch_read_lock(arch_rwlock_t *rw)
18285 {
18286 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18287+
18288+#ifdef CONFIG_PAX_REFCOUNT
18289+ "jno 0f\n"
18290+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18291+ "int $4\n0:\n"
18292+ _ASM_EXTABLE(0b, 0b)
18293+#endif
18294+
18295 "jns 1f\n"
18296 "call __read_lock_failed\n\t"
18297 "1:\n"
18298@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18299 static inline void arch_write_lock(arch_rwlock_t *rw)
18300 {
18301 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18302+
18303+#ifdef CONFIG_PAX_REFCOUNT
18304+ "jno 0f\n"
18305+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18306+ "int $4\n0:\n"
18307+ _ASM_EXTABLE(0b, 0b)
18308+#endif
18309+
18310 "jz 1f\n"
18311 "call __write_lock_failed\n\t"
18312 "1:\n"
18313@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18314
18315 static inline void arch_read_unlock(arch_rwlock_t *rw)
18316 {
18317- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18318+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18319+
18320+#ifdef CONFIG_PAX_REFCOUNT
18321+ "jno 0f\n"
18322+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18323+ "int $4\n0:\n"
18324+ _ASM_EXTABLE(0b, 0b)
18325+#endif
18326+
18327 :"+m" (rw->lock) : : "memory");
18328 }
18329
18330 static inline void arch_write_unlock(arch_rwlock_t *rw)
18331 {
18332- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18333+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18334+
18335+#ifdef CONFIG_PAX_REFCOUNT
18336+ "jno 0f\n"
18337+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18338+ "int $4\n0:\n"
18339+ _ASM_EXTABLE(0b, 0b)
18340+#endif
18341+
18342 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18343 }
18344
18345diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18346index 6a99859..03cb807 100644
18347--- a/arch/x86/include/asm/stackprotector.h
18348+++ b/arch/x86/include/asm/stackprotector.h
18349@@ -47,7 +47,7 @@
18350 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18351 */
18352 #define GDT_STACK_CANARY_INIT \
18353- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18354+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18355
18356 /*
18357 * Initialize the stackprotector canary value.
18358@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18359
18360 static inline void load_stack_canary_segment(void)
18361 {
18362-#ifdef CONFIG_X86_32
18363+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18364 asm volatile ("mov %0, %%gs" : : "r" (0));
18365 #endif
18366 }
18367diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18368index 70bbe39..4ae2bd4 100644
18369--- a/arch/x86/include/asm/stacktrace.h
18370+++ b/arch/x86/include/asm/stacktrace.h
18371@@ -11,28 +11,20 @@
18372
18373 extern int kstack_depth_to_print;
18374
18375-struct thread_info;
18376+struct task_struct;
18377 struct stacktrace_ops;
18378
18379-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18380- unsigned long *stack,
18381- unsigned long bp,
18382- const struct stacktrace_ops *ops,
18383- void *data,
18384- unsigned long *end,
18385- int *graph);
18386+typedef unsigned long walk_stack_t(struct task_struct *task,
18387+ void *stack_start,
18388+ unsigned long *stack,
18389+ unsigned long bp,
18390+ const struct stacktrace_ops *ops,
18391+ void *data,
18392+ unsigned long *end,
18393+ int *graph);
18394
18395-extern unsigned long
18396-print_context_stack(struct thread_info *tinfo,
18397- unsigned long *stack, unsigned long bp,
18398- const struct stacktrace_ops *ops, void *data,
18399- unsigned long *end, int *graph);
18400-
18401-extern unsigned long
18402-print_context_stack_bp(struct thread_info *tinfo,
18403- unsigned long *stack, unsigned long bp,
18404- const struct stacktrace_ops *ops, void *data,
18405- unsigned long *end, int *graph);
18406+extern walk_stack_t print_context_stack;
18407+extern walk_stack_t print_context_stack_bp;
18408
18409 /* Generic stack tracer with callbacks */
18410
18411@@ -40,7 +32,7 @@ struct stacktrace_ops {
18412 void (*address)(void *data, unsigned long address, int reliable);
18413 /* On negative return stop dumping */
18414 int (*stack)(void *data, char *name);
18415- walk_stack_t walk_stack;
18416+ walk_stack_t *walk_stack;
18417 };
18418
18419 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18420diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18421index d7f3b3b..3cc39f1 100644
18422--- a/arch/x86/include/asm/switch_to.h
18423+++ b/arch/x86/include/asm/switch_to.h
18424@@ -108,7 +108,7 @@ do { \
18425 "call __switch_to\n\t" \
18426 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18427 __switch_canary \
18428- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18429+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18430 "movq %%rax,%%rdi\n\t" \
18431 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18432 "jnz ret_from_fork\n\t" \
18433@@ -119,7 +119,7 @@ do { \
18434 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18435 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18436 [_tif_fork] "i" (_TIF_FORK), \
18437- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18438+ [thread_info] "m" (current_tinfo), \
18439 [current_task] "m" (current_task) \
18440 __switch_canary_iparam \
18441 : "memory", "cc" __EXTRA_CLOBBER)
18442diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18443index 3ba3de4..6c113b2 100644
18444--- a/arch/x86/include/asm/thread_info.h
18445+++ b/arch/x86/include/asm/thread_info.h
18446@@ -10,6 +10,7 @@
18447 #include <linux/compiler.h>
18448 #include <asm/page.h>
18449 #include <asm/types.h>
18450+#include <asm/percpu.h>
18451
18452 /*
18453 * low level task data that entry.S needs immediate access to
18454@@ -23,7 +24,6 @@ struct exec_domain;
18455 #include <linux/atomic.h>
18456
18457 struct thread_info {
18458- struct task_struct *task; /* main task structure */
18459 struct exec_domain *exec_domain; /* execution domain */
18460 __u32 flags; /* low level flags */
18461 __u32 status; /* thread synchronous flags */
18462@@ -32,19 +32,13 @@ struct thread_info {
18463 mm_segment_t addr_limit;
18464 struct restart_block restart_block;
18465 void __user *sysenter_return;
18466-#ifdef CONFIG_X86_32
18467- unsigned long previous_esp; /* ESP of the previous stack in
18468- case of nested (IRQ) stacks
18469- */
18470- __u8 supervisor_stack[0];
18471-#endif
18472+ unsigned long lowest_stack;
18473 unsigned int sig_on_uaccess_error:1;
18474 unsigned int uaccess_err:1; /* uaccess failed */
18475 };
18476
18477-#define INIT_THREAD_INFO(tsk) \
18478+#define INIT_THREAD_INFO \
18479 { \
18480- .task = &tsk, \
18481 .exec_domain = &default_exec_domain, \
18482 .flags = 0, \
18483 .cpu = 0, \
18484@@ -55,7 +49,7 @@ struct thread_info {
18485 }, \
18486 }
18487
18488-#define init_thread_info (init_thread_union.thread_info)
18489+#define init_thread_info (init_thread_union.stack)
18490 #define init_stack (init_thread_union.stack)
18491
18492 #else /* !__ASSEMBLY__ */
18493@@ -95,6 +89,7 @@ struct thread_info {
18494 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18495 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18496 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18497+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18498
18499 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18500 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18501@@ -118,17 +113,18 @@ struct thread_info {
18502 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18503 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18504 #define _TIF_X32 (1 << TIF_X32)
18505+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18506
18507 /* work to do in syscall_trace_enter() */
18508 #define _TIF_WORK_SYSCALL_ENTRY \
18509 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18510 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18511- _TIF_NOHZ)
18512+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18513
18514 /* work to do in syscall_trace_leave() */
18515 #define _TIF_WORK_SYSCALL_EXIT \
18516 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18517- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18518+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18519
18520 /* work to do on interrupt/exception return */
18521 #define _TIF_WORK_MASK \
18522@@ -139,7 +135,7 @@ struct thread_info {
18523 /* work to do on any return to user space */
18524 #define _TIF_ALLWORK_MASK \
18525 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18526- _TIF_NOHZ)
18527+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18528
18529 /* Only used for 64 bit */
18530 #define _TIF_DO_NOTIFY_MASK \
18531@@ -153,45 +149,40 @@ struct thread_info {
18532 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18533 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18534
18535-#ifdef CONFIG_X86_32
18536-
18537-#define STACK_WARN (THREAD_SIZE/8)
18538-/*
18539- * macros/functions for gaining access to the thread information structure
18540- *
18541- * preempt_count needs to be 1 initially, until the scheduler is functional.
18542- */
18543-#ifndef __ASSEMBLY__
18544-
18545-
18546-/* how to get the current stack pointer from C */
18547-register unsigned long current_stack_pointer asm("esp") __used;
18548-
18549-/* how to get the thread information struct from C */
18550-static inline struct thread_info *current_thread_info(void)
18551-{
18552- return (struct thread_info *)
18553- (current_stack_pointer & ~(THREAD_SIZE - 1));
18554-}
18555-
18556-#else /* !__ASSEMBLY__ */
18557-
18558+#ifdef __ASSEMBLY__
18559 /* how to get the thread information struct from ASM */
18560 #define GET_THREAD_INFO(reg) \
18561- movl $-THREAD_SIZE, reg; \
18562- andl %esp, reg
18563+ mov PER_CPU_VAR(current_tinfo), reg
18564
18565 /* use this one if reg already contains %esp */
18566-#define GET_THREAD_INFO_WITH_ESP(reg) \
18567- andl $-THREAD_SIZE, reg
18568+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18569+#else
18570+/* how to get the thread information struct from C */
18571+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18572+
18573+static __always_inline struct thread_info *current_thread_info(void)
18574+{
18575+ return this_cpu_read_stable(current_tinfo);
18576+}
18577+#endif
18578+
18579+#ifdef CONFIG_X86_32
18580+
18581+#define STACK_WARN (THREAD_SIZE/8)
18582+/*
18583+ * macros/functions for gaining access to the thread information structure
18584+ *
18585+ * preempt_count needs to be 1 initially, until the scheduler is functional.
18586+ */
18587+#ifndef __ASSEMBLY__
18588+
18589+/* how to get the current stack pointer from C */
18590+register unsigned long current_stack_pointer asm("esp") __used;
18591
18592 #endif
18593
18594 #else /* X86_32 */
18595
18596-#include <asm/percpu.h>
18597-#define KERNEL_STACK_OFFSET (5*8)
18598-
18599 /*
18600 * macros/functions for gaining access to the thread information structure
18601 * preempt_count needs to be 1 initially, until the scheduler is functional.
18602@@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
18603 #ifndef __ASSEMBLY__
18604 DECLARE_PER_CPU(unsigned long, kernel_stack);
18605
18606-static inline struct thread_info *current_thread_info(void)
18607-{
18608- struct thread_info *ti;
18609- ti = (void *)(this_cpu_read_stable(kernel_stack) +
18610- KERNEL_STACK_OFFSET - THREAD_SIZE);
18611- return ti;
18612-}
18613-
18614-#else /* !__ASSEMBLY__ */
18615-
18616-/* how to get the thread information struct from ASM */
18617-#define GET_THREAD_INFO(reg) \
18618- movq PER_CPU_VAR(kernel_stack),reg ; \
18619- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18620-
18621-/*
18622- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18623- * a certain register (to be used in assembler memory operands).
18624- */
18625-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18626-
18627+/* how to get the current stack pointer from C */
18628+register unsigned long current_stack_pointer asm("rsp") __used;
18629 #endif
18630
18631 #endif /* !X86_32 */
18632@@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
18633 extern void arch_task_cache_init(void);
18634 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18635 extern void arch_release_task_struct(struct task_struct *tsk);
18636+
18637+#define __HAVE_THREAD_FUNCTIONS
18638+#define task_thread_info(task) (&(task)->tinfo)
18639+#define task_stack_page(task) ((task)->stack)
18640+#define setup_thread_stack(p, org) do {} while (0)
18641+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18642+
18643 #endif
18644 #endif /* _ASM_X86_THREAD_INFO_H */
18645diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18646index e6d90ba..0897f44 100644
18647--- a/arch/x86/include/asm/tlbflush.h
18648+++ b/arch/x86/include/asm/tlbflush.h
18649@@ -17,18 +17,44 @@
18650
18651 static inline void __native_flush_tlb(void)
18652 {
18653+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18654+ u64 descriptor[2];
18655+
18656+ descriptor[0] = PCID_KERNEL;
18657+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18658+ return;
18659+ }
18660+
18661+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18662+ if (static_cpu_has(X86_FEATURE_PCID)) {
18663+ unsigned int cpu = raw_get_cpu();
18664+
18665+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18666+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18667+ raw_put_cpu_no_resched();
18668+ return;
18669+ }
18670+#endif
18671+
18672 native_write_cr3(native_read_cr3());
18673 }
18674
18675 static inline void __native_flush_tlb_global_irq_disabled(void)
18676 {
18677- unsigned long cr4;
18678+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18679+ u64 descriptor[2];
18680
18681- cr4 = native_read_cr4();
18682- /* clear PGE */
18683- native_write_cr4(cr4 & ~X86_CR4_PGE);
18684- /* write old PGE again and flush TLBs */
18685- native_write_cr4(cr4);
18686+ descriptor[0] = PCID_KERNEL;
18687+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18688+ } else {
18689+ unsigned long cr4;
18690+
18691+ cr4 = native_read_cr4();
18692+ /* clear PGE */
18693+ native_write_cr4(cr4 & ~X86_CR4_PGE);
18694+ /* write old PGE again and flush TLBs */
18695+ native_write_cr4(cr4);
18696+ }
18697 }
18698
18699 static inline void __native_flush_tlb_global(void)
18700@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
18701
18702 static inline void __native_flush_tlb_single(unsigned long addr)
18703 {
18704+
18705+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18706+ u64 descriptor[2];
18707+
18708+ descriptor[0] = PCID_KERNEL;
18709+ descriptor[1] = addr;
18710+
18711+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18712+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18713+ if (addr < TASK_SIZE_MAX)
18714+ descriptor[1] += pax_user_shadow_base;
18715+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18716+ }
18717+
18718+ descriptor[0] = PCID_USER;
18719+ descriptor[1] = addr;
18720+#endif
18721+
18722+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18723+ return;
18724+ }
18725+
18726+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18727+ if (static_cpu_has(X86_FEATURE_PCID)) {
18728+ unsigned int cpu = raw_get_cpu();
18729+
18730+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18731+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18732+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18733+ raw_put_cpu_no_resched();
18734+
18735+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18736+ addr += pax_user_shadow_base;
18737+ }
18738+#endif
18739+
18740 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18741 }
18742
18743diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18744index 8ec57c0..3ee58c9 100644
18745--- a/arch/x86/include/asm/uaccess.h
18746+++ b/arch/x86/include/asm/uaccess.h
18747@@ -7,6 +7,7 @@
18748 #include <linux/compiler.h>
18749 #include <linux/thread_info.h>
18750 #include <linux/string.h>
18751+#include <linux/spinlock.h>
18752 #include <asm/asm.h>
18753 #include <asm/page.h>
18754 #include <asm/smap.h>
18755@@ -29,7 +30,12 @@
18756
18757 #define get_ds() (KERNEL_DS)
18758 #define get_fs() (current_thread_info()->addr_limit)
18759+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18760+void __set_fs(mm_segment_t x);
18761+void set_fs(mm_segment_t x);
18762+#else
18763 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18764+#endif
18765
18766 #define segment_eq(a, b) ((a).seg == (b).seg)
18767
18768@@ -77,8 +83,34 @@
18769 * checks that the pointer is in the user space range - after calling
18770 * this function, memory access functions may still return -EFAULT.
18771 */
18772-#define access_ok(type, addr, size) \
18773- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18774+extern int _cond_resched(void);
18775+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18776+#define access_ok(type, addr, size) \
18777+({ \
18778+ long __size = size; \
18779+ unsigned long __addr = (unsigned long)addr; \
18780+ unsigned long __addr_ao = __addr & PAGE_MASK; \
18781+ unsigned long __end_ao = __addr + __size - 1; \
18782+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18783+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18784+ while(__addr_ao <= __end_ao) { \
18785+ char __c_ao; \
18786+ __addr_ao += PAGE_SIZE; \
18787+ if (__size > PAGE_SIZE) \
18788+ _cond_resched(); \
18789+ if (__get_user(__c_ao, (char __user *)__addr)) \
18790+ break; \
18791+ if (type != VERIFY_WRITE) { \
18792+ __addr = __addr_ao; \
18793+ continue; \
18794+ } \
18795+ if (__put_user(__c_ao, (char __user *)__addr)) \
18796+ break; \
18797+ __addr = __addr_ao; \
18798+ } \
18799+ } \
18800+ __ret_ao; \
18801+})
18802
18803 /*
18804 * The exception table consists of pairs of addresses relative to the
18805@@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18806 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18807 __chk_user_ptr(ptr); \
18808 might_fault(); \
18809+ pax_open_userland(); \
18810 asm volatile("call __get_user_%P3" \
18811 : "=a" (__ret_gu), "=r" (__val_gu) \
18812 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18813 (x) = (__typeof__(*(ptr))) __val_gu; \
18814+ pax_close_userland(); \
18815 __ret_gu; \
18816 })
18817
18818@@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18819 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18820 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18821
18822-
18823+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18824+#define __copyuser_seg "gs;"
18825+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18826+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18827+#else
18828+#define __copyuser_seg
18829+#define __COPYUSER_SET_ES
18830+#define __COPYUSER_RESTORE_ES
18831+#endif
18832
18833 #ifdef CONFIG_X86_32
18834 #define __put_user_asm_u64(x, addr, err, errret) \
18835 asm volatile(ASM_STAC "\n" \
18836- "1: movl %%eax,0(%2)\n" \
18837- "2: movl %%edx,4(%2)\n" \
18838+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18839+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18840 "3: " ASM_CLAC "\n" \
18841 ".section .fixup,\"ax\"\n" \
18842 "4: movl %3,%0\n" \
18843@@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18844
18845 #define __put_user_asm_ex_u64(x, addr) \
18846 asm volatile(ASM_STAC "\n" \
18847- "1: movl %%eax,0(%1)\n" \
18848- "2: movl %%edx,4(%1)\n" \
18849+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18850+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18851 "3: " ASM_CLAC "\n" \
18852 _ASM_EXTABLE_EX(1b, 2b) \
18853 _ASM_EXTABLE_EX(2b, 3b) \
18854@@ -249,7 +291,8 @@ extern void __put_user_8(void);
18855 __typeof__(*(ptr)) __pu_val; \
18856 __chk_user_ptr(ptr); \
18857 might_fault(); \
18858- __pu_val = x; \
18859+ __pu_val = (x); \
18860+ pax_open_userland(); \
18861 switch (sizeof(*(ptr))) { \
18862 case 1: \
18863 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18864@@ -267,6 +310,7 @@ extern void __put_user_8(void);
18865 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18866 break; \
18867 } \
18868+ pax_close_userland(); \
18869 __ret_pu; \
18870 })
18871
18872@@ -347,8 +391,10 @@ do { \
18873 } while (0)
18874
18875 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18876+do { \
18877+ pax_open_userland(); \
18878 asm volatile(ASM_STAC "\n" \
18879- "1: mov"itype" %2,%"rtype"1\n" \
18880+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18881 "2: " ASM_CLAC "\n" \
18882 ".section .fixup,\"ax\"\n" \
18883 "3: mov %3,%0\n" \
18884@@ -356,8 +402,10 @@ do { \
18885 " jmp 2b\n" \
18886 ".previous\n" \
18887 _ASM_EXTABLE(1b, 3b) \
18888- : "=r" (err), ltype(x) \
18889- : "m" (__m(addr)), "i" (errret), "0" (err))
18890+ : "=r" (err), ltype (x) \
18891+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18892+ pax_close_userland(); \
18893+} while (0)
18894
18895 #define __get_user_size_ex(x, ptr, size) \
18896 do { \
18897@@ -381,7 +429,7 @@ do { \
18898 } while (0)
18899
18900 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18901- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18902+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18903 "2:\n" \
18904 _ASM_EXTABLE_EX(1b, 2b) \
18905 : ltype(x) : "m" (__m(addr)))
18906@@ -398,13 +446,24 @@ do { \
18907 int __gu_err; \
18908 unsigned long __gu_val; \
18909 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18910- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18911+ (x) = (__typeof__(*(ptr)))__gu_val; \
18912 __gu_err; \
18913 })
18914
18915 /* FIXME: this hack is definitely wrong -AK */
18916 struct __large_struct { unsigned long buf[100]; };
18917-#define __m(x) (*(struct __large_struct __user *)(x))
18918+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18919+#define ____m(x) \
18920+({ \
18921+ unsigned long ____x = (unsigned long)(x); \
18922+ if (____x < pax_user_shadow_base) \
18923+ ____x += pax_user_shadow_base; \
18924+ (typeof(x))____x; \
18925+})
18926+#else
18927+#define ____m(x) (x)
18928+#endif
18929+#define __m(x) (*(struct __large_struct __user *)____m(x))
18930
18931 /*
18932 * Tell gcc we read from memory instead of writing: this is because
18933@@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
18934 * aliasing issues.
18935 */
18936 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18937+do { \
18938+ pax_open_userland(); \
18939 asm volatile(ASM_STAC "\n" \
18940- "1: mov"itype" %"rtype"1,%2\n" \
18941+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18942 "2: " ASM_CLAC "\n" \
18943 ".section .fixup,\"ax\"\n" \
18944 "3: mov %3,%0\n" \
18945@@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
18946 ".previous\n" \
18947 _ASM_EXTABLE(1b, 3b) \
18948 : "=r"(err) \
18949- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18950+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18951+ pax_close_userland(); \
18952+} while (0)
18953
18954 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18955- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18956+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18957 "2:\n" \
18958 _ASM_EXTABLE_EX(1b, 2b) \
18959 : : ltype(x), "m" (__m(addr)))
18960@@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
18961 */
18962 #define uaccess_try do { \
18963 current_thread_info()->uaccess_err = 0; \
18964+ pax_open_userland(); \
18965 stac(); \
18966 barrier();
18967
18968 #define uaccess_catch(err) \
18969 clac(); \
18970+ pax_close_userland(); \
18971 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18972 } while (0)
18973
18974@@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
18975 * On error, the variable @x is set to zero.
18976 */
18977
18978+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18979+#define __get_user(x, ptr) get_user((x), (ptr))
18980+#else
18981 #define __get_user(x, ptr) \
18982 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18983+#endif
18984
18985 /**
18986 * __put_user: - Write a simple value into user space, with less checking.
18987@@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
18988 * Returns zero on success, or -EFAULT on error.
18989 */
18990
18991+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18992+#define __put_user(x, ptr) put_user((x), (ptr))
18993+#else
18994 #define __put_user(x, ptr) \
18995 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18996+#endif
18997
18998 #define __get_user_unaligned __get_user
18999 #define __put_user_unaligned __put_user
19000@@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19001 #define get_user_ex(x, ptr) do { \
19002 unsigned long __gue_val; \
19003 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19004- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19005+ (x) = (__typeof__(*(ptr)))__gue_val; \
19006 } while (0)
19007
19008 #define put_user_try uaccess_try
19009@@ -536,17 +609,6 @@ extern struct movsl_mask {
19010
19011 #define ARCH_HAS_NOCACHE_UACCESS 1
19012
19013-#ifdef CONFIG_X86_32
19014-# include <asm/uaccess_32.h>
19015-#else
19016-# include <asm/uaccess_64.h>
19017-#endif
19018-
19019-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19020- unsigned n);
19021-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19022- unsigned n);
19023-
19024 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19025 # define copy_user_diag __compiletime_error
19026 #else
19027@@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19028 extern void copy_user_diag("copy_from_user() buffer size is too small")
19029 copy_from_user_overflow(void);
19030 extern void copy_user_diag("copy_to_user() buffer size is too small")
19031-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19032+copy_to_user_overflow(void);
19033
19034 #undef copy_user_diag
19035
19036@@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19037
19038 extern void
19039 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19040-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19041+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19042 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19043
19044 #else
19045@@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19046
19047 #endif
19048
19049+#ifdef CONFIG_X86_32
19050+# include <asm/uaccess_32.h>
19051+#else
19052+# include <asm/uaccess_64.h>
19053+#endif
19054+
19055 static inline unsigned long __must_check
19056 copy_from_user(void *to, const void __user *from, unsigned long n)
19057 {
19058- int sz = __compiletime_object_size(to);
19059+ size_t sz = __compiletime_object_size(to);
19060
19061 might_fault();
19062
19063@@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19064 * case, and do only runtime checking for non-constant sizes.
19065 */
19066
19067- if (likely(sz < 0 || sz >= n))
19068- n = _copy_from_user(to, from, n);
19069- else if(__builtin_constant_p(n))
19070- copy_from_user_overflow();
19071- else
19072- __copy_from_user_overflow(sz, n);
19073+ if (likely(sz != (size_t)-1 && sz < n)) {
19074+ if(__builtin_constant_p(n))
19075+ copy_from_user_overflow();
19076+ else
19077+ __copy_from_user_overflow(sz, n);
19078+ } if (access_ok(VERIFY_READ, from, n))
19079+ n = __copy_from_user(to, from, n);
19080+ else if ((long)n > 0)
19081+ memset(to, 0, n);
19082
19083 return n;
19084 }
19085@@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19086 static inline unsigned long __must_check
19087 copy_to_user(void __user *to, const void *from, unsigned long n)
19088 {
19089- int sz = __compiletime_object_size(from);
19090+ size_t sz = __compiletime_object_size(from);
19091
19092 might_fault();
19093
19094 /* See the comment in copy_from_user() above. */
19095- if (likely(sz < 0 || sz >= n))
19096- n = _copy_to_user(to, from, n);
19097- else if(__builtin_constant_p(n))
19098- copy_to_user_overflow();
19099- else
19100- __copy_to_user_overflow(sz, n);
19101+ if (likely(sz != (size_t)-1 && sz < n)) {
19102+ if(__builtin_constant_p(n))
19103+ copy_to_user_overflow();
19104+ else
19105+ __copy_to_user_overflow(sz, n);
19106+ } else if (access_ok(VERIFY_WRITE, to, n))
19107+ n = __copy_to_user(to, from, n);
19108
19109 return n;
19110 }
19111diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19112index 3c03a5d..1071638 100644
19113--- a/arch/x86/include/asm/uaccess_32.h
19114+++ b/arch/x86/include/asm/uaccess_32.h
19115@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19116 static __always_inline unsigned long __must_check
19117 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19118 {
19119+ if ((long)n < 0)
19120+ return n;
19121+
19122+ check_object_size(from, n, true);
19123+
19124 if (__builtin_constant_p(n)) {
19125 unsigned long ret;
19126
19127@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19128 __copy_to_user(void __user *to, const void *from, unsigned long n)
19129 {
19130 might_fault();
19131+
19132 return __copy_to_user_inatomic(to, from, n);
19133 }
19134
19135 static __always_inline unsigned long
19136 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19137 {
19138+ if ((long)n < 0)
19139+ return n;
19140+
19141 /* Avoid zeroing the tail if the copy fails..
19142 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19143 * but as the zeroing behaviour is only significant when n is not
19144@@ -137,6 +146,12 @@ static __always_inline unsigned long
19145 __copy_from_user(void *to, const void __user *from, unsigned long n)
19146 {
19147 might_fault();
19148+
19149+ if ((long)n < 0)
19150+ return n;
19151+
19152+ check_object_size(to, n, false);
19153+
19154 if (__builtin_constant_p(n)) {
19155 unsigned long ret;
19156
19157@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19158 const void __user *from, unsigned long n)
19159 {
19160 might_fault();
19161+
19162+ if ((long)n < 0)
19163+ return n;
19164+
19165 if (__builtin_constant_p(n)) {
19166 unsigned long ret;
19167
19168@@ -181,7 +200,10 @@ static __always_inline unsigned long
19169 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19170 unsigned long n)
19171 {
19172- return __copy_from_user_ll_nocache_nozero(to, from, n);
19173+ if ((long)n < 0)
19174+ return n;
19175+
19176+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19177 }
19178
19179 #endif /* _ASM_X86_UACCESS_32_H */
19180diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19181index 190413d..bf69468 100644
19182--- a/arch/x86/include/asm/uaccess_64.h
19183+++ b/arch/x86/include/asm/uaccess_64.h
19184@@ -10,6 +10,9 @@
19185 #include <asm/alternative.h>
19186 #include <asm/cpufeature.h>
19187 #include <asm/page.h>
19188+#include <asm/pgtable.h>
19189+
19190+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19191
19192 /*
19193 * Copy To/From Userspace
19194@@ -17,14 +20,14 @@
19195
19196 /* Handles exceptions in both to and from, but doesn't do access_ok */
19197 __must_check unsigned long
19198-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19199+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19200 __must_check unsigned long
19201-copy_user_generic_string(void *to, const void *from, unsigned len);
19202+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19203 __must_check unsigned long
19204-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19205+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19206
19207 static __always_inline __must_check unsigned long
19208-copy_user_generic(void *to, const void *from, unsigned len)
19209+copy_user_generic(void *to, const void *from, unsigned long len)
19210 {
19211 unsigned ret;
19212
19213@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19214 }
19215
19216 __must_check unsigned long
19217-copy_in_user(void __user *to, const void __user *from, unsigned len);
19218+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19219
19220 static __always_inline __must_check
19221-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19222+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19223 {
19224- int ret = 0;
19225+ size_t sz = __compiletime_object_size(dst);
19226+ unsigned ret = 0;
19227+
19228+ if (size > INT_MAX)
19229+ return size;
19230+
19231+ check_object_size(dst, size, false);
19232+
19233+#ifdef CONFIG_PAX_MEMORY_UDEREF
19234+ if (!__access_ok(VERIFY_READ, src, size))
19235+ return size;
19236+#endif
19237+
19238+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19239+ if(__builtin_constant_p(size))
19240+ copy_from_user_overflow();
19241+ else
19242+ __copy_from_user_overflow(sz, size);
19243+ return size;
19244+ }
19245
19246 if (!__builtin_constant_p(size))
19247- return copy_user_generic(dst, (__force void *)src, size);
19248+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19249 switch (size) {
19250- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19251+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19252 ret, "b", "b", "=q", 1);
19253 return ret;
19254- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19255+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19256 ret, "w", "w", "=r", 2);
19257 return ret;
19258- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19259+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19260 ret, "l", "k", "=r", 4);
19261 return ret;
19262- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19263+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19264 ret, "q", "", "=r", 8);
19265 return ret;
19266 case 10:
19267- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19268+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19269 ret, "q", "", "=r", 10);
19270 if (unlikely(ret))
19271 return ret;
19272 __get_user_asm(*(u16 *)(8 + (char *)dst),
19273- (u16 __user *)(8 + (char __user *)src),
19274+ (const u16 __user *)(8 + (const char __user *)src),
19275 ret, "w", "w", "=r", 2);
19276 return ret;
19277 case 16:
19278- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19279+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19280 ret, "q", "", "=r", 16);
19281 if (unlikely(ret))
19282 return ret;
19283 __get_user_asm(*(u64 *)(8 + (char *)dst),
19284- (u64 __user *)(8 + (char __user *)src),
19285+ (const u64 __user *)(8 + (const char __user *)src),
19286 ret, "q", "", "=r", 8);
19287 return ret;
19288 default:
19289- return copy_user_generic(dst, (__force void *)src, size);
19290+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19291 }
19292 }
19293
19294 static __always_inline __must_check
19295-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19296+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19297 {
19298 might_fault();
19299 return __copy_from_user_nocheck(dst, src, size);
19300 }
19301
19302 static __always_inline __must_check
19303-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19304+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19305 {
19306- int ret = 0;
19307+ size_t sz = __compiletime_object_size(src);
19308+ unsigned ret = 0;
19309+
19310+ if (size > INT_MAX)
19311+ return size;
19312+
19313+ check_object_size(src, size, true);
19314+
19315+#ifdef CONFIG_PAX_MEMORY_UDEREF
19316+ if (!__access_ok(VERIFY_WRITE, dst, size))
19317+ return size;
19318+#endif
19319+
19320+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19321+ if(__builtin_constant_p(size))
19322+ copy_to_user_overflow();
19323+ else
19324+ __copy_to_user_overflow(sz, size);
19325+ return size;
19326+ }
19327
19328 if (!__builtin_constant_p(size))
19329- return copy_user_generic((__force void *)dst, src, size);
19330+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19331 switch (size) {
19332- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19333+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19334 ret, "b", "b", "iq", 1);
19335 return ret;
19336- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19337+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19338 ret, "w", "w", "ir", 2);
19339 return ret;
19340- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19341+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19342 ret, "l", "k", "ir", 4);
19343 return ret;
19344- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19345+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19346 ret, "q", "", "er", 8);
19347 return ret;
19348 case 10:
19349- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19350+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19351 ret, "q", "", "er", 10);
19352 if (unlikely(ret))
19353 return ret;
19354 asm("":::"memory");
19355- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19356+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19357 ret, "w", "w", "ir", 2);
19358 return ret;
19359 case 16:
19360- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19361+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19362 ret, "q", "", "er", 16);
19363 if (unlikely(ret))
19364 return ret;
19365 asm("":::"memory");
19366- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19367+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19368 ret, "q", "", "er", 8);
19369 return ret;
19370 default:
19371- return copy_user_generic((__force void *)dst, src, size);
19372+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19373 }
19374 }
19375
19376 static __always_inline __must_check
19377-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19378+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19379 {
19380 might_fault();
19381 return __copy_to_user_nocheck(dst, src, size);
19382 }
19383
19384 static __always_inline __must_check
19385-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19386+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19387 {
19388- int ret = 0;
19389+ unsigned ret = 0;
19390
19391 might_fault();
19392+
19393+ if (size > INT_MAX)
19394+ return size;
19395+
19396+#ifdef CONFIG_PAX_MEMORY_UDEREF
19397+ if (!__access_ok(VERIFY_READ, src, size))
19398+ return size;
19399+ if (!__access_ok(VERIFY_WRITE, dst, size))
19400+ return size;
19401+#endif
19402+
19403 if (!__builtin_constant_p(size))
19404- return copy_user_generic((__force void *)dst,
19405- (__force void *)src, size);
19406+ return copy_user_generic((__force_kernel void *)____m(dst),
19407+ (__force_kernel const void *)____m(src), size);
19408 switch (size) {
19409 case 1: {
19410 u8 tmp;
19411- __get_user_asm(tmp, (u8 __user *)src,
19412+ __get_user_asm(tmp, (const u8 __user *)src,
19413 ret, "b", "b", "=q", 1);
19414 if (likely(!ret))
19415 __put_user_asm(tmp, (u8 __user *)dst,
19416@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19417 }
19418 case 2: {
19419 u16 tmp;
19420- __get_user_asm(tmp, (u16 __user *)src,
19421+ __get_user_asm(tmp, (const u16 __user *)src,
19422 ret, "w", "w", "=r", 2);
19423 if (likely(!ret))
19424 __put_user_asm(tmp, (u16 __user *)dst,
19425@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19426
19427 case 4: {
19428 u32 tmp;
19429- __get_user_asm(tmp, (u32 __user *)src,
19430+ __get_user_asm(tmp, (const u32 __user *)src,
19431 ret, "l", "k", "=r", 4);
19432 if (likely(!ret))
19433 __put_user_asm(tmp, (u32 __user *)dst,
19434@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19435 }
19436 case 8: {
19437 u64 tmp;
19438- __get_user_asm(tmp, (u64 __user *)src,
19439+ __get_user_asm(tmp, (const u64 __user *)src,
19440 ret, "q", "", "=r", 8);
19441 if (likely(!ret))
19442 __put_user_asm(tmp, (u64 __user *)dst,
19443@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19444 return ret;
19445 }
19446 default:
19447- return copy_user_generic((__force void *)dst,
19448- (__force void *)src, size);
19449+ return copy_user_generic((__force_kernel void *)____m(dst),
19450+ (__force_kernel const void *)____m(src), size);
19451 }
19452 }
19453
19454-static __must_check __always_inline int
19455-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19456+static __must_check __always_inline unsigned long
19457+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19458 {
19459- return __copy_from_user_nocheck(dst, (__force const void *)src, size);
19460+ return __copy_from_user_nocheck(dst, ____m(src), size);
19461 }
19462
19463-static __must_check __always_inline int
19464-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19465+static __must_check __always_inline unsigned long
19466+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19467 {
19468- return __copy_to_user_nocheck((__force void *)dst, src, size);
19469+ return __copy_to_user_nocheck(____m(dst), src, size);
19470 }
19471
19472-extern long __copy_user_nocache(void *dst, const void __user *src,
19473- unsigned size, int zerorest);
19474+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19475+ unsigned long size, int zerorest);
19476
19477-static inline int
19478-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19479+static inline unsigned long
19480+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19481 {
19482 might_fault();
19483+
19484+ if (size > INT_MAX)
19485+ return size;
19486+
19487+#ifdef CONFIG_PAX_MEMORY_UDEREF
19488+ if (!__access_ok(VERIFY_READ, src, size))
19489+ return size;
19490+#endif
19491+
19492 return __copy_user_nocache(dst, src, size, 1);
19493 }
19494
19495-static inline int
19496+static inline unsigned long
19497 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19498- unsigned size)
19499+ unsigned long size)
19500 {
19501+ if (size > INT_MAX)
19502+ return size;
19503+
19504+#ifdef CONFIG_PAX_MEMORY_UDEREF
19505+ if (!__access_ok(VERIFY_READ, src, size))
19506+ return size;
19507+#endif
19508+
19509 return __copy_user_nocache(dst, src, size, 0);
19510 }
19511
19512 unsigned long
19513-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19514+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19515
19516 #endif /* _ASM_X86_UACCESS_64_H */
19517diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19518index 5b238981..77fdd78 100644
19519--- a/arch/x86/include/asm/word-at-a-time.h
19520+++ b/arch/x86/include/asm/word-at-a-time.h
19521@@ -11,7 +11,7 @@
19522 * and shift, for example.
19523 */
19524 struct word_at_a_time {
19525- const unsigned long one_bits, high_bits;
19526+ unsigned long one_bits, high_bits;
19527 };
19528
19529 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19530diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19531index 0f1be11..f7542bf 100644
19532--- a/arch/x86/include/asm/x86_init.h
19533+++ b/arch/x86/include/asm/x86_init.h
19534@@ -129,7 +129,7 @@ struct x86_init_ops {
19535 struct x86_init_timers timers;
19536 struct x86_init_iommu iommu;
19537 struct x86_init_pci pci;
19538-};
19539+} __no_const;
19540
19541 /**
19542 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19543@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19544 void (*setup_percpu_clockev)(void);
19545 void (*early_percpu_clock_init)(void);
19546 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19547-};
19548+} __no_const;
19549
19550 struct timespec;
19551
19552@@ -168,7 +168,7 @@ struct x86_platform_ops {
19553 void (*save_sched_clock_state)(void);
19554 void (*restore_sched_clock_state)(void);
19555 void (*apic_post_init)(void);
19556-};
19557+} __no_const;
19558
19559 struct pci_dev;
19560 struct msi_msg;
19561@@ -185,7 +185,7 @@ struct x86_msi_ops {
19562 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19563 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
19564 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
19565-};
19566+} __no_const;
19567
19568 struct IO_APIC_route_entry;
19569 struct io_apic_irq_attr;
19570@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
19571 unsigned int destination, int vector,
19572 struct io_apic_irq_attr *attr);
19573 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19574-};
19575+} __no_const;
19576
19577 extern struct x86_init_ops x86_init;
19578 extern struct x86_cpuinit_ops x86_cpuinit;
19579diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
19580index b913915..4f5a581 100644
19581--- a/arch/x86/include/asm/xen/page.h
19582+++ b/arch/x86/include/asm/xen/page.h
19583@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
19584 extern struct page *m2p_find_override(unsigned long mfn);
19585 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
19586
19587-static inline unsigned long pfn_to_mfn(unsigned long pfn)
19588+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
19589 {
19590 unsigned long mfn;
19591
19592diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19593index 0415cda..3b22adc 100644
19594--- a/arch/x86/include/asm/xsave.h
19595+++ b/arch/x86/include/asm/xsave.h
19596@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19597 if (unlikely(err))
19598 return -EFAULT;
19599
19600+ pax_open_userland();
19601 __asm__ __volatile__(ASM_STAC "\n"
19602- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19603+ "1:"
19604+ __copyuser_seg
19605+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19606 "2: " ASM_CLAC "\n"
19607 ".section .fixup,\"ax\"\n"
19608 "3: movl $-1,%[err]\n"
19609@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19610 : [err] "=r" (err)
19611 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19612 : "memory");
19613+ pax_close_userland();
19614 return err;
19615 }
19616
19617 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19618 {
19619 int err;
19620- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19621+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19622 u32 lmask = mask;
19623 u32 hmask = mask >> 32;
19624
19625+ pax_open_userland();
19626 __asm__ __volatile__(ASM_STAC "\n"
19627- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19628+ "1:"
19629+ __copyuser_seg
19630+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19631 "2: " ASM_CLAC "\n"
19632 ".section .fixup,\"ax\"\n"
19633 "3: movl $-1,%[err]\n"
19634@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19635 : [err] "=r" (err)
19636 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19637 : "memory"); /* memory required? */
19638+ pax_close_userland();
19639 return err;
19640 }
19641
19642diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19643index bbae024..e1528f9 100644
19644--- a/arch/x86/include/uapi/asm/e820.h
19645+++ b/arch/x86/include/uapi/asm/e820.h
19646@@ -63,7 +63,7 @@ struct e820map {
19647 #define ISA_START_ADDRESS 0xa0000
19648 #define ISA_END_ADDRESS 0x100000
19649
19650-#define BIOS_BEGIN 0x000a0000
19651+#define BIOS_BEGIN 0x000c0000
19652 #define BIOS_END 0x00100000
19653
19654 #define BIOS_ROM_BASE 0xffe00000
19655diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
19656index 7b0a55a..ad115bf 100644
19657--- a/arch/x86/include/uapi/asm/ptrace-abi.h
19658+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
19659@@ -49,7 +49,6 @@
19660 #define EFLAGS 144
19661 #define RSP 152
19662 #define SS 160
19663-#define ARGOFFSET R11
19664 #endif /* __ASSEMBLY__ */
19665
19666 /* top of stack page */
19667diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19668index 9b0a34e..fc7e553 100644
19669--- a/arch/x86/kernel/Makefile
19670+++ b/arch/x86/kernel/Makefile
19671@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19672 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19673 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19674 obj-y += probe_roms.o
19675-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19676+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19677 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19678 obj-y += syscall_$(BITS).o
19679 obj-$(CONFIG_X86_64) += vsyscall_64.o
19680diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19681index 6c0b43b..e67bb31 100644
19682--- a/arch/x86/kernel/acpi/boot.c
19683+++ b/arch/x86/kernel/acpi/boot.c
19684@@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19685 * If your system is blacklisted here, but you find that acpi=force
19686 * works for you, please contact linux-acpi@vger.kernel.org
19687 */
19688-static struct dmi_system_id __initdata acpi_dmi_table[] = {
19689+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19690 /*
19691 * Boxes that need ACPI disabled
19692 */
19693@@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19694 };
19695
19696 /* second table for DMI checks that should run after early-quirks */
19697-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19698+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19699 /*
19700 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19701 * which includes some code which overrides all temperature
19702diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19703index 3a2ae4c..9db31d6 100644
19704--- a/arch/x86/kernel/acpi/sleep.c
19705+++ b/arch/x86/kernel/acpi/sleep.c
19706@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
19707 #else /* CONFIG_64BIT */
19708 #ifdef CONFIG_SMP
19709 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19710+
19711+ pax_open_kernel();
19712 early_gdt_descr.address =
19713 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19714+ pax_close_kernel();
19715+
19716 initial_gs = per_cpu_offset(smp_processor_id());
19717 #endif
19718 initial_code = (unsigned long)wakeup_long64;
19719diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19720index 665c6b7..eae4d56 100644
19721--- a/arch/x86/kernel/acpi/wakeup_32.S
19722+++ b/arch/x86/kernel/acpi/wakeup_32.S
19723@@ -29,13 +29,11 @@ wakeup_pmode_return:
19724 # and restore the stack ... but you need gdt for this to work
19725 movl saved_context_esp, %esp
19726
19727- movl %cs:saved_magic, %eax
19728- cmpl $0x12345678, %eax
19729+ cmpl $0x12345678, saved_magic
19730 jne bogus_magic
19731
19732 # jump to place where we left off
19733- movl saved_eip, %eax
19734- jmp *%eax
19735+ jmp *(saved_eip)
19736
19737 bogus_magic:
19738 jmp bogus_magic
19739diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19740index df94598..f3b29bf 100644
19741--- a/arch/x86/kernel/alternative.c
19742+++ b/arch/x86/kernel/alternative.c
19743@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19744 */
19745 for (a = start; a < end; a++) {
19746 instr = (u8 *)&a->instr_offset + a->instr_offset;
19747+
19748+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19749+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19750+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19751+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19752+#endif
19753+
19754 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19755 BUG_ON(a->replacementlen > a->instrlen);
19756 BUG_ON(a->instrlen > sizeof(insnbuf));
19757@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19758 for (poff = start; poff < end; poff++) {
19759 u8 *ptr = (u8 *)poff + *poff;
19760
19761+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19762+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19763+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19764+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19765+#endif
19766+
19767 if (!*poff || ptr < text || ptr >= text_end)
19768 continue;
19769 /* turn DS segment override prefix into lock prefix */
19770- if (*ptr == 0x3e)
19771+ if (*ktla_ktva(ptr) == 0x3e)
19772 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19773 }
19774 mutex_unlock(&text_mutex);
19775@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19776 for (poff = start; poff < end; poff++) {
19777 u8 *ptr = (u8 *)poff + *poff;
19778
19779+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19780+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19781+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19782+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19783+#endif
19784+
19785 if (!*poff || ptr < text || ptr >= text_end)
19786 continue;
19787 /* turn lock prefix into DS segment override prefix */
19788- if (*ptr == 0xf0)
19789+ if (*ktla_ktva(ptr) == 0xf0)
19790 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19791 }
19792 mutex_unlock(&text_mutex);
19793@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19794
19795 BUG_ON(p->len > MAX_PATCH_LEN);
19796 /* prep the buffer with the original instructions */
19797- memcpy(insnbuf, p->instr, p->len);
19798+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19799 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19800 (unsigned long)p->instr, p->len);
19801
19802@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
19803 if (!uniproc_patched || num_possible_cpus() == 1)
19804 free_init_pages("SMP alternatives",
19805 (unsigned long)__smp_locks,
19806- (unsigned long)__smp_locks_end);
19807+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19808 #endif
19809
19810 apply_paravirt(__parainstructions, __parainstructions_end);
19811@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
19812 * instructions. And on the local CPU you need to be protected again NMI or MCE
19813 * handlers seeing an inconsistent instruction while you patch.
19814 */
19815-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19816+void *__kprobes text_poke_early(void *addr, const void *opcode,
19817 size_t len)
19818 {
19819 unsigned long flags;
19820 local_irq_save(flags);
19821- memcpy(addr, opcode, len);
19822+
19823+ pax_open_kernel();
19824+ memcpy(ktla_ktva(addr), opcode, len);
19825 sync_core();
19826+ pax_close_kernel();
19827+
19828 local_irq_restore(flags);
19829 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19830 that causes hangs on some VIA CPUs. */
19831@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19832 */
19833 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19834 {
19835- unsigned long flags;
19836- char *vaddr;
19837+ unsigned char *vaddr = ktla_ktva(addr);
19838 struct page *pages[2];
19839- int i;
19840+ size_t i;
19841
19842 if (!core_kernel_text((unsigned long)addr)) {
19843- pages[0] = vmalloc_to_page(addr);
19844- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19845+ pages[0] = vmalloc_to_page(vaddr);
19846+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19847 } else {
19848- pages[0] = virt_to_page(addr);
19849+ pages[0] = virt_to_page(vaddr);
19850 WARN_ON(!PageReserved(pages[0]));
19851- pages[1] = virt_to_page(addr + PAGE_SIZE);
19852+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19853 }
19854 BUG_ON(!pages[0]);
19855- local_irq_save(flags);
19856- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19857- if (pages[1])
19858- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19859- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19860- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19861- clear_fixmap(FIX_TEXT_POKE0);
19862- if (pages[1])
19863- clear_fixmap(FIX_TEXT_POKE1);
19864- local_flush_tlb();
19865- sync_core();
19866- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19867- that causes hangs on some VIA CPUs. */
19868+ text_poke_early(addr, opcode, len);
19869 for (i = 0; i < len; i++)
19870- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19871- local_irq_restore(flags);
19872+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19873 return addr;
19874 }
19875
19876@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
19877 if (likely(!bp_patching_in_progress))
19878 return 0;
19879
19880- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19881+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19882 return 0;
19883
19884 /* set up the specified breakpoint handler */
19885@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
19886 */
19887 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19888 {
19889- unsigned char int3 = 0xcc;
19890+ const unsigned char int3 = 0xcc;
19891
19892 bp_int3_handler = handler;
19893 bp_int3_addr = (u8 *)addr + sizeof(int3);
19894diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19895index d278736..0b4af9a8 100644
19896--- a/arch/x86/kernel/apic/apic.c
19897+++ b/arch/x86/kernel/apic/apic.c
19898@@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
19899 /*
19900 * Debug level, exported for io_apic.c
19901 */
19902-unsigned int apic_verbosity;
19903+int apic_verbosity;
19904
19905 int pic_mode;
19906
19907@@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19908 apic_write(APIC_ESR, 0);
19909 v1 = apic_read(APIC_ESR);
19910 ack_APIC_irq();
19911- atomic_inc(&irq_err_count);
19912+ atomic_inc_unchecked(&irq_err_count);
19913
19914 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19915 smp_processor_id(), v0 , v1);
19916diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19917index 00c77cf..2dc6a2d 100644
19918--- a/arch/x86/kernel/apic/apic_flat_64.c
19919+++ b/arch/x86/kernel/apic/apic_flat_64.c
19920@@ -157,7 +157,7 @@ static int flat_probe(void)
19921 return 1;
19922 }
19923
19924-static struct apic apic_flat = {
19925+static struct apic apic_flat __read_only = {
19926 .name = "flat",
19927 .probe = flat_probe,
19928 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19929@@ -271,7 +271,7 @@ static int physflat_probe(void)
19930 return 0;
19931 }
19932
19933-static struct apic apic_physflat = {
19934+static struct apic apic_physflat __read_only = {
19935
19936 .name = "physical flat",
19937 .probe = physflat_probe,
19938diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19939index e145f28..2752888 100644
19940--- a/arch/x86/kernel/apic/apic_noop.c
19941+++ b/arch/x86/kernel/apic/apic_noop.c
19942@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19943 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19944 }
19945
19946-struct apic apic_noop = {
19947+struct apic apic_noop __read_only = {
19948 .name = "noop",
19949 .probe = noop_probe,
19950 .acpi_madt_oem_check = NULL,
19951diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19952index d50e364..543bee3 100644
19953--- a/arch/x86/kernel/apic/bigsmp_32.c
19954+++ b/arch/x86/kernel/apic/bigsmp_32.c
19955@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19956 return dmi_bigsmp;
19957 }
19958
19959-static struct apic apic_bigsmp = {
19960+static struct apic apic_bigsmp __read_only = {
19961
19962 .name = "bigsmp",
19963 .probe = probe_bigsmp,
19964diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19965index c552247..587a316 100644
19966--- a/arch/x86/kernel/apic/es7000_32.c
19967+++ b/arch/x86/kernel/apic/es7000_32.c
19968@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19969 return ret && es7000_apic_is_cluster();
19970 }
19971
19972-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19973-static struct apic __refdata apic_es7000_cluster = {
19974+static struct apic apic_es7000_cluster __read_only = {
19975
19976 .name = "es7000",
19977 .probe = probe_es7000,
19978@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19979 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19980 };
19981
19982-static struct apic __refdata apic_es7000 = {
19983+static struct apic apic_es7000 __read_only = {
19984
19985 .name = "es7000",
19986 .probe = probe_es7000,
19987diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19988index e63a5bd..c0babf8 100644
19989--- a/arch/x86/kernel/apic/io_apic.c
19990+++ b/arch/x86/kernel/apic/io_apic.c
19991@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19992 }
19993 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19994
19995-void lock_vector_lock(void)
19996+void lock_vector_lock(void) __acquires(vector_lock)
19997 {
19998 /* Used to the online set of cpus does not change
19999 * during assign_irq_vector.
20000@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20001 raw_spin_lock(&vector_lock);
20002 }
20003
20004-void unlock_vector_lock(void)
20005+void unlock_vector_lock(void) __releases(vector_lock)
20006 {
20007 raw_spin_unlock(&vector_lock);
20008 }
20009@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20010 ack_APIC_irq();
20011 }
20012
20013-atomic_t irq_mis_count;
20014+atomic_unchecked_t irq_mis_count;
20015
20016 #ifdef CONFIG_GENERIC_PENDING_IRQ
20017 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20018@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20019 * at the cpu.
20020 */
20021 if (!(v & (1 << (i & 0x1f)))) {
20022- atomic_inc(&irq_mis_count);
20023+ atomic_inc_unchecked(&irq_mis_count);
20024
20025 eoi_ioapic_irq(irq, cfg);
20026 }
20027diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20028index 1e42e8f..daacf44 100644
20029--- a/arch/x86/kernel/apic/numaq_32.c
20030+++ b/arch/x86/kernel/apic/numaq_32.c
20031@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20032 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20033 }
20034
20035-/* Use __refdata to keep false positive warning calm. */
20036-static struct apic __refdata apic_numaq = {
20037+static struct apic apic_numaq __read_only = {
20038
20039 .name = "NUMAQ",
20040 .probe = probe_numaq,
20041diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20042index eb35ef9..f184a21 100644
20043--- a/arch/x86/kernel/apic/probe_32.c
20044+++ b/arch/x86/kernel/apic/probe_32.c
20045@@ -72,7 +72,7 @@ static int probe_default(void)
20046 return 1;
20047 }
20048
20049-static struct apic apic_default = {
20050+static struct apic apic_default __read_only = {
20051
20052 .name = "default",
20053 .probe = probe_default,
20054diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20055index 77c95c0..434f8a4 100644
20056--- a/arch/x86/kernel/apic/summit_32.c
20057+++ b/arch/x86/kernel/apic/summit_32.c
20058@@ -486,7 +486,7 @@ void setup_summit(void)
20059 }
20060 #endif
20061
20062-static struct apic apic_summit = {
20063+static struct apic apic_summit __read_only = {
20064
20065 .name = "summit",
20066 .probe = probe_summit,
20067diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20068index 140e29d..d88bc95 100644
20069--- a/arch/x86/kernel/apic/x2apic_cluster.c
20070+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20071@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20072 return notifier_from_errno(err);
20073 }
20074
20075-static struct notifier_block __refdata x2apic_cpu_notifier = {
20076+static struct notifier_block x2apic_cpu_notifier = {
20077 .notifier_call = update_clusterinfo,
20078 };
20079
20080@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20081 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20082 }
20083
20084-static struct apic apic_x2apic_cluster = {
20085+static struct apic apic_x2apic_cluster __read_only = {
20086
20087 .name = "cluster x2apic",
20088 .probe = x2apic_cluster_probe,
20089diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20090index 562a76d..a003c0f 100644
20091--- a/arch/x86/kernel/apic/x2apic_phys.c
20092+++ b/arch/x86/kernel/apic/x2apic_phys.c
20093@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20094 return apic == &apic_x2apic_phys;
20095 }
20096
20097-static struct apic apic_x2apic_phys = {
20098+static struct apic apic_x2apic_phys __read_only = {
20099
20100 .name = "physical x2apic",
20101 .probe = x2apic_phys_probe,
20102diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20103index ad0dc04..0d9cc56 100644
20104--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20105+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20106@@ -350,7 +350,7 @@ static int uv_probe(void)
20107 return apic == &apic_x2apic_uv_x;
20108 }
20109
20110-static struct apic __refdata apic_x2apic_uv_x = {
20111+static struct apic apic_x2apic_uv_x __read_only = {
20112
20113 .name = "UV large system",
20114 .probe = uv_probe,
20115diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20116index 3ab0343..814c4787 100644
20117--- a/arch/x86/kernel/apm_32.c
20118+++ b/arch/x86/kernel/apm_32.c
20119@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20120 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20121 * even though they are called in protected mode.
20122 */
20123-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20124+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20125 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20126
20127 static const char driver_version[] = "1.16ac"; /* no spaces */
20128@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20129 BUG_ON(cpu != 0);
20130 gdt = get_cpu_gdt_table(cpu);
20131 save_desc_40 = gdt[0x40 / 8];
20132+
20133+ pax_open_kernel();
20134 gdt[0x40 / 8] = bad_bios_desc;
20135+ pax_close_kernel();
20136
20137 apm_irq_save(flags);
20138 APM_DO_SAVE_SEGS;
20139@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20140 &call->esi);
20141 APM_DO_RESTORE_SEGS;
20142 apm_irq_restore(flags);
20143+
20144+ pax_open_kernel();
20145 gdt[0x40 / 8] = save_desc_40;
20146+ pax_close_kernel();
20147+
20148 put_cpu();
20149
20150 return call->eax & 0xff;
20151@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20152 BUG_ON(cpu != 0);
20153 gdt = get_cpu_gdt_table(cpu);
20154 save_desc_40 = gdt[0x40 / 8];
20155+
20156+ pax_open_kernel();
20157 gdt[0x40 / 8] = bad_bios_desc;
20158+ pax_close_kernel();
20159
20160 apm_irq_save(flags);
20161 APM_DO_SAVE_SEGS;
20162@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20163 &call->eax);
20164 APM_DO_RESTORE_SEGS;
20165 apm_irq_restore(flags);
20166+
20167+ pax_open_kernel();
20168 gdt[0x40 / 8] = save_desc_40;
20169+ pax_close_kernel();
20170+
20171 put_cpu();
20172 return error;
20173 }
20174@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20175 * code to that CPU.
20176 */
20177 gdt = get_cpu_gdt_table(0);
20178+
20179+ pax_open_kernel();
20180 set_desc_base(&gdt[APM_CS >> 3],
20181 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20182 set_desc_base(&gdt[APM_CS_16 >> 3],
20183 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20184 set_desc_base(&gdt[APM_DS >> 3],
20185 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20186+ pax_close_kernel();
20187
20188 proc_create("apm", 0, NULL, &apm_file_ops);
20189
20190diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20191index 9f6b934..cf5ffb3 100644
20192--- a/arch/x86/kernel/asm-offsets.c
20193+++ b/arch/x86/kernel/asm-offsets.c
20194@@ -32,6 +32,8 @@ void common(void) {
20195 OFFSET(TI_flags, thread_info, flags);
20196 OFFSET(TI_status, thread_info, status);
20197 OFFSET(TI_addr_limit, thread_info, addr_limit);
20198+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20199+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20200
20201 BLANK();
20202 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20203@@ -52,8 +54,26 @@ void common(void) {
20204 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20205 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20206 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20207+
20208+#ifdef CONFIG_PAX_KERNEXEC
20209+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20210 #endif
20211
20212+#ifdef CONFIG_PAX_MEMORY_UDEREF
20213+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20214+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20215+#ifdef CONFIG_X86_64
20216+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20217+#endif
20218+#endif
20219+
20220+#endif
20221+
20222+ BLANK();
20223+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20224+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20225+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20226+
20227 #ifdef CONFIG_XEN
20228 BLANK();
20229 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20230diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20231index e7c798b..2b2019b 100644
20232--- a/arch/x86/kernel/asm-offsets_64.c
20233+++ b/arch/x86/kernel/asm-offsets_64.c
20234@@ -77,6 +77,7 @@ int main(void)
20235 BLANK();
20236 #undef ENTRY
20237
20238+ DEFINE(TSS_size, sizeof(struct tss_struct));
20239 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20240 BLANK();
20241
20242diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20243index 47b56a7..efc2bc6 100644
20244--- a/arch/x86/kernel/cpu/Makefile
20245+++ b/arch/x86/kernel/cpu/Makefile
20246@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20247 CFLAGS_REMOVE_perf_event.o = -pg
20248 endif
20249
20250-# Make sure load_percpu_segment has no stackprotector
20251-nostackp := $(call cc-option, -fno-stack-protector)
20252-CFLAGS_common.o := $(nostackp)
20253-
20254 obj-y := intel_cacheinfo.o scattered.o topology.o
20255 obj-y += proc.o capflags.o powerflags.o common.o
20256 obj-y += rdrand.o
20257diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20258index bca023b..c544908 100644
20259--- a/arch/x86/kernel/cpu/amd.c
20260+++ b/arch/x86/kernel/cpu/amd.c
20261@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20262 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20263 {
20264 /* AMD errata T13 (order #21922) */
20265- if ((c->x86 == 6)) {
20266+ if (c->x86 == 6) {
20267 /* Duron Rev A0 */
20268 if (c->x86_model == 3 && c->x86_mask == 0)
20269 size = 64;
20270diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20271index 6abc172..3b0df94 100644
20272--- a/arch/x86/kernel/cpu/common.c
20273+++ b/arch/x86/kernel/cpu/common.c
20274@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20275
20276 static const struct cpu_dev *this_cpu = &default_cpu;
20277
20278-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20279-#ifdef CONFIG_X86_64
20280- /*
20281- * We need valid kernel segments for data and code in long mode too
20282- * IRET will check the segment types kkeil 2000/10/28
20283- * Also sysret mandates a special GDT layout
20284- *
20285- * TLS descriptors are currently at a different place compared to i386.
20286- * Hopefully nobody expects them at a fixed place (Wine?)
20287- */
20288- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20289- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20290- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20291- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20292- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20293- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20294-#else
20295- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20296- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20297- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20298- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20299- /*
20300- * Segments used for calling PnP BIOS have byte granularity.
20301- * They code segments and data segments have fixed 64k limits,
20302- * the transfer segment sizes are set at run time.
20303- */
20304- /* 32-bit code */
20305- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20306- /* 16-bit code */
20307- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20308- /* 16-bit data */
20309- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20310- /* 16-bit data */
20311- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20312- /* 16-bit data */
20313- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20314- /*
20315- * The APM segments have byte granularity and their bases
20316- * are set at run time. All have 64k limits.
20317- */
20318- /* 32-bit code */
20319- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20320- /* 16-bit code */
20321- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20322- /* data */
20323- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20324-
20325- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20326- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20327- GDT_STACK_CANARY_INIT
20328-#endif
20329-} };
20330-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20331-
20332 static int __init x86_xsave_setup(char *s)
20333 {
20334 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20335@@ -288,6 +234,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20336 set_in_cr4(X86_CR4_SMAP);
20337 }
20338
20339+#ifdef CONFIG_X86_64
20340+static __init int setup_disable_pcid(char *arg)
20341+{
20342+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20343+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20344+
20345+#ifdef CONFIG_PAX_MEMORY_UDEREF
20346+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20347+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20348+#endif
20349+
20350+ return 1;
20351+}
20352+__setup("nopcid", setup_disable_pcid);
20353+
20354+static void setup_pcid(struct cpuinfo_x86 *c)
20355+{
20356+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20357+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20358+
20359+#ifdef CONFIG_PAX_MEMORY_UDEREF
20360+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20361+ pax_open_kernel();
20362+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20363+ pax_close_kernel();
20364+ printk("PAX: slow and weak UDEREF enabled\n");
20365+ } else
20366+ printk("PAX: UDEREF disabled\n");
20367+#endif
20368+
20369+ return;
20370+ }
20371+
20372+ printk("PAX: PCID detected\n");
20373+ set_in_cr4(X86_CR4_PCIDE);
20374+
20375+#ifdef CONFIG_PAX_MEMORY_UDEREF
20376+ pax_open_kernel();
20377+ clone_pgd_mask = ~(pgdval_t)0UL;
20378+ pax_close_kernel();
20379+ if (pax_user_shadow_base)
20380+ printk("PAX: weak UDEREF enabled\n");
20381+ else {
20382+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20383+ printk("PAX: strong UDEREF enabled\n");
20384+ }
20385+#endif
20386+
20387+ if (cpu_has(c, X86_FEATURE_INVPCID))
20388+ printk("PAX: INVPCID detected\n");
20389+}
20390+#endif
20391+
20392 /*
20393 * Some CPU features depend on higher CPUID levels, which may not always
20394 * be available due to CPUID level capping or broken virtualization
20395@@ -388,7 +387,7 @@ void switch_to_new_gdt(int cpu)
20396 {
20397 struct desc_ptr gdt_descr;
20398
20399- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20400+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20401 gdt_descr.size = GDT_SIZE - 1;
20402 load_gdt(&gdt_descr);
20403 /* Reload the per-cpu base */
20404@@ -877,6 +876,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20405 setup_smep(c);
20406 setup_smap(c);
20407
20408+#ifdef CONFIG_X86_64
20409+ setup_pcid(c);
20410+#endif
20411+
20412 /*
20413 * The vendor-specific functions might have changed features.
20414 * Now we do "generic changes."
20415@@ -885,6 +888,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20416 /* Filter out anything that depends on CPUID levels we don't have */
20417 filter_cpuid_features(c, true);
20418
20419+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20420+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20421+#endif
20422+
20423 /* If the model name is still unset, do table lookup. */
20424 if (!c->x86_model_id[0]) {
20425 const char *p;
20426@@ -1072,10 +1079,12 @@ static __init int setup_disablecpuid(char *arg)
20427 }
20428 __setup("clearcpuid=", setup_disablecpuid);
20429
20430+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20431+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20432+
20433 #ifdef CONFIG_X86_64
20434-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20435-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20436- (unsigned long) debug_idt_table };
20437+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20438+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20439
20440 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20441 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20442@@ -1089,7 +1098,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20443 EXPORT_PER_CPU_SYMBOL(current_task);
20444
20445 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20446- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20447+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20448 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20449
20450 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20451@@ -1239,7 +1248,7 @@ void cpu_init(void)
20452 load_ucode_ap();
20453
20454 cpu = stack_smp_processor_id();
20455- t = &per_cpu(init_tss, cpu);
20456+ t = init_tss + cpu;
20457 oist = &per_cpu(orig_ist, cpu);
20458
20459 #ifdef CONFIG_NUMA
20460@@ -1274,7 +1283,6 @@ void cpu_init(void)
20461 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20462 barrier();
20463
20464- x86_configure_nx();
20465 enable_x2apic();
20466
20467 /*
20468@@ -1326,7 +1334,7 @@ void cpu_init(void)
20469 {
20470 int cpu = smp_processor_id();
20471 struct task_struct *curr = current;
20472- struct tss_struct *t = &per_cpu(init_tss, cpu);
20473+ struct tss_struct *t = init_tss + cpu;
20474 struct thread_struct *thread = &curr->thread;
20475
20476 show_ucode_info_early();
20477diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20478index 0641113..06f5ba4 100644
20479--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20480+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20481@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20482 };
20483
20484 #ifdef CONFIG_AMD_NB
20485+static struct attribute *default_attrs_amd_nb[] = {
20486+ &type.attr,
20487+ &level.attr,
20488+ &coherency_line_size.attr,
20489+ &physical_line_partition.attr,
20490+ &ways_of_associativity.attr,
20491+ &number_of_sets.attr,
20492+ &size.attr,
20493+ &shared_cpu_map.attr,
20494+ &shared_cpu_list.attr,
20495+ NULL,
20496+ NULL,
20497+ NULL,
20498+ NULL
20499+};
20500+
20501 static struct attribute **amd_l3_attrs(void)
20502 {
20503 static struct attribute **attrs;
20504@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20505
20506 n = ARRAY_SIZE(default_attrs);
20507
20508- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20509- n += 2;
20510-
20511- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20512- n += 1;
20513-
20514- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20515- if (attrs == NULL)
20516- return attrs = default_attrs;
20517-
20518- for (n = 0; default_attrs[n]; n++)
20519- attrs[n] = default_attrs[n];
20520+ attrs = default_attrs_amd_nb;
20521
20522 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20523 attrs[n++] = &cache_disable_0.attr;
20524@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20525 .default_attrs = default_attrs,
20526 };
20527
20528+#ifdef CONFIG_AMD_NB
20529+static struct kobj_type ktype_cache_amd_nb = {
20530+ .sysfs_ops = &sysfs_ops,
20531+ .default_attrs = default_attrs_amd_nb,
20532+};
20533+#endif
20534+
20535 static struct kobj_type ktype_percpu_entry = {
20536 .sysfs_ops = &sysfs_ops,
20537 };
20538@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
20539 return retval;
20540 }
20541
20542+#ifdef CONFIG_AMD_NB
20543+ amd_l3_attrs();
20544+#endif
20545+
20546 for (i = 0; i < num_cache_leaves; i++) {
20547+ struct kobj_type *ktype;
20548+
20549 this_object = INDEX_KOBJECT_PTR(cpu, i);
20550 this_object->cpu = cpu;
20551 this_object->index = i;
20552
20553 this_leaf = CPUID4_INFO_IDX(cpu, i);
20554
20555- ktype_cache.default_attrs = default_attrs;
20556+ ktype = &ktype_cache;
20557 #ifdef CONFIG_AMD_NB
20558 if (this_leaf->base.nb)
20559- ktype_cache.default_attrs = amd_l3_attrs();
20560+ ktype = &ktype_cache_amd_nb;
20561 #endif
20562 retval = kobject_init_and_add(&(this_object->kobj),
20563- &ktype_cache,
20564+ ktype,
20565 per_cpu(ici_cache_kobject, cpu),
20566 "index%1lu", i);
20567 if (unlikely(retval)) {
20568diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20569index b3218cd..99a75de 100644
20570--- a/arch/x86/kernel/cpu/mcheck/mce.c
20571+++ b/arch/x86/kernel/cpu/mcheck/mce.c
20572@@ -45,6 +45,7 @@
20573 #include <asm/processor.h>
20574 #include <asm/mce.h>
20575 #include <asm/msr.h>
20576+#include <asm/local.h>
20577
20578 #include "mce-internal.h"
20579
20580@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
20581 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20582 m->cs, m->ip);
20583
20584- if (m->cs == __KERNEL_CS)
20585+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20586 print_symbol("{%s}", m->ip);
20587 pr_cont("\n");
20588 }
20589@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
20590
20591 #define PANIC_TIMEOUT 5 /* 5 seconds */
20592
20593-static atomic_t mce_paniced;
20594+static atomic_unchecked_t mce_paniced;
20595
20596 static int fake_panic;
20597-static atomic_t mce_fake_paniced;
20598+static atomic_unchecked_t mce_fake_paniced;
20599
20600 /* Panic in progress. Enable interrupts and wait for final IPI */
20601 static void wait_for_panic(void)
20602@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20603 /*
20604 * Make sure only one CPU runs in machine check panic
20605 */
20606- if (atomic_inc_return(&mce_paniced) > 1)
20607+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20608 wait_for_panic();
20609 barrier();
20610
20611@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20612 console_verbose();
20613 } else {
20614 /* Don't log too much for fake panic */
20615- if (atomic_inc_return(&mce_fake_paniced) > 1)
20616+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20617 return;
20618 }
20619 /* First print corrected ones that are still unlogged */
20620@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20621 if (!fake_panic) {
20622 if (panic_timeout == 0)
20623 panic_timeout = mca_cfg.panic_timeout;
20624- panic(msg);
20625+ panic("%s", msg);
20626 } else
20627 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20628 }
20629@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
20630 * might have been modified by someone else.
20631 */
20632 rmb();
20633- if (atomic_read(&mce_paniced))
20634+ if (atomic_read_unchecked(&mce_paniced))
20635 wait_for_panic();
20636 if (!mca_cfg.monarch_timeout)
20637 goto out;
20638@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20639 }
20640
20641 /* Call the installed machine check handler for this CPU setup. */
20642-void (*machine_check_vector)(struct pt_regs *, long error_code) =
20643+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20644 unexpected_machine_check;
20645
20646 /*
20647@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20648 return;
20649 }
20650
20651+ pax_open_kernel();
20652 machine_check_vector = do_machine_check;
20653+ pax_close_kernel();
20654
20655 __mcheck_cpu_init_generic();
20656 __mcheck_cpu_init_vendor(c);
20657@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20658 */
20659
20660 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20661-static int mce_chrdev_open_count; /* #times opened */
20662+static local_t mce_chrdev_open_count; /* #times opened */
20663 static int mce_chrdev_open_exclu; /* already open exclusive? */
20664
20665 static int mce_chrdev_open(struct inode *inode, struct file *file)
20666@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20667 spin_lock(&mce_chrdev_state_lock);
20668
20669 if (mce_chrdev_open_exclu ||
20670- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20671+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20672 spin_unlock(&mce_chrdev_state_lock);
20673
20674 return -EBUSY;
20675@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20676
20677 if (file->f_flags & O_EXCL)
20678 mce_chrdev_open_exclu = 1;
20679- mce_chrdev_open_count++;
20680+ local_inc(&mce_chrdev_open_count);
20681
20682 spin_unlock(&mce_chrdev_state_lock);
20683
20684@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20685 {
20686 spin_lock(&mce_chrdev_state_lock);
20687
20688- mce_chrdev_open_count--;
20689+ local_dec(&mce_chrdev_open_count);
20690 mce_chrdev_open_exclu = 0;
20691
20692 spin_unlock(&mce_chrdev_state_lock);
20693@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
20694
20695 for (i = 0; i < mca_cfg.banks; i++) {
20696 struct mce_bank *b = &mce_banks[i];
20697- struct device_attribute *a = &b->attr;
20698+ device_attribute_no_const *a = &b->attr;
20699
20700 sysfs_attr_init(&a->attr);
20701 a->attr.name = b->attrname;
20702@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
20703 static void mce_reset(void)
20704 {
20705 cpu_missing = 0;
20706- atomic_set(&mce_fake_paniced, 0);
20707+ atomic_set_unchecked(&mce_fake_paniced, 0);
20708 atomic_set(&mce_executing, 0);
20709 atomic_set(&mce_callin, 0);
20710 atomic_set(&global_nwo, 0);
20711diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20712index 1c044b1..37a2a43 100644
20713--- a/arch/x86/kernel/cpu/mcheck/p5.c
20714+++ b/arch/x86/kernel/cpu/mcheck/p5.c
20715@@ -11,6 +11,7 @@
20716 #include <asm/processor.h>
20717 #include <asm/mce.h>
20718 #include <asm/msr.h>
20719+#include <asm/pgtable.h>
20720
20721 /* By default disabled */
20722 int mce_p5_enabled __read_mostly;
20723@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20724 if (!cpu_has(c, X86_FEATURE_MCE))
20725 return;
20726
20727+ pax_open_kernel();
20728 machine_check_vector = pentium_machine_check;
20729+ pax_close_kernel();
20730 /* Make sure the vector pointer is visible before we enable MCEs: */
20731 wmb();
20732
20733diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20734index e9a701a..35317d6 100644
20735--- a/arch/x86/kernel/cpu/mcheck/winchip.c
20736+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20737@@ -10,6 +10,7 @@
20738 #include <asm/processor.h>
20739 #include <asm/mce.h>
20740 #include <asm/msr.h>
20741+#include <asm/pgtable.h>
20742
20743 /* Machine check handler for WinChip C6: */
20744 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20745@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20746 {
20747 u32 lo, hi;
20748
20749+ pax_open_kernel();
20750 machine_check_vector = winchip_machine_check;
20751+ pax_close_kernel();
20752 /* Make sure the vector pointer is visible before we enable MCEs: */
20753 wmb();
20754
20755diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20756index f961de9..8a9d332 100644
20757--- a/arch/x86/kernel/cpu/mtrr/main.c
20758+++ b/arch/x86/kernel/cpu/mtrr/main.c
20759@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20760 u64 size_or_mask, size_and_mask;
20761 static bool mtrr_aps_delayed_init;
20762
20763-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20764+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20765
20766 const struct mtrr_ops *mtrr_if;
20767
20768diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20769index df5e41f..816c719 100644
20770--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20771+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20772@@ -25,7 +25,7 @@ struct mtrr_ops {
20773 int (*validate_add_page)(unsigned long base, unsigned long size,
20774 unsigned int type);
20775 int (*have_wrcomb)(void);
20776-};
20777+} __do_const;
20778
20779 extern int generic_get_free_region(unsigned long base, unsigned long size,
20780 int replace_reg);
20781diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20782index 8e13293..9bfd68c 100644
20783--- a/arch/x86/kernel/cpu/perf_event.c
20784+++ b/arch/x86/kernel/cpu/perf_event.c
20785@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20786 pr_info("no hardware sampling interrupt available.\n");
20787 }
20788
20789-static struct attribute_group x86_pmu_format_group = {
20790+static attribute_group_no_const x86_pmu_format_group = {
20791 .name = "format",
20792 .attrs = NULL,
20793 };
20794@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20795 NULL,
20796 };
20797
20798-static struct attribute_group x86_pmu_events_group = {
20799+static attribute_group_no_const x86_pmu_events_group = {
20800 .name = "events",
20801 .attrs = events_attr,
20802 };
20803@@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20804 if (idx > GDT_ENTRIES)
20805 return 0;
20806
20807- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20808+ desc = get_cpu_gdt_table(smp_processor_id());
20809 }
20810
20811 return get_desc_base(desc + idx);
20812@@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20813 break;
20814
20815 perf_callchain_store(entry, frame.return_address);
20816- fp = frame.next_frame;
20817+ fp = (const void __force_user *)frame.next_frame;
20818 }
20819 }
20820
20821diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20822index 639d128..e92d7e5 100644
20823--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20824+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20825@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20826 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20827 {
20828 struct attribute **attrs;
20829- struct attribute_group *attr_group;
20830+ attribute_group_no_const *attr_group;
20831 int i = 0, j;
20832
20833 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20834diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20835index 0fa4f24..17990ed 100644
20836--- a/arch/x86/kernel/cpu/perf_event_intel.c
20837+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20838@@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
20839 * v2 and above have a perf capabilities MSR
20840 */
20841 if (version > 1) {
20842- u64 capabilities;
20843+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20844
20845- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20846- x86_pmu.intel_cap.capabilities = capabilities;
20847+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20848+ x86_pmu.intel_cap.capabilities = capabilities;
20849 }
20850
20851 intel_ds_init();
20852diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20853index 29c2487..a5606fa 100644
20854--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20855+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20856@@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20857 static int __init uncore_type_init(struct intel_uncore_type *type)
20858 {
20859 struct intel_uncore_pmu *pmus;
20860- struct attribute_group *attr_group;
20861+ attribute_group_no_const *attr_group;
20862 struct attribute **attrs;
20863 int i, j;
20864
20865diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20866index a80ab71..4089da5 100644
20867--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20868+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20869@@ -498,7 +498,7 @@ struct intel_uncore_box {
20870 struct uncore_event_desc {
20871 struct kobj_attribute attr;
20872 const char *config;
20873-};
20874+} __do_const;
20875
20876 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20877 { \
20878diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20879index 7d9481c..99c7e4b 100644
20880--- a/arch/x86/kernel/cpuid.c
20881+++ b/arch/x86/kernel/cpuid.c
20882@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20883 return notifier_from_errno(err);
20884 }
20885
20886-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20887+static struct notifier_block cpuid_class_cpu_notifier =
20888 {
20889 .notifier_call = cpuid_class_cpu_callback,
20890 };
20891diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20892index 18677a9..f67c45b 100644
20893--- a/arch/x86/kernel/crash.c
20894+++ b/arch/x86/kernel/crash.c
20895@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20896 {
20897 #ifdef CONFIG_X86_32
20898 struct pt_regs fixed_regs;
20899-#endif
20900
20901-#ifdef CONFIG_X86_32
20902- if (!user_mode_vm(regs)) {
20903+ if (!user_mode(regs)) {
20904 crash_fixup_ss_esp(&fixed_regs, regs);
20905 regs = &fixed_regs;
20906 }
20907diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20908index afa64ad..dce67dd 100644
20909--- a/arch/x86/kernel/crash_dump_64.c
20910+++ b/arch/x86/kernel/crash_dump_64.c
20911@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20912 return -ENOMEM;
20913
20914 if (userbuf) {
20915- if (copy_to_user(buf, vaddr + offset, csize)) {
20916+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20917 iounmap(vaddr);
20918 return -EFAULT;
20919 }
20920diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20921index 5d3fe8d..02e1429 100644
20922--- a/arch/x86/kernel/doublefault.c
20923+++ b/arch/x86/kernel/doublefault.c
20924@@ -13,7 +13,7 @@
20925
20926 #define DOUBLEFAULT_STACKSIZE (1024)
20927 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20928-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20929+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20930
20931 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20932
20933@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20934 unsigned long gdt, tss;
20935
20936 native_store_gdt(&gdt_desc);
20937- gdt = gdt_desc.address;
20938+ gdt = (unsigned long)gdt_desc.address;
20939
20940 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20941
20942@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20943 /* 0x2 bit is always set */
20944 .flags = X86_EFLAGS_SF | 0x2,
20945 .sp = STACK_START,
20946- .es = __USER_DS,
20947+ .es = __KERNEL_DS,
20948 .cs = __KERNEL_CS,
20949 .ss = __KERNEL_DS,
20950- .ds = __USER_DS,
20951+ .ds = __KERNEL_DS,
20952 .fs = __KERNEL_PERCPU,
20953
20954 .__cr3 = __pa_nodebug(swapper_pg_dir),
20955diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20956index d9c12d3..7858b62 100644
20957--- a/arch/x86/kernel/dumpstack.c
20958+++ b/arch/x86/kernel/dumpstack.c
20959@@ -2,6 +2,9 @@
20960 * Copyright (C) 1991, 1992 Linus Torvalds
20961 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20962 */
20963+#ifdef CONFIG_GRKERNSEC_HIDESYM
20964+#define __INCLUDED_BY_HIDESYM 1
20965+#endif
20966 #include <linux/kallsyms.h>
20967 #include <linux/kprobes.h>
20968 #include <linux/uaccess.h>
20969@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
20970 static void
20971 print_ftrace_graph_addr(unsigned long addr, void *data,
20972 const struct stacktrace_ops *ops,
20973- struct thread_info *tinfo, int *graph)
20974+ struct task_struct *task, int *graph)
20975 {
20976- struct task_struct *task;
20977 unsigned long ret_addr;
20978 int index;
20979
20980 if (addr != (unsigned long)return_to_handler)
20981 return;
20982
20983- task = tinfo->task;
20984 index = task->curr_ret_stack;
20985
20986 if (!task->ret_stack || index < *graph)
20987@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20988 static inline void
20989 print_ftrace_graph_addr(unsigned long addr, void *data,
20990 const struct stacktrace_ops *ops,
20991- struct thread_info *tinfo, int *graph)
20992+ struct task_struct *task, int *graph)
20993 { }
20994 #endif
20995
20996@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20997 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20998 */
20999
21000-static inline int valid_stack_ptr(struct thread_info *tinfo,
21001- void *p, unsigned int size, void *end)
21002+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21003 {
21004- void *t = tinfo;
21005 if (end) {
21006 if (p < end && p >= (end-THREAD_SIZE))
21007 return 1;
21008@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21009 }
21010
21011 unsigned long
21012-print_context_stack(struct thread_info *tinfo,
21013+print_context_stack(struct task_struct *task, void *stack_start,
21014 unsigned long *stack, unsigned long bp,
21015 const struct stacktrace_ops *ops, void *data,
21016 unsigned long *end, int *graph)
21017 {
21018 struct stack_frame *frame = (struct stack_frame *)bp;
21019
21020- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21021+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21022 unsigned long addr;
21023
21024 addr = *stack;
21025@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21026 } else {
21027 ops->address(data, addr, 0);
21028 }
21029- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21030+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21031 }
21032 stack++;
21033 }
21034@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21035 EXPORT_SYMBOL_GPL(print_context_stack);
21036
21037 unsigned long
21038-print_context_stack_bp(struct thread_info *tinfo,
21039+print_context_stack_bp(struct task_struct *task, void *stack_start,
21040 unsigned long *stack, unsigned long bp,
21041 const struct stacktrace_ops *ops, void *data,
21042 unsigned long *end, int *graph)
21043@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21044 struct stack_frame *frame = (struct stack_frame *)bp;
21045 unsigned long *ret_addr = &frame->return_address;
21046
21047- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21048+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21049 unsigned long addr = *ret_addr;
21050
21051 if (!__kernel_text_address(addr))
21052@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21053 ops->address(data, addr, 1);
21054 frame = frame->next_frame;
21055 ret_addr = &frame->return_address;
21056- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21057+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21058 }
21059
21060 return (unsigned long)frame;
21061@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21062 static void print_trace_address(void *data, unsigned long addr, int reliable)
21063 {
21064 touch_nmi_watchdog();
21065- printk(data);
21066+ printk("%s", (char *)data);
21067 printk_stack_address(addr, reliable);
21068 }
21069
21070@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21071 }
21072 EXPORT_SYMBOL_GPL(oops_begin);
21073
21074+extern void gr_handle_kernel_exploit(void);
21075+
21076 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21077 {
21078 if (regs && kexec_should_crash(current))
21079@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21080 panic("Fatal exception in interrupt");
21081 if (panic_on_oops)
21082 panic("Fatal exception");
21083- do_exit(signr);
21084+
21085+ gr_handle_kernel_exploit();
21086+
21087+ do_group_exit(signr);
21088 }
21089
21090 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21091@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21092 print_modules();
21093 show_regs(regs);
21094 #ifdef CONFIG_X86_32
21095- if (user_mode_vm(regs)) {
21096+ if (user_mode(regs)) {
21097 sp = regs->sp;
21098 ss = regs->ss & 0xffff;
21099 } else {
21100@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21101 unsigned long flags = oops_begin();
21102 int sig = SIGSEGV;
21103
21104- if (!user_mode_vm(regs))
21105+ if (!user_mode(regs))
21106 report_bug(regs->ip, regs);
21107
21108 if (__die(str, regs, err))
21109diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21110index f2a1770..540657f 100644
21111--- a/arch/x86/kernel/dumpstack_32.c
21112+++ b/arch/x86/kernel/dumpstack_32.c
21113@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21114 bp = stack_frame(task, regs);
21115
21116 for (;;) {
21117- struct thread_info *context;
21118+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21119
21120- context = (struct thread_info *)
21121- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21122- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21123+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21124
21125- stack = (unsigned long *)context->previous_esp;
21126- if (!stack)
21127+ if (stack_start == task_stack_page(task))
21128 break;
21129+ stack = *(unsigned long **)stack_start;
21130 if (ops->stack(data, "IRQ") < 0)
21131 break;
21132 touch_nmi_watchdog();
21133@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21134 int i;
21135
21136 show_regs_print_info(KERN_EMERG);
21137- __show_regs(regs, !user_mode_vm(regs));
21138+ __show_regs(regs, !user_mode(regs));
21139
21140 /*
21141 * When in-kernel, we also print out the stack and code at the
21142 * time of the fault..
21143 */
21144- if (!user_mode_vm(regs)) {
21145+ if (!user_mode(regs)) {
21146 unsigned int code_prologue = code_bytes * 43 / 64;
21147 unsigned int code_len = code_bytes;
21148 unsigned char c;
21149 u8 *ip;
21150+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21151
21152 pr_emerg("Stack:\n");
21153 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21154
21155 pr_emerg("Code:");
21156
21157- ip = (u8 *)regs->ip - code_prologue;
21158+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21159 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21160 /* try starting at IP */
21161- ip = (u8 *)regs->ip;
21162+ ip = (u8 *)regs->ip + cs_base;
21163 code_len = code_len - code_prologue + 1;
21164 }
21165 for (i = 0; i < code_len; i++, ip++) {
21166@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21167 pr_cont(" Bad EIP value.");
21168 break;
21169 }
21170- if (ip == (u8 *)regs->ip)
21171+ if (ip == (u8 *)regs->ip + cs_base)
21172 pr_cont(" <%02x>", c);
21173 else
21174 pr_cont(" %02x", c);
21175@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21176 {
21177 unsigned short ud2;
21178
21179+ ip = ktla_ktva(ip);
21180 if (ip < PAGE_OFFSET)
21181 return 0;
21182 if (probe_kernel_address((unsigned short *)ip, ud2))
21183@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21184
21185 return ud2 == 0x0b0f;
21186 }
21187+
21188+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21189+void pax_check_alloca(unsigned long size)
21190+{
21191+ unsigned long sp = (unsigned long)&sp, stack_left;
21192+
21193+ /* all kernel stacks are of the same size */
21194+ stack_left = sp & (THREAD_SIZE - 1);
21195+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21196+}
21197+EXPORT_SYMBOL(pax_check_alloca);
21198+#endif
21199diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21200index addb207..99635fa 100644
21201--- a/arch/x86/kernel/dumpstack_64.c
21202+++ b/arch/x86/kernel/dumpstack_64.c
21203@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21204 unsigned long *irq_stack_end =
21205 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21206 unsigned used = 0;
21207- struct thread_info *tinfo;
21208 int graph = 0;
21209 unsigned long dummy;
21210+ void *stack_start;
21211
21212 if (!task)
21213 task = current;
21214@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21215 * current stack address. If the stacks consist of nested
21216 * exceptions
21217 */
21218- tinfo = task_thread_info(task);
21219 for (;;) {
21220 char *id;
21221 unsigned long *estack_end;
21222+
21223 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21224 &used, &id);
21225
21226@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21227 if (ops->stack(data, id) < 0)
21228 break;
21229
21230- bp = ops->walk_stack(tinfo, stack, bp, ops,
21231+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21232 data, estack_end, &graph);
21233 ops->stack(data, "<EOE>");
21234 /*
21235@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21236 * second-to-last pointer (index -2 to end) in the
21237 * exception stack:
21238 */
21239+ if ((u16)estack_end[-1] != __KERNEL_DS)
21240+ goto out;
21241 stack = (unsigned long *) estack_end[-2];
21242 continue;
21243 }
21244@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21245 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21246 if (ops->stack(data, "IRQ") < 0)
21247 break;
21248- bp = ops->walk_stack(tinfo, stack, bp,
21249+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21250 ops, data, irq_stack_end, &graph);
21251 /*
21252 * We link to the next stack (which would be
21253@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21254 /*
21255 * This handles the process stack:
21256 */
21257- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21258+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21259+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21260+out:
21261 put_cpu();
21262 }
21263 EXPORT_SYMBOL(dump_trace);
21264@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21265
21266 return ud2 == 0x0b0f;
21267 }
21268+
21269+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21270+void pax_check_alloca(unsigned long size)
21271+{
21272+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21273+ unsigned cpu, used;
21274+ char *id;
21275+
21276+ /* check the process stack first */
21277+ stack_start = (unsigned long)task_stack_page(current);
21278+ stack_end = stack_start + THREAD_SIZE;
21279+ if (likely(stack_start <= sp && sp < stack_end)) {
21280+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21281+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21282+ return;
21283+ }
21284+
21285+ cpu = get_cpu();
21286+
21287+ /* check the irq stacks */
21288+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21289+ stack_start = stack_end - IRQ_STACK_SIZE;
21290+ if (stack_start <= sp && sp < stack_end) {
21291+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21292+ put_cpu();
21293+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21294+ return;
21295+ }
21296+
21297+ /* check the exception stacks */
21298+ used = 0;
21299+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21300+ stack_start = stack_end - EXCEPTION_STKSZ;
21301+ if (stack_end && stack_start <= sp && sp < stack_end) {
21302+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21303+ put_cpu();
21304+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21305+ return;
21306+ }
21307+
21308+ put_cpu();
21309+
21310+ /* unknown stack */
21311+ BUG();
21312+}
21313+EXPORT_SYMBOL(pax_check_alloca);
21314+#endif
21315diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21316index 174da5f..5e55606 100644
21317--- a/arch/x86/kernel/e820.c
21318+++ b/arch/x86/kernel/e820.c
21319@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21320
21321 static void early_panic(char *msg)
21322 {
21323- early_printk(msg);
21324- panic(msg);
21325+ early_printk("%s", msg);
21326+ panic("%s", msg);
21327 }
21328
21329 static int userdef __initdata;
21330diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21331index 01d1c18..8073693 100644
21332--- a/arch/x86/kernel/early_printk.c
21333+++ b/arch/x86/kernel/early_printk.c
21334@@ -7,6 +7,7 @@
21335 #include <linux/pci_regs.h>
21336 #include <linux/pci_ids.h>
21337 #include <linux/errno.h>
21338+#include <linux/sched.h>
21339 #include <asm/io.h>
21340 #include <asm/processor.h>
21341 #include <asm/fcntl.h>
21342diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21343index a2a4f46..6cab058 100644
21344--- a/arch/x86/kernel/entry_32.S
21345+++ b/arch/x86/kernel/entry_32.S
21346@@ -177,13 +177,153 @@
21347 /*CFI_REL_OFFSET gs, PT_GS*/
21348 .endm
21349 .macro SET_KERNEL_GS reg
21350+
21351+#ifdef CONFIG_CC_STACKPROTECTOR
21352 movl $(__KERNEL_STACK_CANARY), \reg
21353+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21354+ movl $(__USER_DS), \reg
21355+#else
21356+ xorl \reg, \reg
21357+#endif
21358+
21359 movl \reg, %gs
21360 .endm
21361
21362 #endif /* CONFIG_X86_32_LAZY_GS */
21363
21364-.macro SAVE_ALL
21365+.macro pax_enter_kernel
21366+#ifdef CONFIG_PAX_KERNEXEC
21367+ call pax_enter_kernel
21368+#endif
21369+.endm
21370+
21371+.macro pax_exit_kernel
21372+#ifdef CONFIG_PAX_KERNEXEC
21373+ call pax_exit_kernel
21374+#endif
21375+.endm
21376+
21377+#ifdef CONFIG_PAX_KERNEXEC
21378+ENTRY(pax_enter_kernel)
21379+#ifdef CONFIG_PARAVIRT
21380+ pushl %eax
21381+ pushl %ecx
21382+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21383+ mov %eax, %esi
21384+#else
21385+ mov %cr0, %esi
21386+#endif
21387+ bts $16, %esi
21388+ jnc 1f
21389+ mov %cs, %esi
21390+ cmp $__KERNEL_CS, %esi
21391+ jz 3f
21392+ ljmp $__KERNEL_CS, $3f
21393+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21394+2:
21395+#ifdef CONFIG_PARAVIRT
21396+ mov %esi, %eax
21397+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21398+#else
21399+ mov %esi, %cr0
21400+#endif
21401+3:
21402+#ifdef CONFIG_PARAVIRT
21403+ popl %ecx
21404+ popl %eax
21405+#endif
21406+ ret
21407+ENDPROC(pax_enter_kernel)
21408+
21409+ENTRY(pax_exit_kernel)
21410+#ifdef CONFIG_PARAVIRT
21411+ pushl %eax
21412+ pushl %ecx
21413+#endif
21414+ mov %cs, %esi
21415+ cmp $__KERNEXEC_KERNEL_CS, %esi
21416+ jnz 2f
21417+#ifdef CONFIG_PARAVIRT
21418+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21419+ mov %eax, %esi
21420+#else
21421+ mov %cr0, %esi
21422+#endif
21423+ btr $16, %esi
21424+ ljmp $__KERNEL_CS, $1f
21425+1:
21426+#ifdef CONFIG_PARAVIRT
21427+ mov %esi, %eax
21428+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21429+#else
21430+ mov %esi, %cr0
21431+#endif
21432+2:
21433+#ifdef CONFIG_PARAVIRT
21434+ popl %ecx
21435+ popl %eax
21436+#endif
21437+ ret
21438+ENDPROC(pax_exit_kernel)
21439+#endif
21440+
21441+ .macro pax_erase_kstack
21442+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21443+ call pax_erase_kstack
21444+#endif
21445+ .endm
21446+
21447+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21448+/*
21449+ * ebp: thread_info
21450+ */
21451+ENTRY(pax_erase_kstack)
21452+ pushl %edi
21453+ pushl %ecx
21454+ pushl %eax
21455+
21456+ mov TI_lowest_stack(%ebp), %edi
21457+ mov $-0xBEEF, %eax
21458+ std
21459+
21460+1: mov %edi, %ecx
21461+ and $THREAD_SIZE_asm - 1, %ecx
21462+ shr $2, %ecx
21463+ repne scasl
21464+ jecxz 2f
21465+
21466+ cmp $2*16, %ecx
21467+ jc 2f
21468+
21469+ mov $2*16, %ecx
21470+ repe scasl
21471+ jecxz 2f
21472+ jne 1b
21473+
21474+2: cld
21475+ mov %esp, %ecx
21476+ sub %edi, %ecx
21477+
21478+ cmp $THREAD_SIZE_asm, %ecx
21479+ jb 3f
21480+ ud2
21481+3:
21482+
21483+ shr $2, %ecx
21484+ rep stosl
21485+
21486+ mov TI_task_thread_sp0(%ebp), %edi
21487+ sub $128, %edi
21488+ mov %edi, TI_lowest_stack(%ebp)
21489+
21490+ popl %eax
21491+ popl %ecx
21492+ popl %edi
21493+ ret
21494+ENDPROC(pax_erase_kstack)
21495+#endif
21496+
21497+.macro __SAVE_ALL _DS
21498 cld
21499 PUSH_GS
21500 pushl_cfi %fs
21501@@ -206,7 +346,7 @@
21502 CFI_REL_OFFSET ecx, 0
21503 pushl_cfi %ebx
21504 CFI_REL_OFFSET ebx, 0
21505- movl $(__USER_DS), %edx
21506+ movl $\_DS, %edx
21507 movl %edx, %ds
21508 movl %edx, %es
21509 movl $(__KERNEL_PERCPU), %edx
21510@@ -214,6 +354,15 @@
21511 SET_KERNEL_GS %edx
21512 .endm
21513
21514+.macro SAVE_ALL
21515+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21516+ __SAVE_ALL __KERNEL_DS
21517+ pax_enter_kernel
21518+#else
21519+ __SAVE_ALL __USER_DS
21520+#endif
21521+.endm
21522+
21523 .macro RESTORE_INT_REGS
21524 popl_cfi %ebx
21525 CFI_RESTORE ebx
21526@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
21527 popfl_cfi
21528 jmp syscall_exit
21529 CFI_ENDPROC
21530-END(ret_from_fork)
21531+ENDPROC(ret_from_fork)
21532
21533 ENTRY(ret_from_kernel_thread)
21534 CFI_STARTPROC
21535@@ -344,7 +493,15 @@ ret_from_intr:
21536 andl $SEGMENT_RPL_MASK, %eax
21537 #endif
21538 cmpl $USER_RPL, %eax
21539+
21540+#ifdef CONFIG_PAX_KERNEXEC
21541+ jae resume_userspace
21542+
21543+ pax_exit_kernel
21544+ jmp resume_kernel
21545+#else
21546 jb resume_kernel # not returning to v8086 or userspace
21547+#endif
21548
21549 ENTRY(resume_userspace)
21550 LOCKDEP_SYS_EXIT
21551@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21552 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21553 # int/exception return?
21554 jne work_pending
21555- jmp restore_all
21556-END(ret_from_exception)
21557+ jmp restore_all_pax
21558+ENDPROC(ret_from_exception)
21559
21560 #ifdef CONFIG_PREEMPT
21561 ENTRY(resume_kernel)
21562@@ -369,7 +526,7 @@ need_resched:
21563 jz restore_all
21564 call preempt_schedule_irq
21565 jmp need_resched
21566-END(resume_kernel)
21567+ENDPROC(resume_kernel)
21568 #endif
21569 CFI_ENDPROC
21570 /*
21571@@ -403,30 +560,45 @@ sysenter_past_esp:
21572 /*CFI_REL_OFFSET cs, 0*/
21573 /*
21574 * Push current_thread_info()->sysenter_return to the stack.
21575- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21576- * pushed above; +8 corresponds to copy_thread's esp0 setting.
21577 */
21578- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21579+ pushl_cfi $0
21580 CFI_REL_OFFSET eip, 0
21581
21582 pushl_cfi %eax
21583 SAVE_ALL
21584+ GET_THREAD_INFO(%ebp)
21585+ movl TI_sysenter_return(%ebp),%ebp
21586+ movl %ebp,PT_EIP(%esp)
21587 ENABLE_INTERRUPTS(CLBR_NONE)
21588
21589 /*
21590 * Load the potential sixth argument from user stack.
21591 * Careful about security.
21592 */
21593+ movl PT_OLDESP(%esp),%ebp
21594+
21595+#ifdef CONFIG_PAX_MEMORY_UDEREF
21596+ mov PT_OLDSS(%esp),%ds
21597+1: movl %ds:(%ebp),%ebp
21598+ push %ss
21599+ pop %ds
21600+#else
21601 cmpl $__PAGE_OFFSET-3,%ebp
21602 jae syscall_fault
21603 ASM_STAC
21604 1: movl (%ebp),%ebp
21605 ASM_CLAC
21606+#endif
21607+
21608 movl %ebp,PT_EBP(%esp)
21609 _ASM_EXTABLE(1b,syscall_fault)
21610
21611 GET_THREAD_INFO(%ebp)
21612
21613+#ifdef CONFIG_PAX_RANDKSTACK
21614+ pax_erase_kstack
21615+#endif
21616+
21617 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21618 jnz sysenter_audit
21619 sysenter_do_call:
21620@@ -441,12 +613,24 @@ sysenter_do_call:
21621 testl $_TIF_ALLWORK_MASK, %ecx
21622 jne sysexit_audit
21623 sysenter_exit:
21624+
21625+#ifdef CONFIG_PAX_RANDKSTACK
21626+ pushl_cfi %eax
21627+ movl %esp, %eax
21628+ call pax_randomize_kstack
21629+ popl_cfi %eax
21630+#endif
21631+
21632+ pax_erase_kstack
21633+
21634 /* if something modifies registers it must also disable sysexit */
21635 movl PT_EIP(%esp), %edx
21636 movl PT_OLDESP(%esp), %ecx
21637 xorl %ebp,%ebp
21638 TRACE_IRQS_ON
21639 1: mov PT_FS(%esp), %fs
21640+2: mov PT_DS(%esp), %ds
21641+3: mov PT_ES(%esp), %es
21642 PTGS_TO_GS
21643 ENABLE_INTERRUPTS_SYSEXIT
21644
21645@@ -463,6 +647,9 @@ sysenter_audit:
21646 movl %eax,%edx /* 2nd arg: syscall number */
21647 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21648 call __audit_syscall_entry
21649+
21650+ pax_erase_kstack
21651+
21652 pushl_cfi %ebx
21653 movl PT_EAX(%esp),%eax /* reload syscall number */
21654 jmp sysenter_do_call
21655@@ -488,10 +675,16 @@ sysexit_audit:
21656
21657 CFI_ENDPROC
21658 .pushsection .fixup,"ax"
21659-2: movl $0,PT_FS(%esp)
21660+4: movl $0,PT_FS(%esp)
21661+ jmp 1b
21662+5: movl $0,PT_DS(%esp)
21663+ jmp 1b
21664+6: movl $0,PT_ES(%esp)
21665 jmp 1b
21666 .popsection
21667- _ASM_EXTABLE(1b,2b)
21668+ _ASM_EXTABLE(1b,4b)
21669+ _ASM_EXTABLE(2b,5b)
21670+ _ASM_EXTABLE(3b,6b)
21671 PTGS_TO_GS_EX
21672 ENDPROC(ia32_sysenter_target)
21673
21674@@ -506,6 +699,11 @@ ENTRY(system_call)
21675 pushl_cfi %eax # save orig_eax
21676 SAVE_ALL
21677 GET_THREAD_INFO(%ebp)
21678+
21679+#ifdef CONFIG_PAX_RANDKSTACK
21680+ pax_erase_kstack
21681+#endif
21682+
21683 # system call tracing in operation / emulation
21684 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21685 jnz syscall_trace_entry
21686@@ -524,6 +722,15 @@ syscall_exit:
21687 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21688 jne syscall_exit_work
21689
21690+restore_all_pax:
21691+
21692+#ifdef CONFIG_PAX_RANDKSTACK
21693+ movl %esp, %eax
21694+ call pax_randomize_kstack
21695+#endif
21696+
21697+ pax_erase_kstack
21698+
21699 restore_all:
21700 TRACE_IRQS_IRET
21701 restore_all_notrace:
21702@@ -580,14 +787,34 @@ ldt_ss:
21703 * compensating for the offset by changing to the ESPFIX segment with
21704 * a base address that matches for the difference.
21705 */
21706-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21707+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21708 mov %esp, %edx /* load kernel esp */
21709 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21710 mov %dx, %ax /* eax: new kernel esp */
21711 sub %eax, %edx /* offset (low word is 0) */
21712+#ifdef CONFIG_SMP
21713+ movl PER_CPU_VAR(cpu_number), %ebx
21714+ shll $PAGE_SHIFT_asm, %ebx
21715+ addl $cpu_gdt_table, %ebx
21716+#else
21717+ movl $cpu_gdt_table, %ebx
21718+#endif
21719 shr $16, %edx
21720- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21721- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21722+
21723+#ifdef CONFIG_PAX_KERNEXEC
21724+ mov %cr0, %esi
21725+ btr $16, %esi
21726+ mov %esi, %cr0
21727+#endif
21728+
21729+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21730+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21731+
21732+#ifdef CONFIG_PAX_KERNEXEC
21733+ bts $16, %esi
21734+ mov %esi, %cr0
21735+#endif
21736+
21737 pushl_cfi $__ESPFIX_SS
21738 pushl_cfi %eax /* new kernel esp */
21739 /* Disable interrupts, but do not irqtrace this section: we
21740@@ -616,20 +843,18 @@ work_resched:
21741 movl TI_flags(%ebp), %ecx
21742 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21743 # than syscall tracing?
21744- jz restore_all
21745+ jz restore_all_pax
21746 testb $_TIF_NEED_RESCHED, %cl
21747 jnz work_resched
21748
21749 work_notifysig: # deal with pending signals and
21750 # notify-resume requests
21751+ movl %esp, %eax
21752 #ifdef CONFIG_VM86
21753 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21754- movl %esp, %eax
21755 jne work_notifysig_v86 # returning to kernel-space or
21756 # vm86-space
21757 1:
21758-#else
21759- movl %esp, %eax
21760 #endif
21761 TRACE_IRQS_ON
21762 ENABLE_INTERRUPTS(CLBR_NONE)
21763@@ -650,7 +875,7 @@ work_notifysig_v86:
21764 movl %eax, %esp
21765 jmp 1b
21766 #endif
21767-END(work_pending)
21768+ENDPROC(work_pending)
21769
21770 # perform syscall exit tracing
21771 ALIGN
21772@@ -658,11 +883,14 @@ syscall_trace_entry:
21773 movl $-ENOSYS,PT_EAX(%esp)
21774 movl %esp, %eax
21775 call syscall_trace_enter
21776+
21777+ pax_erase_kstack
21778+
21779 /* What it returned is what we'll actually use. */
21780 cmpl $(NR_syscalls), %eax
21781 jnae syscall_call
21782 jmp syscall_exit
21783-END(syscall_trace_entry)
21784+ENDPROC(syscall_trace_entry)
21785
21786 # perform syscall exit tracing
21787 ALIGN
21788@@ -675,21 +903,25 @@ syscall_exit_work:
21789 movl %esp, %eax
21790 call syscall_trace_leave
21791 jmp resume_userspace
21792-END(syscall_exit_work)
21793+ENDPROC(syscall_exit_work)
21794 CFI_ENDPROC
21795
21796 RING0_INT_FRAME # can't unwind into user space anyway
21797 syscall_fault:
21798+#ifdef CONFIG_PAX_MEMORY_UDEREF
21799+ push %ss
21800+ pop %ds
21801+#endif
21802 ASM_CLAC
21803 GET_THREAD_INFO(%ebp)
21804 movl $-EFAULT,PT_EAX(%esp)
21805 jmp resume_userspace
21806-END(syscall_fault)
21807+ENDPROC(syscall_fault)
21808
21809 syscall_badsys:
21810 movl $-ENOSYS,PT_EAX(%esp)
21811 jmp resume_userspace
21812-END(syscall_badsys)
21813+ENDPROC(syscall_badsys)
21814 CFI_ENDPROC
21815 /*
21816 * End of kprobes section
21817@@ -705,8 +937,15 @@ END(syscall_badsys)
21818 * normal stack and adjusts ESP with the matching offset.
21819 */
21820 /* fixup the stack */
21821- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21822- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21823+#ifdef CONFIG_SMP
21824+ movl PER_CPU_VAR(cpu_number), %ebx
21825+ shll $PAGE_SHIFT_asm, %ebx
21826+ addl $cpu_gdt_table, %ebx
21827+#else
21828+ movl $cpu_gdt_table, %ebx
21829+#endif
21830+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21831+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21832 shl $16, %eax
21833 addl %esp, %eax /* the adjusted stack pointer */
21834 pushl_cfi $__KERNEL_DS
21835@@ -759,7 +998,7 @@ vector=vector+1
21836 .endr
21837 2: jmp common_interrupt
21838 .endr
21839-END(irq_entries_start)
21840+ENDPROC(irq_entries_start)
21841
21842 .previous
21843 END(interrupt)
21844@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
21845 pushl_cfi $do_coprocessor_error
21846 jmp error_code
21847 CFI_ENDPROC
21848-END(coprocessor_error)
21849+ENDPROC(coprocessor_error)
21850
21851 ENTRY(simd_coprocessor_error)
21852 RING0_INT_FRAME
21853@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
21854 .section .altinstructions,"a"
21855 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21856 .previous
21857-.section .altinstr_replacement,"ax"
21858+.section .altinstr_replacement,"a"
21859 663: pushl $do_simd_coprocessor_error
21860 664:
21861 .previous
21862@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
21863 #endif
21864 jmp error_code
21865 CFI_ENDPROC
21866-END(simd_coprocessor_error)
21867+ENDPROC(simd_coprocessor_error)
21868
21869 ENTRY(device_not_available)
21870 RING0_INT_FRAME
21871@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
21872 pushl_cfi $do_device_not_available
21873 jmp error_code
21874 CFI_ENDPROC
21875-END(device_not_available)
21876+ENDPROC(device_not_available)
21877
21878 #ifdef CONFIG_PARAVIRT
21879 ENTRY(native_iret)
21880 iret
21881 _ASM_EXTABLE(native_iret, iret_exc)
21882-END(native_iret)
21883+ENDPROC(native_iret)
21884
21885 ENTRY(native_irq_enable_sysexit)
21886 sti
21887 sysexit
21888-END(native_irq_enable_sysexit)
21889+ENDPROC(native_irq_enable_sysexit)
21890 #endif
21891
21892 ENTRY(overflow)
21893@@ -872,7 +1111,7 @@ ENTRY(overflow)
21894 pushl_cfi $do_overflow
21895 jmp error_code
21896 CFI_ENDPROC
21897-END(overflow)
21898+ENDPROC(overflow)
21899
21900 ENTRY(bounds)
21901 RING0_INT_FRAME
21902@@ -881,7 +1120,7 @@ ENTRY(bounds)
21903 pushl_cfi $do_bounds
21904 jmp error_code
21905 CFI_ENDPROC
21906-END(bounds)
21907+ENDPROC(bounds)
21908
21909 ENTRY(invalid_op)
21910 RING0_INT_FRAME
21911@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
21912 pushl_cfi $do_invalid_op
21913 jmp error_code
21914 CFI_ENDPROC
21915-END(invalid_op)
21916+ENDPROC(invalid_op)
21917
21918 ENTRY(coprocessor_segment_overrun)
21919 RING0_INT_FRAME
21920@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
21921 pushl_cfi $do_coprocessor_segment_overrun
21922 jmp error_code
21923 CFI_ENDPROC
21924-END(coprocessor_segment_overrun)
21925+ENDPROC(coprocessor_segment_overrun)
21926
21927 ENTRY(invalid_TSS)
21928 RING0_EC_FRAME
21929@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
21930 pushl_cfi $do_invalid_TSS
21931 jmp error_code
21932 CFI_ENDPROC
21933-END(invalid_TSS)
21934+ENDPROC(invalid_TSS)
21935
21936 ENTRY(segment_not_present)
21937 RING0_EC_FRAME
21938@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
21939 pushl_cfi $do_segment_not_present
21940 jmp error_code
21941 CFI_ENDPROC
21942-END(segment_not_present)
21943+ENDPROC(segment_not_present)
21944
21945 ENTRY(stack_segment)
21946 RING0_EC_FRAME
21947@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
21948 pushl_cfi $do_stack_segment
21949 jmp error_code
21950 CFI_ENDPROC
21951-END(stack_segment)
21952+ENDPROC(stack_segment)
21953
21954 ENTRY(alignment_check)
21955 RING0_EC_FRAME
21956@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
21957 pushl_cfi $do_alignment_check
21958 jmp error_code
21959 CFI_ENDPROC
21960-END(alignment_check)
21961+ENDPROC(alignment_check)
21962
21963 ENTRY(divide_error)
21964 RING0_INT_FRAME
21965@@ -940,7 +1179,7 @@ ENTRY(divide_error)
21966 pushl_cfi $do_divide_error
21967 jmp error_code
21968 CFI_ENDPROC
21969-END(divide_error)
21970+ENDPROC(divide_error)
21971
21972 #ifdef CONFIG_X86_MCE
21973 ENTRY(machine_check)
21974@@ -950,7 +1189,7 @@ ENTRY(machine_check)
21975 pushl_cfi machine_check_vector
21976 jmp error_code
21977 CFI_ENDPROC
21978-END(machine_check)
21979+ENDPROC(machine_check)
21980 #endif
21981
21982 ENTRY(spurious_interrupt_bug)
21983@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
21984 pushl_cfi $do_spurious_interrupt_bug
21985 jmp error_code
21986 CFI_ENDPROC
21987-END(spurious_interrupt_bug)
21988+ENDPROC(spurious_interrupt_bug)
21989 /*
21990 * End of kprobes section
21991 */
21992@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21993
21994 ENTRY(mcount)
21995 ret
21996-END(mcount)
21997+ENDPROC(mcount)
21998
21999 ENTRY(ftrace_caller)
22000 cmpl $0, function_trace_stop
22001@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22002 .globl ftrace_stub
22003 ftrace_stub:
22004 ret
22005-END(ftrace_caller)
22006+ENDPROC(ftrace_caller)
22007
22008 ENTRY(ftrace_regs_caller)
22009 pushf /* push flags before compare (in cs location) */
22010@@ -1207,7 +1446,7 @@ trace:
22011 popl %ecx
22012 popl %eax
22013 jmp ftrace_stub
22014-END(mcount)
22015+ENDPROC(mcount)
22016 #endif /* CONFIG_DYNAMIC_FTRACE */
22017 #endif /* CONFIG_FUNCTION_TRACER */
22018
22019@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22020 popl %ecx
22021 popl %eax
22022 ret
22023-END(ftrace_graph_caller)
22024+ENDPROC(ftrace_graph_caller)
22025
22026 .globl return_to_handler
22027 return_to_handler:
22028@@ -1291,15 +1530,18 @@ error_code:
22029 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22030 REG_TO_PTGS %ecx
22031 SET_KERNEL_GS %ecx
22032- movl $(__USER_DS), %ecx
22033+ movl $(__KERNEL_DS), %ecx
22034 movl %ecx, %ds
22035 movl %ecx, %es
22036+
22037+ pax_enter_kernel
22038+
22039 TRACE_IRQS_OFF
22040 movl %esp,%eax # pt_regs pointer
22041 call *%edi
22042 jmp ret_from_exception
22043 CFI_ENDPROC
22044-END(page_fault)
22045+ENDPROC(page_fault)
22046
22047 /*
22048 * Debug traps and NMI can happen at the one SYSENTER instruction
22049@@ -1342,7 +1584,7 @@ debug_stack_correct:
22050 call do_debug
22051 jmp ret_from_exception
22052 CFI_ENDPROC
22053-END(debug)
22054+ENDPROC(debug)
22055
22056 /*
22057 * NMI is doubly nasty. It can happen _while_ we're handling
22058@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22059 xorl %edx,%edx # zero error code
22060 movl %esp,%eax # pt_regs pointer
22061 call do_nmi
22062+
22063+ pax_exit_kernel
22064+
22065 jmp restore_all_notrace
22066 CFI_ENDPROC
22067
22068@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22069 FIXUP_ESPFIX_STACK # %eax == %esp
22070 xorl %edx,%edx # zero error code
22071 call do_nmi
22072+
22073+ pax_exit_kernel
22074+
22075 RESTORE_REGS
22076 lss 12+4(%esp), %esp # back to espfix stack
22077 CFI_ADJUST_CFA_OFFSET -24
22078 jmp irq_return
22079 CFI_ENDPROC
22080-END(nmi)
22081+ENDPROC(nmi)
22082
22083 ENTRY(int3)
22084 RING0_INT_FRAME
22085@@ -1434,14 +1682,14 @@ ENTRY(int3)
22086 call do_int3
22087 jmp ret_from_exception
22088 CFI_ENDPROC
22089-END(int3)
22090+ENDPROC(int3)
22091
22092 ENTRY(general_protection)
22093 RING0_EC_FRAME
22094 pushl_cfi $do_general_protection
22095 jmp error_code
22096 CFI_ENDPROC
22097-END(general_protection)
22098+ENDPROC(general_protection)
22099
22100 #ifdef CONFIG_KVM_GUEST
22101 ENTRY(async_page_fault)
22102@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22103 pushl_cfi $do_async_page_fault
22104 jmp error_code
22105 CFI_ENDPROC
22106-END(async_page_fault)
22107+ENDPROC(async_page_fault)
22108 #endif
22109
22110 /*
22111diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22112index 1e96c36..86f2033 100644
22113--- a/arch/x86/kernel/entry_64.S
22114+++ b/arch/x86/kernel/entry_64.S
22115@@ -59,6 +59,8 @@
22116 #include <asm/context_tracking.h>
22117 #include <asm/smap.h>
22118 #include <linux/err.h>
22119+#include <asm/pgtable.h>
22120+#include <asm/alternative-asm.h>
22121
22122 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22123 #include <linux/elf-em.h>
22124@@ -80,8 +82,9 @@
22125 #ifdef CONFIG_DYNAMIC_FTRACE
22126
22127 ENTRY(function_hook)
22128+ pax_force_retaddr
22129 retq
22130-END(function_hook)
22131+ENDPROC(function_hook)
22132
22133 /* skip is set if stack has been adjusted */
22134 .macro ftrace_caller_setup skip=0
22135@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22136 #endif
22137
22138 GLOBAL(ftrace_stub)
22139+ pax_force_retaddr
22140 retq
22141-END(ftrace_caller)
22142+ENDPROC(ftrace_caller)
22143
22144 ENTRY(ftrace_regs_caller)
22145 /* Save the current flags before compare (in SS location)*/
22146@@ -191,7 +195,7 @@ ftrace_restore_flags:
22147 popfq
22148 jmp ftrace_stub
22149
22150-END(ftrace_regs_caller)
22151+ENDPROC(ftrace_regs_caller)
22152
22153
22154 #else /* ! CONFIG_DYNAMIC_FTRACE */
22155@@ -212,6 +216,7 @@ ENTRY(function_hook)
22156 #endif
22157
22158 GLOBAL(ftrace_stub)
22159+ pax_force_retaddr
22160 retq
22161
22162 trace:
22163@@ -225,12 +230,13 @@ trace:
22164 #endif
22165 subq $MCOUNT_INSN_SIZE, %rdi
22166
22167+ pax_force_fptr ftrace_trace_function
22168 call *ftrace_trace_function
22169
22170 MCOUNT_RESTORE_FRAME
22171
22172 jmp ftrace_stub
22173-END(function_hook)
22174+ENDPROC(function_hook)
22175 #endif /* CONFIG_DYNAMIC_FTRACE */
22176 #endif /* CONFIG_FUNCTION_TRACER */
22177
22178@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22179
22180 MCOUNT_RESTORE_FRAME
22181
22182+ pax_force_retaddr
22183 retq
22184-END(ftrace_graph_caller)
22185+ENDPROC(ftrace_graph_caller)
22186
22187 GLOBAL(return_to_handler)
22188 subq $24, %rsp
22189@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22190 movq 8(%rsp), %rdx
22191 movq (%rsp), %rax
22192 addq $24, %rsp
22193+ pax_force_fptr %rdi
22194 jmp *%rdi
22195+ENDPROC(return_to_handler)
22196 #endif
22197
22198
22199@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22200 ENDPROC(native_usergs_sysret64)
22201 #endif /* CONFIG_PARAVIRT */
22202
22203+ .macro ljmpq sel, off
22204+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22205+ .byte 0x48; ljmp *1234f(%rip)
22206+ .pushsection .rodata
22207+ .align 16
22208+ 1234: .quad \off; .word \sel
22209+ .popsection
22210+#else
22211+ pushq $\sel
22212+ pushq $\off
22213+ lretq
22214+#endif
22215+ .endm
22216+
22217+ .macro pax_enter_kernel
22218+ pax_set_fptr_mask
22219+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22220+ call pax_enter_kernel
22221+#endif
22222+ .endm
22223+
22224+ .macro pax_exit_kernel
22225+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22226+ call pax_exit_kernel
22227+#endif
22228+
22229+ .endm
22230+
22231+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22232+ENTRY(pax_enter_kernel)
22233+ pushq %rdi
22234+
22235+#ifdef CONFIG_PARAVIRT
22236+ PV_SAVE_REGS(CLBR_RDI)
22237+#endif
22238+
22239+#ifdef CONFIG_PAX_KERNEXEC
22240+ GET_CR0_INTO_RDI
22241+ bts $16,%rdi
22242+ jnc 3f
22243+ mov %cs,%edi
22244+ cmp $__KERNEL_CS,%edi
22245+ jnz 2f
22246+1:
22247+#endif
22248+
22249+#ifdef CONFIG_PAX_MEMORY_UDEREF
22250+ 661: jmp 111f
22251+ .pushsection .altinstr_replacement, "a"
22252+ 662: ASM_NOP2
22253+ .popsection
22254+ .pushsection .altinstructions, "a"
22255+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22256+ .popsection
22257+ GET_CR3_INTO_RDI
22258+ cmp $0,%dil
22259+ jnz 112f
22260+ mov $__KERNEL_DS,%edi
22261+ mov %edi,%ss
22262+ jmp 111f
22263+112: cmp $1,%dil
22264+ jz 113f
22265+ ud2
22266+113: sub $4097,%rdi
22267+ bts $63,%rdi
22268+ SET_RDI_INTO_CR3
22269+ mov $__UDEREF_KERNEL_DS,%edi
22270+ mov %edi,%ss
22271+111:
22272+#endif
22273+
22274+#ifdef CONFIG_PARAVIRT
22275+ PV_RESTORE_REGS(CLBR_RDI)
22276+#endif
22277+
22278+ popq %rdi
22279+ pax_force_retaddr
22280+ retq
22281+
22282+#ifdef CONFIG_PAX_KERNEXEC
22283+2: ljmpq __KERNEL_CS,1b
22284+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22285+4: SET_RDI_INTO_CR0
22286+ jmp 1b
22287+#endif
22288+ENDPROC(pax_enter_kernel)
22289+
22290+ENTRY(pax_exit_kernel)
22291+ pushq %rdi
22292+
22293+#ifdef CONFIG_PARAVIRT
22294+ PV_SAVE_REGS(CLBR_RDI)
22295+#endif
22296+
22297+#ifdef CONFIG_PAX_KERNEXEC
22298+ mov %cs,%rdi
22299+ cmp $__KERNEXEC_KERNEL_CS,%edi
22300+ jz 2f
22301+ GET_CR0_INTO_RDI
22302+ bts $16,%rdi
22303+ jnc 4f
22304+1:
22305+#endif
22306+
22307+#ifdef CONFIG_PAX_MEMORY_UDEREF
22308+ 661: jmp 111f
22309+ .pushsection .altinstr_replacement, "a"
22310+ 662: ASM_NOP2
22311+ .popsection
22312+ .pushsection .altinstructions, "a"
22313+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22314+ .popsection
22315+ mov %ss,%edi
22316+ cmp $__UDEREF_KERNEL_DS,%edi
22317+ jnz 111f
22318+ GET_CR3_INTO_RDI
22319+ cmp $0,%dil
22320+ jz 112f
22321+ ud2
22322+112: add $4097,%rdi
22323+ bts $63,%rdi
22324+ SET_RDI_INTO_CR3
22325+ mov $__KERNEL_DS,%edi
22326+ mov %edi,%ss
22327+111:
22328+#endif
22329+
22330+#ifdef CONFIG_PARAVIRT
22331+ PV_RESTORE_REGS(CLBR_RDI);
22332+#endif
22333+
22334+ popq %rdi
22335+ pax_force_retaddr
22336+ retq
22337+
22338+#ifdef CONFIG_PAX_KERNEXEC
22339+2: GET_CR0_INTO_RDI
22340+ btr $16,%rdi
22341+ jnc 4f
22342+ ljmpq __KERNEL_CS,3f
22343+3: SET_RDI_INTO_CR0
22344+ jmp 1b
22345+4: ud2
22346+ jmp 4b
22347+#endif
22348+ENDPROC(pax_exit_kernel)
22349+#endif
22350+
22351+ .macro pax_enter_kernel_user
22352+ pax_set_fptr_mask
22353+#ifdef CONFIG_PAX_MEMORY_UDEREF
22354+ call pax_enter_kernel_user
22355+#endif
22356+ .endm
22357+
22358+ .macro pax_exit_kernel_user
22359+#ifdef CONFIG_PAX_MEMORY_UDEREF
22360+ call pax_exit_kernel_user
22361+#endif
22362+#ifdef CONFIG_PAX_RANDKSTACK
22363+ pushq %rax
22364+ pushq %r11
22365+ call pax_randomize_kstack
22366+ popq %r11
22367+ popq %rax
22368+#endif
22369+ .endm
22370+
22371+#ifdef CONFIG_PAX_MEMORY_UDEREF
22372+ENTRY(pax_enter_kernel_user)
22373+ pushq %rdi
22374+ pushq %rbx
22375+
22376+#ifdef CONFIG_PARAVIRT
22377+ PV_SAVE_REGS(CLBR_RDI)
22378+#endif
22379+
22380+ 661: jmp 111f
22381+ .pushsection .altinstr_replacement, "a"
22382+ 662: ASM_NOP2
22383+ .popsection
22384+ .pushsection .altinstructions, "a"
22385+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22386+ .popsection
22387+ GET_CR3_INTO_RDI
22388+ cmp $1,%dil
22389+ jnz 4f
22390+ sub $4097,%rdi
22391+ bts $63,%rdi
22392+ SET_RDI_INTO_CR3
22393+ jmp 3f
22394+111:
22395+
22396+ GET_CR3_INTO_RDI
22397+ mov %rdi,%rbx
22398+ add $__START_KERNEL_map,%rbx
22399+ sub phys_base(%rip),%rbx
22400+
22401+#ifdef CONFIG_PARAVIRT
22402+ cmpl $0, pv_info+PARAVIRT_enabled
22403+ jz 1f
22404+ pushq %rdi
22405+ i = 0
22406+ .rept USER_PGD_PTRS
22407+ mov i*8(%rbx),%rsi
22408+ mov $0,%sil
22409+ lea i*8(%rbx),%rdi
22410+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22411+ i = i + 1
22412+ .endr
22413+ popq %rdi
22414+ jmp 2f
22415+1:
22416+#endif
22417+
22418+ i = 0
22419+ .rept USER_PGD_PTRS
22420+ movb $0,i*8(%rbx)
22421+ i = i + 1
22422+ .endr
22423+
22424+2: SET_RDI_INTO_CR3
22425+
22426+#ifdef CONFIG_PAX_KERNEXEC
22427+ GET_CR0_INTO_RDI
22428+ bts $16,%rdi
22429+ SET_RDI_INTO_CR0
22430+#endif
22431+
22432+3:
22433+
22434+#ifdef CONFIG_PARAVIRT
22435+ PV_RESTORE_REGS(CLBR_RDI)
22436+#endif
22437+
22438+ popq %rbx
22439+ popq %rdi
22440+ pax_force_retaddr
22441+ retq
22442+4: ud2
22443+ENDPROC(pax_enter_kernel_user)
22444+
22445+ENTRY(pax_exit_kernel_user)
22446+ pushq %rdi
22447+ pushq %rbx
22448+
22449+#ifdef CONFIG_PARAVIRT
22450+ PV_SAVE_REGS(CLBR_RDI)
22451+#endif
22452+
22453+ GET_CR3_INTO_RDI
22454+ 661: jmp 1f
22455+ .pushsection .altinstr_replacement, "a"
22456+ 662: ASM_NOP2
22457+ .popsection
22458+ .pushsection .altinstructions, "a"
22459+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22460+ .popsection
22461+ cmp $0,%dil
22462+ jnz 3f
22463+ add $4097,%rdi
22464+ bts $63,%rdi
22465+ SET_RDI_INTO_CR3
22466+ jmp 2f
22467+1:
22468+
22469+ mov %rdi,%rbx
22470+
22471+#ifdef CONFIG_PAX_KERNEXEC
22472+ GET_CR0_INTO_RDI
22473+ btr $16,%rdi
22474+ jnc 3f
22475+ SET_RDI_INTO_CR0
22476+#endif
22477+
22478+ add $__START_KERNEL_map,%rbx
22479+ sub phys_base(%rip),%rbx
22480+
22481+#ifdef CONFIG_PARAVIRT
22482+ cmpl $0, pv_info+PARAVIRT_enabled
22483+ jz 1f
22484+ i = 0
22485+ .rept USER_PGD_PTRS
22486+ mov i*8(%rbx),%rsi
22487+ mov $0x67,%sil
22488+ lea i*8(%rbx),%rdi
22489+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22490+ i = i + 1
22491+ .endr
22492+ jmp 2f
22493+1:
22494+#endif
22495+
22496+ i = 0
22497+ .rept USER_PGD_PTRS
22498+ movb $0x67,i*8(%rbx)
22499+ i = i + 1
22500+ .endr
22501+2:
22502+
22503+#ifdef CONFIG_PARAVIRT
22504+ PV_RESTORE_REGS(CLBR_RDI)
22505+#endif
22506+
22507+ popq %rbx
22508+ popq %rdi
22509+ pax_force_retaddr
22510+ retq
22511+3: ud2
22512+ENDPROC(pax_exit_kernel_user)
22513+#endif
22514+
22515+ .macro pax_enter_kernel_nmi
22516+ pax_set_fptr_mask
22517+
22518+#ifdef CONFIG_PAX_KERNEXEC
22519+ GET_CR0_INTO_RDI
22520+ bts $16,%rdi
22521+ jc 110f
22522+ SET_RDI_INTO_CR0
22523+ or $2,%ebx
22524+110:
22525+#endif
22526+
22527+#ifdef CONFIG_PAX_MEMORY_UDEREF
22528+ 661: jmp 111f
22529+ .pushsection .altinstr_replacement, "a"
22530+ 662: ASM_NOP2
22531+ .popsection
22532+ .pushsection .altinstructions, "a"
22533+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22534+ .popsection
22535+ GET_CR3_INTO_RDI
22536+ cmp $0,%dil
22537+ jz 111f
22538+ sub $4097,%rdi
22539+ or $4,%ebx
22540+ bts $63,%rdi
22541+ SET_RDI_INTO_CR3
22542+ mov $__UDEREF_KERNEL_DS,%edi
22543+ mov %edi,%ss
22544+111:
22545+#endif
22546+ .endm
22547+
22548+ .macro pax_exit_kernel_nmi
22549+#ifdef CONFIG_PAX_KERNEXEC
22550+ btr $1,%ebx
22551+ jnc 110f
22552+ GET_CR0_INTO_RDI
22553+ btr $16,%rdi
22554+ SET_RDI_INTO_CR0
22555+110:
22556+#endif
22557+
22558+#ifdef CONFIG_PAX_MEMORY_UDEREF
22559+ btr $2,%ebx
22560+ jnc 111f
22561+ GET_CR3_INTO_RDI
22562+ add $4097,%rdi
22563+ bts $63,%rdi
22564+ SET_RDI_INTO_CR3
22565+ mov $__KERNEL_DS,%edi
22566+ mov %edi,%ss
22567+111:
22568+#endif
22569+ .endm
22570+
22571+ .macro pax_erase_kstack
22572+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22573+ call pax_erase_kstack
22574+#endif
22575+ .endm
22576+
22577+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22578+ENTRY(pax_erase_kstack)
22579+ pushq %rdi
22580+ pushq %rcx
22581+ pushq %rax
22582+ pushq %r11
22583+
22584+ GET_THREAD_INFO(%r11)
22585+ mov TI_lowest_stack(%r11), %rdi
22586+ mov $-0xBEEF, %rax
22587+ std
22588+
22589+1: mov %edi, %ecx
22590+ and $THREAD_SIZE_asm - 1, %ecx
22591+ shr $3, %ecx
22592+ repne scasq
22593+ jecxz 2f
22594+
22595+ cmp $2*8, %ecx
22596+ jc 2f
22597+
22598+ mov $2*8, %ecx
22599+ repe scasq
22600+ jecxz 2f
22601+ jne 1b
22602+
22603+2: cld
22604+ mov %esp, %ecx
22605+ sub %edi, %ecx
22606+
22607+ cmp $THREAD_SIZE_asm, %rcx
22608+ jb 3f
22609+ ud2
22610+3:
22611+
22612+ shr $3, %ecx
22613+ rep stosq
22614+
22615+ mov TI_task_thread_sp0(%r11), %rdi
22616+ sub $256, %rdi
22617+ mov %rdi, TI_lowest_stack(%r11)
22618+
22619+ popq %r11
22620+ popq %rax
22621+ popq %rcx
22622+ popq %rdi
22623+ pax_force_retaddr
22624+ ret
22625+ENDPROC(pax_erase_kstack)
22626+#endif
22627
22628 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22629 #ifdef CONFIG_TRACE_IRQFLAGS
22630@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
22631 .endm
22632
22633 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
22634- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
22635+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
22636 jnc 1f
22637 TRACE_IRQS_ON_DEBUG
22638 1:
22639@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
22640 movq \tmp,R11+\offset(%rsp)
22641 .endm
22642
22643- .macro FAKE_STACK_FRAME child_rip
22644- /* push in order ss, rsp, eflags, cs, rip */
22645- xorl %eax, %eax
22646- pushq_cfi $__KERNEL_DS /* ss */
22647- /*CFI_REL_OFFSET ss,0*/
22648- pushq_cfi %rax /* rsp */
22649- CFI_REL_OFFSET rsp,0
22650- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
22651- /*CFI_REL_OFFSET rflags,0*/
22652- pushq_cfi $__KERNEL_CS /* cs */
22653- /*CFI_REL_OFFSET cs,0*/
22654- pushq_cfi \child_rip /* rip */
22655- CFI_REL_OFFSET rip,0
22656- pushq_cfi %rax /* orig rax */
22657- .endm
22658-
22659- .macro UNFAKE_STACK_FRAME
22660- addq $8*6, %rsp
22661- CFI_ADJUST_CFA_OFFSET -(6*8)
22662- .endm
22663-
22664 /*
22665 * initial frame state for interrupts (and exceptions without error code)
22666 */
22667@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
22668 /* save partial stack frame */
22669 .macro SAVE_ARGS_IRQ
22670 cld
22671- /* start from rbp in pt_regs and jump over */
22672- movq_cfi rdi, (RDI-RBP)
22673- movq_cfi rsi, (RSI-RBP)
22674- movq_cfi rdx, (RDX-RBP)
22675- movq_cfi rcx, (RCX-RBP)
22676- movq_cfi rax, (RAX-RBP)
22677- movq_cfi r8, (R8-RBP)
22678- movq_cfi r9, (R9-RBP)
22679- movq_cfi r10, (R10-RBP)
22680- movq_cfi r11, (R11-RBP)
22681+ /* start from r15 in pt_regs and jump over */
22682+ movq_cfi rdi, RDI
22683+ movq_cfi rsi, RSI
22684+ movq_cfi rdx, RDX
22685+ movq_cfi rcx, RCX
22686+ movq_cfi rax, RAX
22687+ movq_cfi r8, R8
22688+ movq_cfi r9, R9
22689+ movq_cfi r10, R10
22690+ movq_cfi r11, R11
22691+ movq_cfi r12, R12
22692
22693 /* Save rbp so that we can unwind from get_irq_regs() */
22694- movq_cfi rbp, 0
22695+ movq_cfi rbp, RBP
22696
22697 /* Save previous stack value */
22698 movq %rsp, %rsi
22699
22700- leaq -RBP(%rsp),%rdi /* arg1 for handler */
22701- testl $3, CS-RBP(%rsi)
22702+ movq %rsp,%rdi /* arg1 for handler */
22703+ testb $3, CS(%rsi)
22704 je 1f
22705 SWAPGS
22706 /*
22707@@ -514,9 +927,52 @@ ENTRY(save_paranoid)
22708 js 1f /* negative -> in kernel */
22709 SWAPGS
22710 xorl %ebx,%ebx
22711-1: ret
22712+1:
22713+#ifdef CONFIG_PAX_MEMORY_UDEREF
22714+ testb $3, CS+8(%rsp)
22715+ jnz 1f
22716+ pax_enter_kernel
22717+ jmp 2f
22718+1: pax_enter_kernel_user
22719+2:
22720+#else
22721+ pax_enter_kernel
22722+#endif
22723+ pax_force_retaddr
22724+ ret
22725 CFI_ENDPROC
22726-END(save_paranoid)
22727+ENDPROC(save_paranoid)
22728+
22729+ENTRY(save_paranoid_nmi)
22730+ XCPT_FRAME 1 RDI+8
22731+ cld
22732+ movq_cfi rdi, RDI+8
22733+ movq_cfi rsi, RSI+8
22734+ movq_cfi rdx, RDX+8
22735+ movq_cfi rcx, RCX+8
22736+ movq_cfi rax, RAX+8
22737+ movq_cfi r8, R8+8
22738+ movq_cfi r9, R9+8
22739+ movq_cfi r10, R10+8
22740+ movq_cfi r11, R11+8
22741+ movq_cfi rbx, RBX+8
22742+ movq_cfi rbp, RBP+8
22743+ movq_cfi r12, R12+8
22744+ movq_cfi r13, R13+8
22745+ movq_cfi r14, R14+8
22746+ movq_cfi r15, R15+8
22747+ movl $1,%ebx
22748+ movl $MSR_GS_BASE,%ecx
22749+ rdmsr
22750+ testl %edx,%edx
22751+ js 1f /* negative -> in kernel */
22752+ SWAPGS
22753+ xorl %ebx,%ebx
22754+1: pax_enter_kernel_nmi
22755+ pax_force_retaddr
22756+ ret
22757+ CFI_ENDPROC
22758+ENDPROC(save_paranoid_nmi)
22759 .popsection
22760
22761 /*
22762@@ -538,7 +994,7 @@ ENTRY(ret_from_fork)
22763
22764 RESTORE_REST
22765
22766- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22767+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22768 jz 1f
22769
22770 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22771@@ -548,15 +1004,13 @@ ENTRY(ret_from_fork)
22772 jmp ret_from_sys_call # go to the SYSRET fastpath
22773
22774 1:
22775- subq $REST_SKIP, %rsp # leave space for volatiles
22776- CFI_ADJUST_CFA_OFFSET REST_SKIP
22777 movq %rbp, %rdi
22778 call *%rbx
22779 movl $0, RAX(%rsp)
22780 RESTORE_REST
22781 jmp int_ret_from_sys_call
22782 CFI_ENDPROC
22783-END(ret_from_fork)
22784+ENDPROC(ret_from_fork)
22785
22786 /*
22787 * System call entry. Up to 6 arguments in registers are supported.
22788@@ -593,7 +1047,7 @@ END(ret_from_fork)
22789 ENTRY(system_call)
22790 CFI_STARTPROC simple
22791 CFI_SIGNAL_FRAME
22792- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22793+ CFI_DEF_CFA rsp,0
22794 CFI_REGISTER rip,rcx
22795 /*CFI_REGISTER rflags,r11*/
22796 SWAPGS_UNSAFE_STACK
22797@@ -606,16 +1060,23 @@ GLOBAL(system_call_after_swapgs)
22798
22799 movq %rsp,PER_CPU_VAR(old_rsp)
22800 movq PER_CPU_VAR(kernel_stack),%rsp
22801+ SAVE_ARGS 8*6,0
22802+ pax_enter_kernel_user
22803+
22804+#ifdef CONFIG_PAX_RANDKSTACK
22805+ pax_erase_kstack
22806+#endif
22807+
22808 /*
22809 * No need to follow this irqs off/on section - it's straight
22810 * and short:
22811 */
22812 ENABLE_INTERRUPTS(CLBR_NONE)
22813- SAVE_ARGS 8,0
22814 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22815 movq %rcx,RIP-ARGOFFSET(%rsp)
22816 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22817- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22818+ GET_THREAD_INFO(%rcx)
22819+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22820 jnz tracesys
22821 system_call_fastpath:
22822 #if __SYSCALL_MASK == ~0
22823@@ -639,10 +1100,13 @@ sysret_check:
22824 LOCKDEP_SYS_EXIT
22825 DISABLE_INTERRUPTS(CLBR_NONE)
22826 TRACE_IRQS_OFF
22827- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22828+ GET_THREAD_INFO(%rcx)
22829+ movl TI_flags(%rcx),%edx
22830 andl %edi,%edx
22831 jnz sysret_careful
22832 CFI_REMEMBER_STATE
22833+ pax_exit_kernel_user
22834+ pax_erase_kstack
22835 /*
22836 * sysretq will re-enable interrupts:
22837 */
22838@@ -701,6 +1165,9 @@ auditsys:
22839 movq %rax,%rsi /* 2nd arg: syscall number */
22840 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22841 call __audit_syscall_entry
22842+
22843+ pax_erase_kstack
22844+
22845 LOAD_ARGS 0 /* reload call-clobbered registers */
22846 jmp system_call_fastpath
22847
22848@@ -722,7 +1189,7 @@ sysret_audit:
22849 /* Do syscall tracing */
22850 tracesys:
22851 #ifdef CONFIG_AUDITSYSCALL
22852- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22853+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22854 jz auditsys
22855 #endif
22856 SAVE_REST
22857@@ -730,12 +1197,15 @@ tracesys:
22858 FIXUP_TOP_OF_STACK %rdi
22859 movq %rsp,%rdi
22860 call syscall_trace_enter
22861+
22862+ pax_erase_kstack
22863+
22864 /*
22865 * Reload arg registers from stack in case ptrace changed them.
22866 * We don't reload %rax because syscall_trace_enter() returned
22867 * the value it wants us to use in the table lookup.
22868 */
22869- LOAD_ARGS ARGOFFSET, 1
22870+ LOAD_ARGS 1
22871 RESTORE_REST
22872 #if __SYSCALL_MASK == ~0
22873 cmpq $__NR_syscall_max,%rax
22874@@ -765,7 +1235,9 @@ GLOBAL(int_with_check)
22875 andl %edi,%edx
22876 jnz int_careful
22877 andl $~TS_COMPAT,TI_status(%rcx)
22878- jmp retint_swapgs
22879+ pax_exit_kernel_user
22880+ pax_erase_kstack
22881+ jmp retint_swapgs_pax
22882
22883 /* Either reschedule or signal or syscall exit tracking needed. */
22884 /* First do a reschedule test. */
22885@@ -811,7 +1283,7 @@ int_restore_rest:
22886 TRACE_IRQS_OFF
22887 jmp int_with_check
22888 CFI_ENDPROC
22889-END(system_call)
22890+ENDPROC(system_call)
22891
22892 .macro FORK_LIKE func
22893 ENTRY(stub_\func)
22894@@ -824,9 +1296,10 @@ ENTRY(stub_\func)
22895 DEFAULT_FRAME 0 8 /* offset 8: return address */
22896 call sys_\func
22897 RESTORE_TOP_OF_STACK %r11, 8
22898- ret $REST_SKIP /* pop extended registers */
22899+ pax_force_retaddr
22900+ ret
22901 CFI_ENDPROC
22902-END(stub_\func)
22903+ENDPROC(stub_\func)
22904 .endm
22905
22906 .macro FIXED_FRAME label,func
22907@@ -836,9 +1309,10 @@ ENTRY(\label)
22908 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22909 call \func
22910 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22911+ pax_force_retaddr
22912 ret
22913 CFI_ENDPROC
22914-END(\label)
22915+ENDPROC(\label)
22916 .endm
22917
22918 FORK_LIKE clone
22919@@ -846,19 +1320,6 @@ END(\label)
22920 FORK_LIKE vfork
22921 FIXED_FRAME stub_iopl, sys_iopl
22922
22923-ENTRY(ptregscall_common)
22924- DEFAULT_FRAME 1 8 /* offset 8: return address */
22925- RESTORE_TOP_OF_STACK %r11, 8
22926- movq_cfi_restore R15+8, r15
22927- movq_cfi_restore R14+8, r14
22928- movq_cfi_restore R13+8, r13
22929- movq_cfi_restore R12+8, r12
22930- movq_cfi_restore RBP+8, rbp
22931- movq_cfi_restore RBX+8, rbx
22932- ret $REST_SKIP /* pop extended registers */
22933- CFI_ENDPROC
22934-END(ptregscall_common)
22935-
22936 ENTRY(stub_execve)
22937 CFI_STARTPROC
22938 addq $8, %rsp
22939@@ -870,7 +1331,7 @@ ENTRY(stub_execve)
22940 RESTORE_REST
22941 jmp int_ret_from_sys_call
22942 CFI_ENDPROC
22943-END(stub_execve)
22944+ENDPROC(stub_execve)
22945
22946 /*
22947 * sigreturn is special because it needs to restore all registers on return.
22948@@ -887,7 +1348,7 @@ ENTRY(stub_rt_sigreturn)
22949 RESTORE_REST
22950 jmp int_ret_from_sys_call
22951 CFI_ENDPROC
22952-END(stub_rt_sigreturn)
22953+ENDPROC(stub_rt_sigreturn)
22954
22955 #ifdef CONFIG_X86_X32_ABI
22956 ENTRY(stub_x32_rt_sigreturn)
22957@@ -901,7 +1362,7 @@ ENTRY(stub_x32_rt_sigreturn)
22958 RESTORE_REST
22959 jmp int_ret_from_sys_call
22960 CFI_ENDPROC
22961-END(stub_x32_rt_sigreturn)
22962+ENDPROC(stub_x32_rt_sigreturn)
22963
22964 ENTRY(stub_x32_execve)
22965 CFI_STARTPROC
22966@@ -915,7 +1376,7 @@ ENTRY(stub_x32_execve)
22967 RESTORE_REST
22968 jmp int_ret_from_sys_call
22969 CFI_ENDPROC
22970-END(stub_x32_execve)
22971+ENDPROC(stub_x32_execve)
22972
22973 #endif
22974
22975@@ -952,7 +1413,7 @@ vector=vector+1
22976 2: jmp common_interrupt
22977 .endr
22978 CFI_ENDPROC
22979-END(irq_entries_start)
22980+ENDPROC(irq_entries_start)
22981
22982 .previous
22983 END(interrupt)
22984@@ -969,9 +1430,19 @@ END(interrupt)
22985 /* 0(%rsp): ~(interrupt number) */
22986 .macro interrupt func
22987 /* reserve pt_regs for scratch regs and rbp */
22988- subq $ORIG_RAX-RBP, %rsp
22989- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22990+ subq $ORIG_RAX, %rsp
22991+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
22992 SAVE_ARGS_IRQ
22993+#ifdef CONFIG_PAX_MEMORY_UDEREF
22994+ testb $3, CS(%rdi)
22995+ jnz 1f
22996+ pax_enter_kernel
22997+ jmp 2f
22998+1: pax_enter_kernel_user
22999+2:
23000+#else
23001+ pax_enter_kernel
23002+#endif
23003 call \func
23004 .endm
23005
23006@@ -997,14 +1468,14 @@ ret_from_intr:
23007
23008 /* Restore saved previous stack */
23009 popq %rsi
23010- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23011- leaq ARGOFFSET-RBP(%rsi), %rsp
23012+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23013+ movq %rsi, %rsp
23014 CFI_DEF_CFA_REGISTER rsp
23015- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23016+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23017
23018 exit_intr:
23019 GET_THREAD_INFO(%rcx)
23020- testl $3,CS-ARGOFFSET(%rsp)
23021+ testb $3,CS-ARGOFFSET(%rsp)
23022 je retint_kernel
23023
23024 /* Interrupt came from user space */
23025@@ -1026,12 +1497,16 @@ retint_swapgs: /* return to user-space */
23026 * The iretq could re-enable interrupts:
23027 */
23028 DISABLE_INTERRUPTS(CLBR_ANY)
23029+ pax_exit_kernel_user
23030+retint_swapgs_pax:
23031 TRACE_IRQS_IRETQ
23032 SWAPGS
23033 jmp restore_args
23034
23035 retint_restore_args: /* return to kernel space */
23036 DISABLE_INTERRUPTS(CLBR_ANY)
23037+ pax_exit_kernel
23038+ pax_force_retaddr (RIP-ARGOFFSET)
23039 /*
23040 * The iretq could re-enable interrupts:
23041 */
23042@@ -1112,7 +1587,7 @@ ENTRY(retint_kernel)
23043 #endif
23044
23045 CFI_ENDPROC
23046-END(common_interrupt)
23047+ENDPROC(common_interrupt)
23048 /*
23049 * End of kprobes section
23050 */
23051@@ -1130,7 +1605,7 @@ ENTRY(\sym)
23052 interrupt \do_sym
23053 jmp ret_from_intr
23054 CFI_ENDPROC
23055-END(\sym)
23056+ENDPROC(\sym)
23057 .endm
23058
23059 #ifdef CONFIG_TRACING
23060@@ -1218,7 +1693,7 @@ ENTRY(\sym)
23061 call \do_sym
23062 jmp error_exit /* %ebx: no swapgs flag */
23063 CFI_ENDPROC
23064-END(\sym)
23065+ENDPROC(\sym)
23066 .endm
23067
23068 .macro paranoidzeroentry sym do_sym
23069@@ -1236,10 +1711,10 @@ ENTRY(\sym)
23070 call \do_sym
23071 jmp paranoid_exit /* %ebx: no swapgs flag */
23072 CFI_ENDPROC
23073-END(\sym)
23074+ENDPROC(\sym)
23075 .endm
23076
23077-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23078+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23079 .macro paranoidzeroentry_ist sym do_sym ist
23080 ENTRY(\sym)
23081 INTR_FRAME
23082@@ -1252,12 +1727,18 @@ ENTRY(\sym)
23083 TRACE_IRQS_OFF_DEBUG
23084 movq %rsp,%rdi /* pt_regs pointer */
23085 xorl %esi,%esi /* no error code */
23086+#ifdef CONFIG_SMP
23087+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23088+ lea init_tss(%r13), %r13
23089+#else
23090+ lea init_tss(%rip), %r13
23091+#endif
23092 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23093 call \do_sym
23094 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23095 jmp paranoid_exit /* %ebx: no swapgs flag */
23096 CFI_ENDPROC
23097-END(\sym)
23098+ENDPROC(\sym)
23099 .endm
23100
23101 .macro errorentry sym do_sym
23102@@ -1275,7 +1756,7 @@ ENTRY(\sym)
23103 call \do_sym
23104 jmp error_exit /* %ebx: no swapgs flag */
23105 CFI_ENDPROC
23106-END(\sym)
23107+ENDPROC(\sym)
23108 .endm
23109
23110 #ifdef CONFIG_TRACING
23111@@ -1306,7 +1787,7 @@ ENTRY(\sym)
23112 call \do_sym
23113 jmp paranoid_exit /* %ebx: no swapgs flag */
23114 CFI_ENDPROC
23115-END(\sym)
23116+ENDPROC(\sym)
23117 .endm
23118
23119 zeroentry divide_error do_divide_error
23120@@ -1336,9 +1817,10 @@ gs_change:
23121 2: mfence /* workaround */
23122 SWAPGS
23123 popfq_cfi
23124+ pax_force_retaddr
23125 ret
23126 CFI_ENDPROC
23127-END(native_load_gs_index)
23128+ENDPROC(native_load_gs_index)
23129
23130 _ASM_EXTABLE(gs_change,bad_gs)
23131 .section .fixup,"ax"
23132@@ -1366,9 +1848,10 @@ ENTRY(do_softirq_own_stack)
23133 CFI_DEF_CFA_REGISTER rsp
23134 CFI_ADJUST_CFA_OFFSET -8
23135 decl PER_CPU_VAR(irq_count)
23136+ pax_force_retaddr
23137 ret
23138 CFI_ENDPROC
23139-END(do_softirq_own_stack)
23140+ENDPROC(do_softirq_own_stack)
23141
23142 #ifdef CONFIG_XEN
23143 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23144@@ -1406,7 +1889,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23145 decl PER_CPU_VAR(irq_count)
23146 jmp error_exit
23147 CFI_ENDPROC
23148-END(xen_do_hypervisor_callback)
23149+ENDPROC(xen_do_hypervisor_callback)
23150
23151 /*
23152 * Hypervisor uses this for application faults while it executes.
23153@@ -1465,7 +1948,7 @@ ENTRY(xen_failsafe_callback)
23154 SAVE_ALL
23155 jmp error_exit
23156 CFI_ENDPROC
23157-END(xen_failsafe_callback)
23158+ENDPROC(xen_failsafe_callback)
23159
23160 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23161 xen_hvm_callback_vector xen_evtchn_do_upcall
23162@@ -1517,18 +2000,33 @@ ENTRY(paranoid_exit)
23163 DEFAULT_FRAME
23164 DISABLE_INTERRUPTS(CLBR_NONE)
23165 TRACE_IRQS_OFF_DEBUG
23166- testl %ebx,%ebx /* swapgs needed? */
23167+ testl $1,%ebx /* swapgs needed? */
23168 jnz paranoid_restore
23169- testl $3,CS(%rsp)
23170+ testb $3,CS(%rsp)
23171 jnz paranoid_userspace
23172+#ifdef CONFIG_PAX_MEMORY_UDEREF
23173+ pax_exit_kernel
23174+ TRACE_IRQS_IRETQ 0
23175+ SWAPGS_UNSAFE_STACK
23176+ RESTORE_ALL 8
23177+ pax_force_retaddr_bts
23178+ jmp irq_return
23179+#endif
23180 paranoid_swapgs:
23181+#ifdef CONFIG_PAX_MEMORY_UDEREF
23182+ pax_exit_kernel_user
23183+#else
23184+ pax_exit_kernel
23185+#endif
23186 TRACE_IRQS_IRETQ 0
23187 SWAPGS_UNSAFE_STACK
23188 RESTORE_ALL 8
23189 jmp irq_return
23190 paranoid_restore:
23191+ pax_exit_kernel
23192 TRACE_IRQS_IRETQ_DEBUG 0
23193 RESTORE_ALL 8
23194+ pax_force_retaddr_bts
23195 jmp irq_return
23196 paranoid_userspace:
23197 GET_THREAD_INFO(%rcx)
23198@@ -1557,7 +2055,7 @@ paranoid_schedule:
23199 TRACE_IRQS_OFF
23200 jmp paranoid_userspace
23201 CFI_ENDPROC
23202-END(paranoid_exit)
23203+ENDPROC(paranoid_exit)
23204
23205 /*
23206 * Exception entry point. This expects an error code/orig_rax on the stack.
23207@@ -1584,12 +2082,23 @@ ENTRY(error_entry)
23208 movq_cfi r14, R14+8
23209 movq_cfi r15, R15+8
23210 xorl %ebx,%ebx
23211- testl $3,CS+8(%rsp)
23212+ testb $3,CS+8(%rsp)
23213 je error_kernelspace
23214 error_swapgs:
23215 SWAPGS
23216 error_sti:
23217+#ifdef CONFIG_PAX_MEMORY_UDEREF
23218+ testb $3, CS+8(%rsp)
23219+ jnz 1f
23220+ pax_enter_kernel
23221+ jmp 2f
23222+1: pax_enter_kernel_user
23223+2:
23224+#else
23225+ pax_enter_kernel
23226+#endif
23227 TRACE_IRQS_OFF
23228+ pax_force_retaddr
23229 ret
23230
23231 /*
23232@@ -1616,7 +2125,7 @@ bstep_iret:
23233 movq %rcx,RIP+8(%rsp)
23234 jmp error_swapgs
23235 CFI_ENDPROC
23236-END(error_entry)
23237+ENDPROC(error_entry)
23238
23239
23240 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23241@@ -1627,7 +2136,7 @@ ENTRY(error_exit)
23242 DISABLE_INTERRUPTS(CLBR_NONE)
23243 TRACE_IRQS_OFF
23244 GET_THREAD_INFO(%rcx)
23245- testl %eax,%eax
23246+ testl $1,%eax
23247 jne retint_kernel
23248 LOCKDEP_SYS_EXIT_IRQ
23249 movl TI_flags(%rcx),%edx
23250@@ -1636,7 +2145,7 @@ ENTRY(error_exit)
23251 jnz retint_careful
23252 jmp retint_swapgs
23253 CFI_ENDPROC
23254-END(error_exit)
23255+ENDPROC(error_exit)
23256
23257 /*
23258 * Test if a given stack is an NMI stack or not.
23259@@ -1694,9 +2203,11 @@ ENTRY(nmi)
23260 * If %cs was not the kernel segment, then the NMI triggered in user
23261 * space, which means it is definitely not nested.
23262 */
23263+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23264+ je 1f
23265 cmpl $__KERNEL_CS, 16(%rsp)
23266 jne first_nmi
23267-
23268+1:
23269 /*
23270 * Check the special variable on the stack to see if NMIs are
23271 * executing.
23272@@ -1730,8 +2241,7 @@ nested_nmi:
23273
23274 1:
23275 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23276- leaq -1*8(%rsp), %rdx
23277- movq %rdx, %rsp
23278+ subq $8, %rsp
23279 CFI_ADJUST_CFA_OFFSET 1*8
23280 leaq -10*8(%rsp), %rdx
23281 pushq_cfi $__KERNEL_DS
23282@@ -1749,6 +2259,7 @@ nested_nmi_out:
23283 CFI_RESTORE rdx
23284
23285 /* No need to check faults here */
23286+# pax_force_retaddr_bts
23287 INTERRUPT_RETURN
23288
23289 CFI_RESTORE_STATE
23290@@ -1845,13 +2356,13 @@ end_repeat_nmi:
23291 subq $ORIG_RAX-R15, %rsp
23292 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23293 /*
23294- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23295+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23296 * as we should not be calling schedule in NMI context.
23297 * Even with normal interrupts enabled. An NMI should not be
23298 * setting NEED_RESCHED or anything that normal interrupts and
23299 * exceptions might do.
23300 */
23301- call save_paranoid
23302+ call save_paranoid_nmi
23303 DEFAULT_FRAME 0
23304
23305 /*
23306@@ -1861,9 +2372,9 @@ end_repeat_nmi:
23307 * NMI itself takes a page fault, the page fault that was preempted
23308 * will read the information from the NMI page fault and not the
23309 * origin fault. Save it off and restore it if it changes.
23310- * Use the r12 callee-saved register.
23311+ * Use the r13 callee-saved register.
23312 */
23313- movq %cr2, %r12
23314+ movq %cr2, %r13
23315
23316 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23317 movq %rsp,%rdi
23318@@ -1872,31 +2383,36 @@ end_repeat_nmi:
23319
23320 /* Did the NMI take a page fault? Restore cr2 if it did */
23321 movq %cr2, %rcx
23322- cmpq %rcx, %r12
23323+ cmpq %rcx, %r13
23324 je 1f
23325- movq %r12, %cr2
23326+ movq %r13, %cr2
23327 1:
23328
23329- testl %ebx,%ebx /* swapgs needed? */
23330+ testl $1,%ebx /* swapgs needed? */
23331 jnz nmi_restore
23332 nmi_swapgs:
23333 SWAPGS_UNSAFE_STACK
23334 nmi_restore:
23335+ pax_exit_kernel_nmi
23336 /* Pop the extra iret frame at once */
23337 RESTORE_ALL 6*8
23338+ testb $3, 8(%rsp)
23339+ jnz 1f
23340+ pax_force_retaddr_bts
23341+1:
23342
23343 /* Clear the NMI executing stack variable */
23344 movq $0, 5*8(%rsp)
23345 jmp irq_return
23346 CFI_ENDPROC
23347-END(nmi)
23348+ENDPROC(nmi)
23349
23350 ENTRY(ignore_sysret)
23351 CFI_STARTPROC
23352 mov $-ENOSYS,%eax
23353 sysret
23354 CFI_ENDPROC
23355-END(ignore_sysret)
23356+ENDPROC(ignore_sysret)
23357
23358 /*
23359 * End of kprobes section
23360diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23361index d4bdd25..912664c 100644
23362--- a/arch/x86/kernel/ftrace.c
23363+++ b/arch/x86/kernel/ftrace.c
23364@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23365 {
23366 unsigned char replaced[MCOUNT_INSN_SIZE];
23367
23368+ ip = ktla_ktva(ip);
23369+
23370 /*
23371 * Note: Due to modules and __init, code can
23372 * disappear and change, we need to protect against faulting
23373@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23374 unsigned char old[MCOUNT_INSN_SIZE], *new;
23375 int ret;
23376
23377- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
23378+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
23379 new = ftrace_call_replace(ip, (unsigned long)func);
23380
23381 /* See comment above by declaration of modifying_ftrace_code */
23382@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23383 /* Also update the regs callback function */
23384 if (!ret) {
23385 ip = (unsigned long)(&ftrace_regs_call);
23386- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
23387+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
23388 new = ftrace_call_replace(ip, (unsigned long)func);
23389 ret = ftrace_modify_code(ip, old, new);
23390 }
23391@@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23392 * kernel identity mapping to modify code.
23393 */
23394 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23395- ip = (unsigned long)__va(__pa_symbol(ip));
23396+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23397
23398 return probe_kernel_write((void *)ip, val, size);
23399 }
23400@@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
23401 unsigned char replaced[MCOUNT_INSN_SIZE];
23402 unsigned char brk = BREAKPOINT_INSTRUCTION;
23403
23404- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23405+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23406 return -EFAULT;
23407
23408 /* Make sure it is what we expect it to be */
23409@@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23410 return ret;
23411
23412 fail_update:
23413- probe_kernel_write((void *)ip, &old_code[0], 1);
23414+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23415 goto out;
23416 }
23417
23418@@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
23419 {
23420 unsigned char code[MCOUNT_INSN_SIZE];
23421
23422+ ip = ktla_ktva(ip);
23423+
23424 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
23425 return -EFAULT;
23426
23427diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23428index 85126cc..1bbce17 100644
23429--- a/arch/x86/kernel/head64.c
23430+++ b/arch/x86/kernel/head64.c
23431@@ -67,12 +67,12 @@ again:
23432 pgd = *pgd_p;
23433
23434 /*
23435- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23436- * critical -- __PAGE_OFFSET would point us back into the dynamic
23437+ * The use of __early_va rather than __va here is critical:
23438+ * __va would point us back into the dynamic
23439 * range and we might end up looping forever...
23440 */
23441 if (pgd)
23442- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23443+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23444 else {
23445 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23446 reset_early_page_tables();
23447@@ -82,13 +82,13 @@ again:
23448 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23449 for (i = 0; i < PTRS_PER_PUD; i++)
23450 pud_p[i] = 0;
23451- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23452+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23453 }
23454 pud_p += pud_index(address);
23455 pud = *pud_p;
23456
23457 if (pud)
23458- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23459+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23460 else {
23461 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23462 reset_early_page_tables();
23463@@ -98,7 +98,7 @@ again:
23464 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23465 for (i = 0; i < PTRS_PER_PMD; i++)
23466 pmd_p[i] = 0;
23467- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23468+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23469 }
23470 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23471 pmd_p[pmd_index(address)] = pmd;
23472@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23473 if (console_loglevel == 10)
23474 early_printk("Kernel alive\n");
23475
23476- clear_page(init_level4_pgt);
23477 /* set init_level4_pgt kernel high mapping*/
23478 init_level4_pgt[511] = early_level4_pgt[511];
23479
23480diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23481index 81ba276..30c5411 100644
23482--- a/arch/x86/kernel/head_32.S
23483+++ b/arch/x86/kernel/head_32.S
23484@@ -26,6 +26,12 @@
23485 /* Physical address */
23486 #define pa(X) ((X) - __PAGE_OFFSET)
23487
23488+#ifdef CONFIG_PAX_KERNEXEC
23489+#define ta(X) (X)
23490+#else
23491+#define ta(X) ((X) - __PAGE_OFFSET)
23492+#endif
23493+
23494 /*
23495 * References to members of the new_cpu_data structure.
23496 */
23497@@ -55,11 +61,7 @@
23498 * and small than max_low_pfn, otherwise will waste some page table entries
23499 */
23500
23501-#if PTRS_PER_PMD > 1
23502-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
23503-#else
23504-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
23505-#endif
23506+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
23507
23508 /* Number of possible pages in the lowmem region */
23509 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
23510@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
23511 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23512
23513 /*
23514+ * Real beginning of normal "text" segment
23515+ */
23516+ENTRY(stext)
23517+ENTRY(_stext)
23518+
23519+/*
23520 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
23521 * %esi points to the real-mode code as a 32-bit pointer.
23522 * CS and DS must be 4 GB flat segments, but we don't depend on
23523@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23524 * can.
23525 */
23526 __HEAD
23527+
23528+#ifdef CONFIG_PAX_KERNEXEC
23529+ jmp startup_32
23530+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
23531+.fill PAGE_SIZE-5,1,0xcc
23532+#endif
23533+
23534 ENTRY(startup_32)
23535 movl pa(stack_start),%ecx
23536
23537@@ -106,6 +121,59 @@ ENTRY(startup_32)
23538 2:
23539 leal -__PAGE_OFFSET(%ecx),%esp
23540
23541+#ifdef CONFIG_SMP
23542+ movl $pa(cpu_gdt_table),%edi
23543+ movl $__per_cpu_load,%eax
23544+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
23545+ rorl $16,%eax
23546+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
23547+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
23548+ movl $__per_cpu_end - 1,%eax
23549+ subl $__per_cpu_start,%eax
23550+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
23551+#endif
23552+
23553+#ifdef CONFIG_PAX_MEMORY_UDEREF
23554+ movl $NR_CPUS,%ecx
23555+ movl $pa(cpu_gdt_table),%edi
23556+1:
23557+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
23558+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
23559+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
23560+ addl $PAGE_SIZE_asm,%edi
23561+ loop 1b
23562+#endif
23563+
23564+#ifdef CONFIG_PAX_KERNEXEC
23565+ movl $pa(boot_gdt),%edi
23566+ movl $__LOAD_PHYSICAL_ADDR,%eax
23567+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
23568+ rorl $16,%eax
23569+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
23570+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
23571+ rorl $16,%eax
23572+
23573+ ljmp $(__BOOT_CS),$1f
23574+1:
23575+
23576+ movl $NR_CPUS,%ecx
23577+ movl $pa(cpu_gdt_table),%edi
23578+ addl $__PAGE_OFFSET,%eax
23579+1:
23580+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
23581+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
23582+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23583+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23584+ rorl $16,%eax
23585+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23586+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23587+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23588+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23589+ rorl $16,%eax
23590+ addl $PAGE_SIZE_asm,%edi
23591+ loop 1b
23592+#endif
23593+
23594 /*
23595 * Clear BSS first so that there are no surprises...
23596 */
23597@@ -201,8 +269,11 @@ ENTRY(startup_32)
23598 movl %eax, pa(max_pfn_mapped)
23599
23600 /* Do early initialization of the fixmap area */
23601- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23602- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23603+#ifdef CONFIG_COMPAT_VDSO
23604+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23605+#else
23606+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23607+#endif
23608 #else /* Not PAE */
23609
23610 page_pde_offset = (__PAGE_OFFSET >> 20);
23611@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23612 movl %eax, pa(max_pfn_mapped)
23613
23614 /* Do early initialization of the fixmap area */
23615- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23616- movl %eax,pa(initial_page_table+0xffc)
23617+#ifdef CONFIG_COMPAT_VDSO
23618+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23619+#else
23620+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23621+#endif
23622 #endif
23623
23624 #ifdef CONFIG_PARAVIRT
23625@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23626 cmpl $num_subarch_entries, %eax
23627 jae bad_subarch
23628
23629- movl pa(subarch_entries)(,%eax,4), %eax
23630- subl $__PAGE_OFFSET, %eax
23631- jmp *%eax
23632+ jmp *pa(subarch_entries)(,%eax,4)
23633
23634 bad_subarch:
23635 WEAK(lguest_entry)
23636@@ -261,10 +333,10 @@ WEAK(xen_entry)
23637 __INITDATA
23638
23639 subarch_entries:
23640- .long default_entry /* normal x86/PC */
23641- .long lguest_entry /* lguest hypervisor */
23642- .long xen_entry /* Xen hypervisor */
23643- .long default_entry /* Moorestown MID */
23644+ .long ta(default_entry) /* normal x86/PC */
23645+ .long ta(lguest_entry) /* lguest hypervisor */
23646+ .long ta(xen_entry) /* Xen hypervisor */
23647+ .long ta(default_entry) /* Moorestown MID */
23648 num_subarch_entries = (. - subarch_entries) / 4
23649 .previous
23650 #else
23651@@ -354,6 +426,7 @@ default_entry:
23652 movl pa(mmu_cr4_features),%eax
23653 movl %eax,%cr4
23654
23655+#ifdef CONFIG_X86_PAE
23656 testb $X86_CR4_PAE, %al # check if PAE is enabled
23657 jz enable_paging
23658
23659@@ -382,6 +455,9 @@ default_entry:
23660 /* Make changes effective */
23661 wrmsr
23662
23663+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23664+#endif
23665+
23666 enable_paging:
23667
23668 /*
23669@@ -449,14 +525,20 @@ is486:
23670 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23671 movl %eax,%ss # after changing gdt.
23672
23673- movl $(__USER_DS),%eax # DS/ES contains default USER segment
23674+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23675 movl %eax,%ds
23676 movl %eax,%es
23677
23678 movl $(__KERNEL_PERCPU), %eax
23679 movl %eax,%fs # set this cpu's percpu
23680
23681+#ifdef CONFIG_CC_STACKPROTECTOR
23682 movl $(__KERNEL_STACK_CANARY),%eax
23683+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23684+ movl $(__USER_DS),%eax
23685+#else
23686+ xorl %eax,%eax
23687+#endif
23688 movl %eax,%gs
23689
23690 xorl %eax,%eax # Clear LDT
23691@@ -512,8 +594,11 @@ setup_once:
23692 * relocation. Manually set base address in stack canary
23693 * segment descriptor.
23694 */
23695- movl $gdt_page,%eax
23696+ movl $cpu_gdt_table,%eax
23697 movl $stack_canary,%ecx
23698+#ifdef CONFIG_SMP
23699+ addl $__per_cpu_load,%ecx
23700+#endif
23701 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23702 shrl $16, %ecx
23703 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23704@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
23705 /* This is global to keep gas from relaxing the jumps */
23706 ENTRY(early_idt_handler)
23707 cld
23708- cmpl $2,%ss:early_recursion_flag
23709+ cmpl $1,%ss:early_recursion_flag
23710 je hlt_loop
23711 incl %ss:early_recursion_flag
23712
23713@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
23714 pushl (20+6*4)(%esp) /* trapno */
23715 pushl $fault_msg
23716 call printk
23717-#endif
23718 call dump_stack
23719+#endif
23720 hlt_loop:
23721 hlt
23722 jmp hlt_loop
23723@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
23724 /* This is the default interrupt "handler" :-) */
23725 ALIGN
23726 ignore_int:
23727- cld
23728 #ifdef CONFIG_PRINTK
23729+ cmpl $2,%ss:early_recursion_flag
23730+ je hlt_loop
23731+ incl %ss:early_recursion_flag
23732+ cld
23733 pushl %eax
23734 pushl %ecx
23735 pushl %edx
23736@@ -612,9 +700,6 @@ ignore_int:
23737 movl $(__KERNEL_DS),%eax
23738 movl %eax,%ds
23739 movl %eax,%es
23740- cmpl $2,early_recursion_flag
23741- je hlt_loop
23742- incl early_recursion_flag
23743 pushl 16(%esp)
23744 pushl 24(%esp)
23745 pushl 32(%esp)
23746@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
23747 /*
23748 * BSS section
23749 */
23750-__PAGE_ALIGNED_BSS
23751- .align PAGE_SIZE
23752 #ifdef CONFIG_X86_PAE
23753+.section .initial_pg_pmd,"a",@progbits
23754 initial_pg_pmd:
23755 .fill 1024*KPMDS,4,0
23756 #else
23757+.section .initial_page_table,"a",@progbits
23758 ENTRY(initial_page_table)
23759 .fill 1024,4,0
23760 #endif
23761+.section .initial_pg_fixmap,"a",@progbits
23762 initial_pg_fixmap:
23763 .fill 1024,4,0
23764+.section .empty_zero_page,"a",@progbits
23765 ENTRY(empty_zero_page)
23766 .fill 4096,1,0
23767+.section .swapper_pg_dir,"a",@progbits
23768 ENTRY(swapper_pg_dir)
23769+#ifdef CONFIG_X86_PAE
23770+ .fill 4,8,0
23771+#else
23772 .fill 1024,4,0
23773+#endif
23774
23775 /*
23776 * This starts the data section.
23777 */
23778 #ifdef CONFIG_X86_PAE
23779-__PAGE_ALIGNED_DATA
23780- /* Page-aligned for the benefit of paravirt? */
23781- .align PAGE_SIZE
23782+.section .initial_page_table,"a",@progbits
23783 ENTRY(initial_page_table)
23784 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23785 # if KPMDS == 3
23786@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
23787 # error "Kernel PMDs should be 1, 2 or 3"
23788 # endif
23789 .align PAGE_SIZE /* needs to be page-sized too */
23790+
23791+#ifdef CONFIG_PAX_PER_CPU_PGD
23792+ENTRY(cpu_pgd)
23793+ .rept 2*NR_CPUS
23794+ .fill 4,8,0
23795+ .endr
23796+#endif
23797+
23798 #endif
23799
23800 .data
23801 .balign 4
23802 ENTRY(stack_start)
23803- .long init_thread_union+THREAD_SIZE
23804+ .long init_thread_union+THREAD_SIZE-8
23805
23806 __INITRODATA
23807 int_msg:
23808@@ -722,7 +820,7 @@ fault_msg:
23809 * segment size, and 32-bit linear address value:
23810 */
23811
23812- .data
23813+.section .rodata,"a",@progbits
23814 .globl boot_gdt_descr
23815 .globl idt_descr
23816
23817@@ -731,7 +829,7 @@ fault_msg:
23818 .word 0 # 32 bit align gdt_desc.address
23819 boot_gdt_descr:
23820 .word __BOOT_DS+7
23821- .long boot_gdt - __PAGE_OFFSET
23822+ .long pa(boot_gdt)
23823
23824 .word 0 # 32-bit align idt_desc.address
23825 idt_descr:
23826@@ -742,7 +840,7 @@ idt_descr:
23827 .word 0 # 32 bit align gdt_desc.address
23828 ENTRY(early_gdt_descr)
23829 .word GDT_ENTRIES*8-1
23830- .long gdt_page /* Overwritten for secondary CPUs */
23831+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
23832
23833 /*
23834 * The boot_gdt must mirror the equivalent in setup.S and is
23835@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23836 .align L1_CACHE_BYTES
23837 ENTRY(boot_gdt)
23838 .fill GDT_ENTRY_BOOT_CS,8,0
23839- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23840- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23841+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23842+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23843+
23844+ .align PAGE_SIZE_asm
23845+ENTRY(cpu_gdt_table)
23846+ .rept NR_CPUS
23847+ .quad 0x0000000000000000 /* NULL descriptor */
23848+ .quad 0x0000000000000000 /* 0x0b reserved */
23849+ .quad 0x0000000000000000 /* 0x13 reserved */
23850+ .quad 0x0000000000000000 /* 0x1b reserved */
23851+
23852+#ifdef CONFIG_PAX_KERNEXEC
23853+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23854+#else
23855+ .quad 0x0000000000000000 /* 0x20 unused */
23856+#endif
23857+
23858+ .quad 0x0000000000000000 /* 0x28 unused */
23859+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23860+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23861+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23862+ .quad 0x0000000000000000 /* 0x4b reserved */
23863+ .quad 0x0000000000000000 /* 0x53 reserved */
23864+ .quad 0x0000000000000000 /* 0x5b reserved */
23865+
23866+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23867+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23868+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23869+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23870+
23871+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23872+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23873+
23874+ /*
23875+ * Segments used for calling PnP BIOS have byte granularity.
23876+ * The code segments and data segments have fixed 64k limits,
23877+ * the transfer segment sizes are set at run time.
23878+ */
23879+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23880+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23881+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23882+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23883+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23884+
23885+ /*
23886+ * The APM segments have byte granularity and their bases
23887+ * are set at run time. All have 64k limits.
23888+ */
23889+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23890+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23891+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23892+
23893+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23894+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23895+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23896+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23897+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23898+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23899+
23900+ /* Be sure this is zeroed to avoid false validations in Xen */
23901+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23902+ .endr
23903diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23904index e1aabdb..fee4fee 100644
23905--- a/arch/x86/kernel/head_64.S
23906+++ b/arch/x86/kernel/head_64.S
23907@@ -20,6 +20,8 @@
23908 #include <asm/processor-flags.h>
23909 #include <asm/percpu.h>
23910 #include <asm/nops.h>
23911+#include <asm/cpufeature.h>
23912+#include <asm/alternative-asm.h>
23913
23914 #ifdef CONFIG_PARAVIRT
23915 #include <asm/asm-offsets.h>
23916@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23917 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23918 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23919 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23920+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23921+L3_VMALLOC_START = pud_index(VMALLOC_START)
23922+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23923+L3_VMALLOC_END = pud_index(VMALLOC_END)
23924+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23925+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23926
23927 .text
23928 __HEAD
23929@@ -89,11 +97,24 @@ startup_64:
23930 * Fixup the physical addresses in the page table
23931 */
23932 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23933+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23934+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23935+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23936+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23937+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23938
23939- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23940- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23941+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23942+#ifndef CONFIG_XEN
23943+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23944+#endif
23945+
23946+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23947+
23948+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23949+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23950
23951 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23952+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23953
23954 /*
23955 * Set up the identity mapping for the switchover. These
23956@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
23957 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23958 1:
23959
23960- /* Enable PAE mode and PGE */
23961- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23962+ /* Enable PAE mode and PSE/PGE */
23963+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23964 movq %rcx, %cr4
23965
23966 /* Setup early boot stage 4 level pagetables. */
23967@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
23968 movl $MSR_EFER, %ecx
23969 rdmsr
23970 btsl $_EFER_SCE, %eax /* Enable System Call */
23971- btl $20,%edi /* No Execute supported? */
23972+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23973 jnc 1f
23974 btsl $_EFER_NX, %eax
23975 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23976+#ifndef CONFIG_EFI
23977+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
23978+#endif
23979+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
23980+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
23981+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
23982+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
23983+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
23984+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23985 1: wrmsr /* Make changes effective */
23986
23987 /* Setup cr0 */
23988@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
23989 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23990 * address given in m16:64.
23991 */
23992+ pax_set_fptr_mask
23993 movq initial_code(%rip),%rax
23994 pushq $0 # fake return address to stop unwinder
23995 pushq $__KERNEL_CS # set correct cs
23996@@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
23997 call dump_stack
23998 #ifdef CONFIG_KALLSYMS
23999 leaq early_idt_ripmsg(%rip),%rdi
24000- movq 40(%rsp),%rsi # %rip again
24001+ movq 88(%rsp),%rsi # %rip again
24002 call __print_symbol
24003 #endif
24004 #endif /* EARLY_PRINTK */
24005@@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
24006 early_recursion_flag:
24007 .long 0
24008
24009+ .section .rodata,"a",@progbits
24010 #ifdef CONFIG_EARLY_PRINTK
24011 early_idt_msg:
24012 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24013@@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
24014 NEXT_PAGE(early_dynamic_pgts)
24015 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24016
24017- .data
24018+ .section .rodata,"a",@progbits
24019
24020-#ifndef CONFIG_XEN
24021 NEXT_PAGE(init_level4_pgt)
24022- .fill 512,8,0
24023-#else
24024-NEXT_PAGE(init_level4_pgt)
24025- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24026 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24027 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24028+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24029+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24030+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24031+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24032+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24033+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24034 .org init_level4_pgt + L4_START_KERNEL*8, 0
24035 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24036 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24037
24038+#ifdef CONFIG_PAX_PER_CPU_PGD
24039+NEXT_PAGE(cpu_pgd)
24040+ .rept 2*NR_CPUS
24041+ .fill 512,8,0
24042+ .endr
24043+#endif
24044+
24045 NEXT_PAGE(level3_ident_pgt)
24046 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24047+#ifdef CONFIG_XEN
24048 .fill 511, 8, 0
24049+#else
24050+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24051+ .fill 510,8,0
24052+#endif
24053+
24054+NEXT_PAGE(level3_vmalloc_start_pgt)
24055+ .fill 512,8,0
24056+
24057+NEXT_PAGE(level3_vmalloc_end_pgt)
24058+ .fill 512,8,0
24059+
24060+NEXT_PAGE(level3_vmemmap_pgt)
24061+ .fill L3_VMEMMAP_START,8,0
24062+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24063+
24064 NEXT_PAGE(level2_ident_pgt)
24065- /* Since I easily can, map the first 1G.
24066+ /* Since I easily can, map the first 2G.
24067 * Don't set NX because code runs from these pages.
24068 */
24069- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24070-#endif
24071+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24072
24073 NEXT_PAGE(level3_kernel_pgt)
24074 .fill L3_START_KERNEL,8,0
24075@@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
24076 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24077 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24078
24079+NEXT_PAGE(level2_vmemmap_pgt)
24080+ .fill 512,8,0
24081+
24082 NEXT_PAGE(level2_kernel_pgt)
24083 /*
24084 * 512 MB kernel mapping. We spend a full page on this pagetable
24085@@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
24086 NEXT_PAGE(level2_fixmap_pgt)
24087 .fill 506,8,0
24088 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24089- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24090- .fill 5,8,0
24091+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24092+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24093+ .fill 4,8,0
24094
24095 NEXT_PAGE(level1_fixmap_pgt)
24096 .fill 512,8,0
24097
24098+NEXT_PAGE(level1_vsyscall_pgt)
24099+ .fill 512,8,0
24100+
24101 #undef PMDS
24102
24103- .data
24104+ .align PAGE_SIZE
24105+ENTRY(cpu_gdt_table)
24106+ .rept NR_CPUS
24107+ .quad 0x0000000000000000 /* NULL descriptor */
24108+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24109+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24110+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24111+ .quad 0x00cffb000000ffff /* __USER32_CS */
24112+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24113+ .quad 0x00affb000000ffff /* __USER_CS */
24114+
24115+#ifdef CONFIG_PAX_KERNEXEC
24116+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24117+#else
24118+ .quad 0x0 /* unused */
24119+#endif
24120+
24121+ .quad 0,0 /* TSS */
24122+ .quad 0,0 /* LDT */
24123+ .quad 0,0,0 /* three TLS descriptors */
24124+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24125+ /* asm/segment.h:GDT_ENTRIES must match this */
24126+
24127+#ifdef CONFIG_PAX_MEMORY_UDEREF
24128+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24129+#else
24130+ .quad 0x0 /* unused */
24131+#endif
24132+
24133+ /* zero the remaining page */
24134+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24135+ .endr
24136+
24137 .align 16
24138 .globl early_gdt_descr
24139 early_gdt_descr:
24140 .word GDT_ENTRIES*8-1
24141 early_gdt_descr_base:
24142- .quad INIT_PER_CPU_VAR(gdt_page)
24143+ .quad cpu_gdt_table
24144
24145 ENTRY(phys_base)
24146 /* This must match the first entry in level2_kernel_pgt */
24147 .quad 0x0000000000000000
24148
24149 #include "../../x86/xen/xen-head.S"
24150-
24151- __PAGE_ALIGNED_BSS
24152+
24153+ .section .rodata,"a",@progbits
24154 NEXT_PAGE(empty_zero_page)
24155 .skip PAGE_SIZE
24156diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24157index 05fd74f..c3548b1 100644
24158--- a/arch/x86/kernel/i386_ksyms_32.c
24159+++ b/arch/x86/kernel/i386_ksyms_32.c
24160@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24161 EXPORT_SYMBOL(cmpxchg8b_emu);
24162 #endif
24163
24164+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24165+
24166 /* Networking helper routines. */
24167 EXPORT_SYMBOL(csum_partial_copy_generic);
24168+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24169+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24170
24171 EXPORT_SYMBOL(__get_user_1);
24172 EXPORT_SYMBOL(__get_user_2);
24173@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24174 EXPORT_SYMBOL(___preempt_schedule_context);
24175 #endif
24176 #endif
24177+
24178+#ifdef CONFIG_PAX_KERNEXEC
24179+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24180+#endif
24181+
24182+#ifdef CONFIG_PAX_PER_CPU_PGD
24183+EXPORT_SYMBOL(cpu_pgd);
24184+#endif
24185diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24186index e8368c6..9c1a712 100644
24187--- a/arch/x86/kernel/i387.c
24188+++ b/arch/x86/kernel/i387.c
24189@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24190 static inline bool interrupted_user_mode(void)
24191 {
24192 struct pt_regs *regs = get_irq_regs();
24193- return regs && user_mode_vm(regs);
24194+ return regs && user_mode(regs);
24195 }
24196
24197 /*
24198diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24199index 2e977b5..5f2c273 100644
24200--- a/arch/x86/kernel/i8259.c
24201+++ b/arch/x86/kernel/i8259.c
24202@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24203 static void make_8259A_irq(unsigned int irq)
24204 {
24205 disable_irq_nosync(irq);
24206- io_apic_irqs &= ~(1<<irq);
24207+ io_apic_irqs &= ~(1UL<<irq);
24208 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24209 i8259A_chip.name);
24210 enable_irq(irq);
24211@@ -209,7 +209,7 @@ spurious_8259A_irq:
24212 "spurious 8259A interrupt: IRQ%d.\n", irq);
24213 spurious_irq_mask |= irqmask;
24214 }
24215- atomic_inc(&irq_err_count);
24216+ atomic_inc_unchecked(&irq_err_count);
24217 /*
24218 * Theoretically we do not have to handle this IRQ,
24219 * but in Linux this does not cause problems and is
24220@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24221 /* (slave's support for AEOI in flat mode is to be investigated) */
24222 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24223
24224+ pax_open_kernel();
24225 if (auto_eoi)
24226 /*
24227 * In AEOI mode we just have to mask the interrupt
24228 * when acking.
24229 */
24230- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24231+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24232 else
24233- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24234+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24235+ pax_close_kernel();
24236
24237 udelay(100); /* wait for 8259A to initialize */
24238
24239diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24240index a979b5b..1d6db75 100644
24241--- a/arch/x86/kernel/io_delay.c
24242+++ b/arch/x86/kernel/io_delay.c
24243@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24244 * Quirk table for systems that misbehave (lock up, etc.) if port
24245 * 0x80 is used:
24246 */
24247-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24248+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24249 {
24250 .callback = dmi_io_delay_0xed_port,
24251 .ident = "Compaq Presario V6000",
24252diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24253index 4ddaf66..49d5c18 100644
24254--- a/arch/x86/kernel/ioport.c
24255+++ b/arch/x86/kernel/ioport.c
24256@@ -6,6 +6,7 @@
24257 #include <linux/sched.h>
24258 #include <linux/kernel.h>
24259 #include <linux/capability.h>
24260+#include <linux/security.h>
24261 #include <linux/errno.h>
24262 #include <linux/types.h>
24263 #include <linux/ioport.h>
24264@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24265 return -EINVAL;
24266 if (turn_on && !capable(CAP_SYS_RAWIO))
24267 return -EPERM;
24268+#ifdef CONFIG_GRKERNSEC_IO
24269+ if (turn_on && grsec_disable_privio) {
24270+ gr_handle_ioperm();
24271+ return -ENODEV;
24272+ }
24273+#endif
24274
24275 /*
24276 * If it's the first ioperm() call in this thread's lifetime, set the
24277@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24278 * because the ->io_bitmap_max value must match the bitmap
24279 * contents:
24280 */
24281- tss = &per_cpu(init_tss, get_cpu());
24282+ tss = init_tss + get_cpu();
24283
24284 if (turn_on)
24285 bitmap_clear(t->io_bitmap_ptr, from, num);
24286@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24287 if (level > old) {
24288 if (!capable(CAP_SYS_RAWIO))
24289 return -EPERM;
24290+#ifdef CONFIG_GRKERNSEC_IO
24291+ if (grsec_disable_privio) {
24292+ gr_handle_iopl();
24293+ return -ENODEV;
24294+ }
24295+#endif
24296 }
24297 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24298 t->iopl = level << 12;
24299diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24300index 22d0687..e07b2a5 100644
24301--- a/arch/x86/kernel/irq.c
24302+++ b/arch/x86/kernel/irq.c
24303@@ -21,7 +21,7 @@
24304 #define CREATE_TRACE_POINTS
24305 #include <asm/trace/irq_vectors.h>
24306
24307-atomic_t irq_err_count;
24308+atomic_unchecked_t irq_err_count;
24309
24310 /* Function pointer for generic interrupt vector handling */
24311 void (*x86_platform_ipi_callback)(void) = NULL;
24312@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24313 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24314 seq_printf(p, " Machine check polls\n");
24315 #endif
24316- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24317+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24318 #if defined(CONFIG_X86_IO_APIC)
24319- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24320+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24321 #endif
24322 return 0;
24323 }
24324@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24325
24326 u64 arch_irq_stat(void)
24327 {
24328- u64 sum = atomic_read(&irq_err_count);
24329+ u64 sum = atomic_read_unchecked(&irq_err_count);
24330 return sum;
24331 }
24332
24333diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24334index d7fcbed..1f747f7 100644
24335--- a/arch/x86/kernel/irq_32.c
24336+++ b/arch/x86/kernel/irq_32.c
24337@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24338 __asm__ __volatile__("andl %%esp,%0" :
24339 "=r" (sp) : "0" (THREAD_SIZE - 1));
24340
24341- return sp < (sizeof(struct thread_info) + STACK_WARN);
24342+ return sp < STACK_WARN;
24343 }
24344
24345 static void print_stack_overflow(void)
24346@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24347 * per-CPU IRQ handling contexts (thread information and stack)
24348 */
24349 union irq_ctx {
24350- struct thread_info tinfo;
24351- u32 stack[THREAD_SIZE/sizeof(u32)];
24352+ unsigned long previous_esp;
24353+ u32 stack[THREAD_SIZE/sizeof(u32)];
24354 } __attribute__((aligned(THREAD_SIZE)));
24355
24356 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24357@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24358 static inline int
24359 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24360 {
24361- union irq_ctx *curctx, *irqctx;
24362+ union irq_ctx *irqctx;
24363 u32 *isp, arg1, arg2;
24364
24365- curctx = (union irq_ctx *) current_thread_info();
24366 irqctx = __this_cpu_read(hardirq_ctx);
24367
24368 /*
24369@@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24370 * handler) we can't do that and just have to keep using the
24371 * current stack (which is the irq stack already after all)
24372 */
24373- if (unlikely(curctx == irqctx))
24374+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24375 return 0;
24376
24377 /* build the stack frame on the IRQ stack */
24378- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24379- irqctx->tinfo.task = curctx->tinfo.task;
24380- irqctx->tinfo.previous_esp = current_stack_pointer;
24381+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24382+ irqctx->previous_esp = current_stack_pointer;
24383+
24384+#ifdef CONFIG_PAX_MEMORY_UDEREF
24385+ __set_fs(MAKE_MM_SEG(0));
24386+#endif
24387
24388 if (unlikely(overflow))
24389 call_on_stack(print_stack_overflow, isp);
24390@@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24391 : "0" (irq), "1" (desc), "2" (isp),
24392 "D" (desc->handle_irq)
24393 : "memory", "cc", "ecx");
24394+
24395+#ifdef CONFIG_PAX_MEMORY_UDEREF
24396+ __set_fs(current_thread_info()->addr_limit);
24397+#endif
24398+
24399 return 1;
24400 }
24401
24402@@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24403 */
24404 void irq_ctx_init(int cpu)
24405 {
24406- union irq_ctx *irqctx;
24407-
24408 if (per_cpu(hardirq_ctx, cpu))
24409 return;
24410
24411- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24412- THREADINFO_GFP,
24413- THREAD_SIZE_ORDER));
24414- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24415- irqctx->tinfo.cpu = cpu;
24416- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24417-
24418- per_cpu(hardirq_ctx, cpu) = irqctx;
24419-
24420- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24421- THREADINFO_GFP,
24422- THREAD_SIZE_ORDER));
24423- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24424- irqctx->tinfo.cpu = cpu;
24425- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24426-
24427- per_cpu(softirq_ctx, cpu) = irqctx;
24428-
24429- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24430- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24431+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24432+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24433 }
24434
24435 void do_softirq_own_stack(void)
24436 {
24437- struct thread_info *curctx;
24438 union irq_ctx *irqctx;
24439 u32 *isp;
24440
24441- curctx = current_thread_info();
24442 irqctx = __this_cpu_read(softirq_ctx);
24443- irqctx->tinfo.task = curctx->task;
24444- irqctx->tinfo.previous_esp = current_stack_pointer;
24445+ irqctx->previous_esp = current_stack_pointer;
24446
24447 /* build the stack frame on the softirq stack */
24448- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24449+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24450+
24451+#ifdef CONFIG_PAX_MEMORY_UDEREF
24452+ __set_fs(MAKE_MM_SEG(0));
24453+#endif
24454
24455 call_on_stack(__do_softirq, isp);
24456+
24457+#ifdef CONFIG_PAX_MEMORY_UDEREF
24458+ __set_fs(current_thread_info()->addr_limit);
24459+#endif
24460+
24461 }
24462
24463 bool handle_irq(unsigned irq, struct pt_regs *regs)
24464@@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24465 if (unlikely(!desc))
24466 return false;
24467
24468- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24469+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24470 if (unlikely(overflow))
24471 print_stack_overflow();
24472 desc->handle_irq(irq, desc);
24473diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24474index 4d1c746..232961d 100644
24475--- a/arch/x86/kernel/irq_64.c
24476+++ b/arch/x86/kernel/irq_64.c
24477@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24478 u64 estack_top, estack_bottom;
24479 u64 curbase = (u64)task_stack_page(current);
24480
24481- if (user_mode_vm(regs))
24482+ if (user_mode(regs))
24483 return;
24484
24485 if (regs->sp >= curbase + sizeof(struct thread_info) +
24486diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24487index 26d5a55..a01160a 100644
24488--- a/arch/x86/kernel/jump_label.c
24489+++ b/arch/x86/kernel/jump_label.c
24490@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24491 * Jump label is enabled for the first time.
24492 * So we expect a default_nop...
24493 */
24494- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
24495+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
24496 != 0))
24497 bug_at((void *)entry->code, __LINE__);
24498 } else {
24499@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24500 * ...otherwise expect an ideal_nop. Otherwise
24501 * something went horribly wrong.
24502 */
24503- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
24504+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
24505 != 0))
24506 bug_at((void *)entry->code, __LINE__);
24507 }
24508@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
24509 * are converting the default nop to the ideal nop.
24510 */
24511 if (init) {
24512- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
24513+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
24514 bug_at((void *)entry->code, __LINE__);
24515 } else {
24516 code.jump = 0xe9;
24517 code.offset = entry->target -
24518 (entry->code + JUMP_LABEL_NOP_SIZE);
24519- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
24520+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
24521 bug_at((void *)entry->code, __LINE__);
24522 }
24523 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
24524diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
24525index 836f832..a8bda67 100644
24526--- a/arch/x86/kernel/kgdb.c
24527+++ b/arch/x86/kernel/kgdb.c
24528@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
24529 #ifdef CONFIG_X86_32
24530 switch (regno) {
24531 case GDB_SS:
24532- if (!user_mode_vm(regs))
24533+ if (!user_mode(regs))
24534 *(unsigned long *)mem = __KERNEL_DS;
24535 break;
24536 case GDB_SP:
24537- if (!user_mode_vm(regs))
24538+ if (!user_mode(regs))
24539 *(unsigned long *)mem = kernel_stack_pointer(regs);
24540 break;
24541 case GDB_GS:
24542@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
24543 bp->attr.bp_addr = breakinfo[breakno].addr;
24544 bp->attr.bp_len = breakinfo[breakno].len;
24545 bp->attr.bp_type = breakinfo[breakno].type;
24546- info->address = breakinfo[breakno].addr;
24547+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
24548+ info->address = ktla_ktva(breakinfo[breakno].addr);
24549+ else
24550+ info->address = breakinfo[breakno].addr;
24551 info->len = breakinfo[breakno].len;
24552 info->type = breakinfo[breakno].type;
24553 val = arch_install_hw_breakpoint(bp);
24554@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
24555 case 'k':
24556 /* clear the trace bit */
24557 linux_regs->flags &= ~X86_EFLAGS_TF;
24558- atomic_set(&kgdb_cpu_doing_single_step, -1);
24559+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
24560
24561 /* set the trace bit if we're stepping */
24562 if (remcomInBuffer[0] == 's') {
24563 linux_regs->flags |= X86_EFLAGS_TF;
24564- atomic_set(&kgdb_cpu_doing_single_step,
24565+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
24566 raw_smp_processor_id());
24567 }
24568
24569@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
24570
24571 switch (cmd) {
24572 case DIE_DEBUG:
24573- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
24574+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24575 if (user_mode(regs))
24576 return single_step_cont(regs, args);
24577 break;
24578@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24579 #endif /* CONFIG_DEBUG_RODATA */
24580
24581 bpt->type = BP_BREAKPOINT;
24582- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24583+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24584 BREAK_INSTR_SIZE);
24585 if (err)
24586 return err;
24587- err = probe_kernel_write((char *)bpt->bpt_addr,
24588+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24589 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24590 #ifdef CONFIG_DEBUG_RODATA
24591 if (!err)
24592@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24593 return -EBUSY;
24594 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24595 BREAK_INSTR_SIZE);
24596- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24597+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24598 if (err)
24599 return err;
24600 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24601@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24602 if (mutex_is_locked(&text_mutex))
24603 goto knl_write;
24604 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24605- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24606+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24607 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24608 goto knl_write;
24609 return err;
24610 knl_write:
24611 #endif /* CONFIG_DEBUG_RODATA */
24612- return probe_kernel_write((char *)bpt->bpt_addr,
24613+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24614 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24615 }
24616
24617diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24618index 79a3f96..6ba030a 100644
24619--- a/arch/x86/kernel/kprobes/core.c
24620+++ b/arch/x86/kernel/kprobes/core.c
24621@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24622 s32 raddr;
24623 } __packed *insn;
24624
24625- insn = (struct __arch_relative_insn *)from;
24626+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
24627+
24628+ pax_open_kernel();
24629 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24630 insn->op = op;
24631+ pax_close_kernel();
24632 }
24633
24634 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24635@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24636 kprobe_opcode_t opcode;
24637 kprobe_opcode_t *orig_opcodes = opcodes;
24638
24639- if (search_exception_tables((unsigned long)opcodes))
24640+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24641 return 0; /* Page fault may occur on this address. */
24642
24643 retry:
24644@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24645 * for the first byte, we can recover the original instruction
24646 * from it and kp->opcode.
24647 */
24648- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24649+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24650 buf[0] = kp->opcode;
24651- return (unsigned long)buf;
24652+ return ktva_ktla((unsigned long)buf);
24653 }
24654
24655 /*
24656@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24657 /* Another subsystem puts a breakpoint, failed to recover */
24658 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24659 return 0;
24660+ pax_open_kernel();
24661 memcpy(dest, insn.kaddr, insn.length);
24662+ pax_close_kernel();
24663
24664 #ifdef CONFIG_X86_64
24665 if (insn_rip_relative(&insn)) {
24666@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24667 return 0;
24668 }
24669 disp = (u8 *) dest + insn_offset_displacement(&insn);
24670+ pax_open_kernel();
24671 *(s32 *) disp = (s32) newdisp;
24672+ pax_close_kernel();
24673 }
24674 #endif
24675 return insn.length;
24676@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24677 * nor set current_kprobe, because it doesn't use single
24678 * stepping.
24679 */
24680- regs->ip = (unsigned long)p->ainsn.insn;
24681+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24682 preempt_enable_no_resched();
24683 return;
24684 }
24685@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24686 regs->flags &= ~X86_EFLAGS_IF;
24687 /* single step inline if the instruction is an int3 */
24688 if (p->opcode == BREAKPOINT_INSTRUCTION)
24689- regs->ip = (unsigned long)p->addr;
24690+ regs->ip = ktla_ktva((unsigned long)p->addr);
24691 else
24692- regs->ip = (unsigned long)p->ainsn.insn;
24693+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24694 }
24695
24696 /*
24697@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24698 setup_singlestep(p, regs, kcb, 0);
24699 return 1;
24700 }
24701- } else if (*addr != BREAKPOINT_INSTRUCTION) {
24702+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24703 /*
24704 * The breakpoint instruction was removed right
24705 * after we hit it. Another cpu has removed
24706@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24707 " movq %rax, 152(%rsp)\n"
24708 RESTORE_REGS_STRING
24709 " popfq\n"
24710+#ifdef KERNEXEC_PLUGIN
24711+ " btsq $63,(%rsp)\n"
24712+#endif
24713 #else
24714 " pushf\n"
24715 SAVE_REGS_STRING
24716@@ -779,7 +789,7 @@ static void __kprobes
24717 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24718 {
24719 unsigned long *tos = stack_addr(regs);
24720- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24721+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24722 unsigned long orig_ip = (unsigned long)p->addr;
24723 kprobe_opcode_t *insn = p->ainsn.insn;
24724
24725@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24726 struct die_args *args = data;
24727 int ret = NOTIFY_DONE;
24728
24729- if (args->regs && user_mode_vm(args->regs))
24730+ if (args->regs && user_mode(args->regs))
24731 return ret;
24732
24733 switch (val) {
24734diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24735index 898160b..758cde8 100644
24736--- a/arch/x86/kernel/kprobes/opt.c
24737+++ b/arch/x86/kernel/kprobes/opt.c
24738@@ -79,6 +79,7 @@ found:
24739 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24740 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24741 {
24742+ pax_open_kernel();
24743 #ifdef CONFIG_X86_64
24744 *addr++ = 0x48;
24745 *addr++ = 0xbf;
24746@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24747 *addr++ = 0xb8;
24748 #endif
24749 *(unsigned long *)addr = val;
24750+ pax_close_kernel();
24751 }
24752
24753 asm (
24754@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24755 * Verify if the address gap is in 2GB range, because this uses
24756 * a relative jump.
24757 */
24758- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24759+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24760 if (abs(rel) > 0x7fffffff)
24761 return -ERANGE;
24762
24763@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24764 op->optinsn.size = ret;
24765
24766 /* Copy arch-dep-instance from template */
24767- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24768+ pax_open_kernel();
24769+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24770+ pax_close_kernel();
24771
24772 /* Set probe information */
24773 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24774
24775 /* Set probe function call */
24776- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24777+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24778
24779 /* Set returning jmp instruction at the tail of out-of-line buffer */
24780- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24781+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24782 (u8 *)op->kp.addr + op->optinsn.size);
24783
24784 flush_icache_range((unsigned long) buf,
24785@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
24786 WARN_ON(kprobe_disabled(&op->kp));
24787
24788 /* Backup instructions which will be replaced by jump address */
24789- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24790+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24791 RELATIVE_ADDR_SIZE);
24792
24793 insn_buf[0] = RELATIVEJUMP_OPCODE;
24794@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24795 /* This kprobe is really able to run optimized path. */
24796 op = container_of(p, struct optimized_kprobe, kp);
24797 /* Detour through copied instructions */
24798- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24799+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24800 if (!reenter)
24801 reset_current_kprobe();
24802 preempt_enable_no_resched();
24803diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24804index ebc9873..1b9724b 100644
24805--- a/arch/x86/kernel/ldt.c
24806+++ b/arch/x86/kernel/ldt.c
24807@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24808 if (reload) {
24809 #ifdef CONFIG_SMP
24810 preempt_disable();
24811- load_LDT(pc);
24812+ load_LDT_nolock(pc);
24813 if (!cpumask_equal(mm_cpumask(current->mm),
24814 cpumask_of(smp_processor_id())))
24815 smp_call_function(flush_ldt, current->mm, 1);
24816 preempt_enable();
24817 #else
24818- load_LDT(pc);
24819+ load_LDT_nolock(pc);
24820 #endif
24821 }
24822 if (oldsize) {
24823@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24824 return err;
24825
24826 for (i = 0; i < old->size; i++)
24827- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24828+ write_ldt_entry(new->ldt, i, old->ldt + i);
24829 return 0;
24830 }
24831
24832@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24833 retval = copy_ldt(&mm->context, &old_mm->context);
24834 mutex_unlock(&old_mm->context.lock);
24835 }
24836+
24837+ if (tsk == current) {
24838+ mm->context.vdso = 0;
24839+
24840+#ifdef CONFIG_X86_32
24841+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24842+ mm->context.user_cs_base = 0UL;
24843+ mm->context.user_cs_limit = ~0UL;
24844+
24845+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24846+ cpus_clear(mm->context.cpu_user_cs_mask);
24847+#endif
24848+
24849+#endif
24850+#endif
24851+
24852+ }
24853+
24854 return retval;
24855 }
24856
24857@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24858 }
24859 }
24860
24861+#ifdef CONFIG_PAX_SEGMEXEC
24862+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24863+ error = -EINVAL;
24864+ goto out_unlock;
24865+ }
24866+#endif
24867+
24868 fill_ldt(&ldt, &ldt_info);
24869 if (oldmode)
24870 ldt.avl = 0;
24871diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24872index 5b19e4d..6476a76 100644
24873--- a/arch/x86/kernel/machine_kexec_32.c
24874+++ b/arch/x86/kernel/machine_kexec_32.c
24875@@ -26,7 +26,7 @@
24876 #include <asm/cacheflush.h>
24877 #include <asm/debugreg.h>
24878
24879-static void set_idt(void *newidt, __u16 limit)
24880+static void set_idt(struct desc_struct *newidt, __u16 limit)
24881 {
24882 struct desc_ptr curidt;
24883
24884@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24885 }
24886
24887
24888-static void set_gdt(void *newgdt, __u16 limit)
24889+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24890 {
24891 struct desc_ptr curgdt;
24892
24893@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24894 }
24895
24896 control_page = page_address(image->control_code_page);
24897- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24898+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24899
24900 relocate_kernel_ptr = control_page;
24901 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24902diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24903index 15c9876..0a43909 100644
24904--- a/arch/x86/kernel/microcode_core.c
24905+++ b/arch/x86/kernel/microcode_core.c
24906@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24907 return NOTIFY_OK;
24908 }
24909
24910-static struct notifier_block __refdata mc_cpu_notifier = {
24911+static struct notifier_block mc_cpu_notifier = {
24912 .notifier_call = mc_cpu_callback,
24913 };
24914
24915diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24916index 5fb2ceb..3ae90bb 100644
24917--- a/arch/x86/kernel/microcode_intel.c
24918+++ b/arch/x86/kernel/microcode_intel.c
24919@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24920
24921 static int get_ucode_user(void *to, const void *from, size_t n)
24922 {
24923- return copy_from_user(to, from, n);
24924+ return copy_from_user(to, (const void __force_user *)from, n);
24925 }
24926
24927 static enum ucode_state
24928 request_microcode_user(int cpu, const void __user *buf, size_t size)
24929 {
24930- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24931+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24932 }
24933
24934 static void microcode_fini_cpu(int cpu)
24935diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24936index 18be189..4a9fe40 100644
24937--- a/arch/x86/kernel/module.c
24938+++ b/arch/x86/kernel/module.c
24939@@ -43,15 +43,60 @@ do { \
24940 } while (0)
24941 #endif
24942
24943-void *module_alloc(unsigned long size)
24944+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24945 {
24946- if (PAGE_ALIGN(size) > MODULES_LEN)
24947+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24948 return NULL;
24949 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24950- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24951+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24952 NUMA_NO_NODE, __builtin_return_address(0));
24953 }
24954
24955+void *module_alloc(unsigned long size)
24956+{
24957+
24958+#ifdef CONFIG_PAX_KERNEXEC
24959+ return __module_alloc(size, PAGE_KERNEL);
24960+#else
24961+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24962+#endif
24963+
24964+}
24965+
24966+#ifdef CONFIG_PAX_KERNEXEC
24967+#ifdef CONFIG_X86_32
24968+void *module_alloc_exec(unsigned long size)
24969+{
24970+ struct vm_struct *area;
24971+
24972+ if (size == 0)
24973+ return NULL;
24974+
24975+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24976+ return area ? area->addr : NULL;
24977+}
24978+EXPORT_SYMBOL(module_alloc_exec);
24979+
24980+void module_free_exec(struct module *mod, void *module_region)
24981+{
24982+ vunmap(module_region);
24983+}
24984+EXPORT_SYMBOL(module_free_exec);
24985+#else
24986+void module_free_exec(struct module *mod, void *module_region)
24987+{
24988+ module_free(mod, module_region);
24989+}
24990+EXPORT_SYMBOL(module_free_exec);
24991+
24992+void *module_alloc_exec(unsigned long size)
24993+{
24994+ return __module_alloc(size, PAGE_KERNEL_RX);
24995+}
24996+EXPORT_SYMBOL(module_alloc_exec);
24997+#endif
24998+#endif
24999+
25000 #ifdef CONFIG_X86_32
25001 int apply_relocate(Elf32_Shdr *sechdrs,
25002 const char *strtab,
25003@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25004 unsigned int i;
25005 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25006 Elf32_Sym *sym;
25007- uint32_t *location;
25008+ uint32_t *plocation, location;
25009
25010 DEBUGP("Applying relocate section %u to %u\n",
25011 relsec, sechdrs[relsec].sh_info);
25012 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25013 /* This is where to make the change */
25014- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25015- + rel[i].r_offset;
25016+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25017+ location = (uint32_t)plocation;
25018+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25019+ plocation = ktla_ktva((void *)plocation);
25020 /* This is the symbol it is referring to. Note that all
25021 undefined symbols have been resolved. */
25022 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25023@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25024 switch (ELF32_R_TYPE(rel[i].r_info)) {
25025 case R_386_32:
25026 /* We add the value into the location given */
25027- *location += sym->st_value;
25028+ pax_open_kernel();
25029+ *plocation += sym->st_value;
25030+ pax_close_kernel();
25031 break;
25032 case R_386_PC32:
25033 /* Add the value, subtract its position */
25034- *location += sym->st_value - (uint32_t)location;
25035+ pax_open_kernel();
25036+ *plocation += sym->st_value - location;
25037+ pax_close_kernel();
25038 break;
25039 default:
25040 pr_err("%s: Unknown relocation: %u\n",
25041@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25042 case R_X86_64_NONE:
25043 break;
25044 case R_X86_64_64:
25045+ pax_open_kernel();
25046 *(u64 *)loc = val;
25047+ pax_close_kernel();
25048 break;
25049 case R_X86_64_32:
25050+ pax_open_kernel();
25051 *(u32 *)loc = val;
25052+ pax_close_kernel();
25053 if (val != *(u32 *)loc)
25054 goto overflow;
25055 break;
25056 case R_X86_64_32S:
25057+ pax_open_kernel();
25058 *(s32 *)loc = val;
25059+ pax_close_kernel();
25060 if ((s64)val != *(s32 *)loc)
25061 goto overflow;
25062 break;
25063 case R_X86_64_PC32:
25064 val -= (u64)loc;
25065+ pax_open_kernel();
25066 *(u32 *)loc = val;
25067+ pax_close_kernel();
25068+
25069 #if 0
25070 if ((s64)val != *(s32 *)loc)
25071 goto overflow;
25072diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25073index 05266b5..1577fde 100644
25074--- a/arch/x86/kernel/msr.c
25075+++ b/arch/x86/kernel/msr.c
25076@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25077 return notifier_from_errno(err);
25078 }
25079
25080-static struct notifier_block __refdata msr_class_cpu_notifier = {
25081+static struct notifier_block msr_class_cpu_notifier = {
25082 .notifier_call = msr_class_cpu_callback,
25083 };
25084
25085diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25086index 6fcb49c..5b3f4ff 100644
25087--- a/arch/x86/kernel/nmi.c
25088+++ b/arch/x86/kernel/nmi.c
25089@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25090 return handled;
25091 }
25092
25093-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25094+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25095 {
25096 struct nmi_desc *desc = nmi_to_desc(type);
25097 unsigned long flags;
25098@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25099 * event confuses some handlers (kdump uses this flag)
25100 */
25101 if (action->flags & NMI_FLAG_FIRST)
25102- list_add_rcu(&action->list, &desc->head);
25103+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25104 else
25105- list_add_tail_rcu(&action->list, &desc->head);
25106+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25107
25108 spin_unlock_irqrestore(&desc->lock, flags);
25109 return 0;
25110@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25111 if (!strcmp(n->name, name)) {
25112 WARN(in_nmi(),
25113 "Trying to free NMI (%s) from NMI context!\n", n->name);
25114- list_del_rcu(&n->list);
25115+ pax_list_del_rcu((struct list_head *)&n->list);
25116 break;
25117 }
25118 }
25119@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25120 dotraplinkage notrace __kprobes void
25121 do_nmi(struct pt_regs *regs, long error_code)
25122 {
25123+
25124+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25125+ if (!user_mode(regs)) {
25126+ unsigned long cs = regs->cs & 0xFFFF;
25127+ unsigned long ip = ktva_ktla(regs->ip);
25128+
25129+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25130+ regs->ip = ip;
25131+ }
25132+#endif
25133+
25134 nmi_nesting_preprocess(regs);
25135
25136 nmi_enter();
25137diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25138index 6d9582e..f746287 100644
25139--- a/arch/x86/kernel/nmi_selftest.c
25140+++ b/arch/x86/kernel/nmi_selftest.c
25141@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25142 {
25143 /* trap all the unknown NMIs we may generate */
25144 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25145- __initdata);
25146+ __initconst);
25147 }
25148
25149 static void __init cleanup_nmi_testsuite(void)
25150@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25151 unsigned long timeout;
25152
25153 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25154- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25155+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25156 nmi_fail = FAILURE;
25157 return;
25158 }
25159diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25160index bbb6c73..24a58ef 100644
25161--- a/arch/x86/kernel/paravirt-spinlocks.c
25162+++ b/arch/x86/kernel/paravirt-spinlocks.c
25163@@ -8,7 +8,7 @@
25164
25165 #include <asm/paravirt.h>
25166
25167-struct pv_lock_ops pv_lock_ops = {
25168+struct pv_lock_ops pv_lock_ops __read_only = {
25169 #ifdef CONFIG_SMP
25170 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25171 .unlock_kick = paravirt_nop,
25172diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25173index 1b10af8..0b58cbc 100644
25174--- a/arch/x86/kernel/paravirt.c
25175+++ b/arch/x86/kernel/paravirt.c
25176@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25177 {
25178 return x;
25179 }
25180+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25181+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25182+#endif
25183
25184 void __init default_banner(void)
25185 {
25186@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25187 if (opfunc == NULL)
25188 /* If there's no function, patch it with a ud2a (BUG) */
25189 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25190- else if (opfunc == _paravirt_nop)
25191+ else if (opfunc == (void *)_paravirt_nop)
25192 /* If the operation is a nop, then nop the callsite */
25193 ret = paravirt_patch_nop();
25194
25195 /* identity functions just return their single argument */
25196- else if (opfunc == _paravirt_ident_32)
25197+ else if (opfunc == (void *)_paravirt_ident_32)
25198 ret = paravirt_patch_ident_32(insnbuf, len);
25199- else if (opfunc == _paravirt_ident_64)
25200+ else if (opfunc == (void *)_paravirt_ident_64)
25201 ret = paravirt_patch_ident_64(insnbuf, len);
25202+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25203+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25204+ ret = paravirt_patch_ident_64(insnbuf, len);
25205+#endif
25206
25207 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25208 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25209@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25210 if (insn_len > len || start == NULL)
25211 insn_len = len;
25212 else
25213- memcpy(insnbuf, start, insn_len);
25214+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25215
25216 return insn_len;
25217 }
25218@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25219 return this_cpu_read(paravirt_lazy_mode);
25220 }
25221
25222-struct pv_info pv_info = {
25223+struct pv_info pv_info __read_only = {
25224 .name = "bare hardware",
25225 .paravirt_enabled = 0,
25226 .kernel_rpl = 0,
25227@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25228 #endif
25229 };
25230
25231-struct pv_init_ops pv_init_ops = {
25232+struct pv_init_ops pv_init_ops __read_only = {
25233 .patch = native_patch,
25234 };
25235
25236-struct pv_time_ops pv_time_ops = {
25237+struct pv_time_ops pv_time_ops __read_only = {
25238 .sched_clock = native_sched_clock,
25239 .steal_clock = native_steal_clock,
25240 };
25241
25242-__visible struct pv_irq_ops pv_irq_ops = {
25243+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25244 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25245 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25246 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25247@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25248 #endif
25249 };
25250
25251-__visible struct pv_cpu_ops pv_cpu_ops = {
25252+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25253 .cpuid = native_cpuid,
25254 .get_debugreg = native_get_debugreg,
25255 .set_debugreg = native_set_debugreg,
25256@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25257 .end_context_switch = paravirt_nop,
25258 };
25259
25260-struct pv_apic_ops pv_apic_ops = {
25261+struct pv_apic_ops pv_apic_ops __read_only= {
25262 #ifdef CONFIG_X86_LOCAL_APIC
25263 .startup_ipi_hook = paravirt_nop,
25264 #endif
25265 };
25266
25267-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25268+#ifdef CONFIG_X86_32
25269+#ifdef CONFIG_X86_PAE
25270+/* 64-bit pagetable entries */
25271+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25272+#else
25273 /* 32-bit pagetable entries */
25274 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25275+#endif
25276 #else
25277 /* 64-bit pagetable entries */
25278 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25279 #endif
25280
25281-struct pv_mmu_ops pv_mmu_ops = {
25282+struct pv_mmu_ops pv_mmu_ops __read_only = {
25283
25284 .read_cr2 = native_read_cr2,
25285 .write_cr2 = native_write_cr2,
25286@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25287 .make_pud = PTE_IDENT,
25288
25289 .set_pgd = native_set_pgd,
25290+ .set_pgd_batched = native_set_pgd_batched,
25291 #endif
25292 #endif /* PAGETABLE_LEVELS >= 3 */
25293
25294@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25295 },
25296
25297 .set_fixmap = native_set_fixmap,
25298+
25299+#ifdef CONFIG_PAX_KERNEXEC
25300+ .pax_open_kernel = native_pax_open_kernel,
25301+ .pax_close_kernel = native_pax_close_kernel,
25302+#endif
25303+
25304 };
25305
25306 EXPORT_SYMBOL_GPL(pv_time_ops);
25307diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25308index 299d493..2ccb0ee 100644
25309--- a/arch/x86/kernel/pci-calgary_64.c
25310+++ b/arch/x86/kernel/pci-calgary_64.c
25311@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25312 tce_space = be64_to_cpu(readq(target));
25313 tce_space = tce_space & TAR_SW_BITS;
25314
25315- tce_space = tce_space & (~specified_table_size);
25316+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25317 info->tce_space = (u64 *)__va(tce_space);
25318 }
25319 }
25320diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25321index 35ccf75..7a15747 100644
25322--- a/arch/x86/kernel/pci-iommu_table.c
25323+++ b/arch/x86/kernel/pci-iommu_table.c
25324@@ -2,7 +2,7 @@
25325 #include <asm/iommu_table.h>
25326 #include <linux/string.h>
25327 #include <linux/kallsyms.h>
25328-
25329+#include <linux/sched.h>
25330
25331 #define DEBUG 1
25332
25333diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25334index 6c483ba..d10ce2f 100644
25335--- a/arch/x86/kernel/pci-swiotlb.c
25336+++ b/arch/x86/kernel/pci-swiotlb.c
25337@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25338 void *vaddr, dma_addr_t dma_addr,
25339 struct dma_attrs *attrs)
25340 {
25341- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25342+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25343 }
25344
25345 static struct dma_map_ops swiotlb_dma_ops = {
25346diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25347index ca7f0d5..8996469 100644
25348--- a/arch/x86/kernel/preempt.S
25349+++ b/arch/x86/kernel/preempt.S
25350@@ -3,12 +3,14 @@
25351 #include <asm/dwarf2.h>
25352 #include <asm/asm.h>
25353 #include <asm/calling.h>
25354+#include <asm/alternative-asm.h>
25355
25356 ENTRY(___preempt_schedule)
25357 CFI_STARTPROC
25358 SAVE_ALL
25359 call preempt_schedule
25360 RESTORE_ALL
25361+ pax_force_retaddr
25362 ret
25363 CFI_ENDPROC
25364
25365@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25366 SAVE_ALL
25367 call preempt_schedule_context
25368 RESTORE_ALL
25369+ pax_force_retaddr
25370 ret
25371 CFI_ENDPROC
25372
25373diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25374index 3fb8d95..254dc51 100644
25375--- a/arch/x86/kernel/process.c
25376+++ b/arch/x86/kernel/process.c
25377@@ -36,7 +36,8 @@
25378 * section. Since TSS's are completely CPU-local, we want them
25379 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25380 */
25381-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25382+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25383+EXPORT_SYMBOL(init_tss);
25384
25385 #ifdef CONFIG_X86_64
25386 static DEFINE_PER_CPU(unsigned char, is_idle);
25387@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25388 task_xstate_cachep =
25389 kmem_cache_create("task_xstate", xstate_size,
25390 __alignof__(union thread_xstate),
25391- SLAB_PANIC | SLAB_NOTRACK, NULL);
25392+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25393 }
25394
25395 /*
25396@@ -105,7 +106,7 @@ void exit_thread(void)
25397 unsigned long *bp = t->io_bitmap_ptr;
25398
25399 if (bp) {
25400- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25401+ struct tss_struct *tss = init_tss + get_cpu();
25402
25403 t->io_bitmap_ptr = NULL;
25404 clear_thread_flag(TIF_IO_BITMAP);
25405@@ -125,6 +126,9 @@ void flush_thread(void)
25406 {
25407 struct task_struct *tsk = current;
25408
25409+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25410+ loadsegment(gs, 0);
25411+#endif
25412 flush_ptrace_hw_breakpoint(tsk);
25413 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25414 drop_init_fpu(tsk);
25415@@ -271,7 +275,7 @@ static void __exit_idle(void)
25416 void exit_idle(void)
25417 {
25418 /* idle loop has pid 0 */
25419- if (current->pid)
25420+ if (task_pid_nr(current))
25421 return;
25422 __exit_idle();
25423 }
25424@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25425 return ret;
25426 }
25427 #endif
25428-void stop_this_cpu(void *dummy)
25429+__noreturn void stop_this_cpu(void *dummy)
25430 {
25431 local_irq_disable();
25432 /*
25433@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25434 }
25435 early_param("idle", idle_setup);
25436
25437-unsigned long arch_align_stack(unsigned long sp)
25438+#ifdef CONFIG_PAX_RANDKSTACK
25439+void pax_randomize_kstack(struct pt_regs *regs)
25440 {
25441- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25442- sp -= get_random_int() % 8192;
25443- return sp & ~0xf;
25444-}
25445+ struct thread_struct *thread = &current->thread;
25446+ unsigned long time;
25447
25448-unsigned long arch_randomize_brk(struct mm_struct *mm)
25449-{
25450- unsigned long range_end = mm->brk + 0x02000000;
25451- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25452-}
25453+ if (!randomize_va_space)
25454+ return;
25455+
25456+ if (v8086_mode(regs))
25457+ return;
25458
25459+ rdtscl(time);
25460+
25461+ /* P4 seems to return a 0 LSB, ignore it */
25462+#ifdef CONFIG_MPENTIUM4
25463+ time &= 0x3EUL;
25464+ time <<= 2;
25465+#elif defined(CONFIG_X86_64)
25466+ time &= 0xFUL;
25467+ time <<= 4;
25468+#else
25469+ time &= 0x1FUL;
25470+ time <<= 3;
25471+#endif
25472+
25473+ thread->sp0 ^= time;
25474+ load_sp0(init_tss + smp_processor_id(), thread);
25475+
25476+#ifdef CONFIG_X86_64
25477+ this_cpu_write(kernel_stack, thread->sp0);
25478+#endif
25479+}
25480+#endif
25481diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
25482index 6f1236c..fd448d4 100644
25483--- a/arch/x86/kernel/process_32.c
25484+++ b/arch/x86/kernel/process_32.c
25485@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
25486 unsigned long thread_saved_pc(struct task_struct *tsk)
25487 {
25488 return ((unsigned long *)tsk->thread.sp)[3];
25489+//XXX return tsk->thread.eip;
25490 }
25491
25492 void __show_regs(struct pt_regs *regs, int all)
25493@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
25494 unsigned long sp;
25495 unsigned short ss, gs;
25496
25497- if (user_mode_vm(regs)) {
25498+ if (user_mode(regs)) {
25499 sp = regs->sp;
25500 ss = regs->ss & 0xffff;
25501- gs = get_user_gs(regs);
25502 } else {
25503 sp = kernel_stack_pointer(regs);
25504 savesegment(ss, ss);
25505- savesegment(gs, gs);
25506 }
25507+ gs = get_user_gs(regs);
25508
25509 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
25510 (u16)regs->cs, regs->ip, regs->flags,
25511- smp_processor_id());
25512+ raw_smp_processor_id());
25513 print_symbol("EIP is at %s\n", regs->ip);
25514
25515 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
25516@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
25517 int copy_thread(unsigned long clone_flags, unsigned long sp,
25518 unsigned long arg, struct task_struct *p)
25519 {
25520- struct pt_regs *childregs = task_pt_regs(p);
25521+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
25522 struct task_struct *tsk;
25523 int err;
25524
25525 p->thread.sp = (unsigned long) childregs;
25526 p->thread.sp0 = (unsigned long) (childregs+1);
25527+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25528
25529 if (unlikely(p->flags & PF_KTHREAD)) {
25530 /* kernel thread */
25531 memset(childregs, 0, sizeof(struct pt_regs));
25532 p->thread.ip = (unsigned long) ret_from_kernel_thread;
25533- task_user_gs(p) = __KERNEL_STACK_CANARY;
25534- childregs->ds = __USER_DS;
25535- childregs->es = __USER_DS;
25536+ savesegment(gs, childregs->gs);
25537+ childregs->ds = __KERNEL_DS;
25538+ childregs->es = __KERNEL_DS;
25539 childregs->fs = __KERNEL_PERCPU;
25540 childregs->bx = sp; /* function */
25541 childregs->bp = arg;
25542@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25543 struct thread_struct *prev = &prev_p->thread,
25544 *next = &next_p->thread;
25545 int cpu = smp_processor_id();
25546- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25547+ struct tss_struct *tss = init_tss + cpu;
25548 fpu_switch_t fpu;
25549
25550 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
25551@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25552 */
25553 lazy_save_gs(prev->gs);
25554
25555+#ifdef CONFIG_PAX_MEMORY_UDEREF
25556+ __set_fs(task_thread_info(next_p)->addr_limit);
25557+#endif
25558+
25559 /*
25560 * Load the per-thread Thread-Local Storage descriptor.
25561 */
25562@@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25563 */
25564 arch_end_context_switch(next_p);
25565
25566+ this_cpu_write(current_task, next_p);
25567+ this_cpu_write(current_tinfo, &next_p->tinfo);
25568+
25569 /*
25570 * Restore %gs if needed (which is common)
25571 */
25572@@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25573
25574 switch_fpu_finish(next_p, fpu);
25575
25576- this_cpu_write(current_task, next_p);
25577-
25578 return prev_p;
25579 }
25580
25581@@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
25582 } while (count++ < 16);
25583 return 0;
25584 }
25585-
25586diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
25587index 9c0280f..5bbb1c0 100644
25588--- a/arch/x86/kernel/process_64.c
25589+++ b/arch/x86/kernel/process_64.c
25590@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25591 struct pt_regs *childregs;
25592 struct task_struct *me = current;
25593
25594- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25595+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25596 childregs = task_pt_regs(p);
25597 p->thread.sp = (unsigned long) childregs;
25598 p->thread.usersp = me->thread.usersp;
25599+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25600 set_tsk_thread_flag(p, TIF_FORK);
25601 p->thread.fpu_counter = 0;
25602 p->thread.io_bitmap_ptr = NULL;
25603@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25604 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25605 savesegment(es, p->thread.es);
25606 savesegment(ds, p->thread.ds);
25607+ savesegment(ss, p->thread.ss);
25608+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25609 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25610
25611 if (unlikely(p->flags & PF_KTHREAD)) {
25612@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25613 struct thread_struct *prev = &prev_p->thread;
25614 struct thread_struct *next = &next_p->thread;
25615 int cpu = smp_processor_id();
25616- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25617+ struct tss_struct *tss = init_tss + cpu;
25618 unsigned fsindex, gsindex;
25619 fpu_switch_t fpu;
25620
25621@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25622 if (unlikely(next->ds | prev->ds))
25623 loadsegment(ds, next->ds);
25624
25625+ savesegment(ss, prev->ss);
25626+ if (unlikely(next->ss != prev->ss))
25627+ loadsegment(ss, next->ss);
25628
25629 /* We must save %fs and %gs before load_TLS() because
25630 * %fs and %gs may be cleared by load_TLS().
25631@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25632 prev->usersp = this_cpu_read(old_rsp);
25633 this_cpu_write(old_rsp, next->usersp);
25634 this_cpu_write(current_task, next_p);
25635+ this_cpu_write(current_tinfo, &next_p->tinfo);
25636
25637 /*
25638 * If it were not for PREEMPT_ACTIVE we could guarantee that the
25639@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25640 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
25641 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
25642
25643- this_cpu_write(kernel_stack,
25644- (unsigned long)task_stack_page(next_p) +
25645- THREAD_SIZE - KERNEL_STACK_OFFSET);
25646+ this_cpu_write(kernel_stack, next->sp0);
25647
25648 /*
25649 * Now maybe reload the debug registers and handle I/O bitmaps
25650@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
25651 if (!p || p == current || p->state == TASK_RUNNING)
25652 return 0;
25653 stack = (unsigned long)task_stack_page(p);
25654- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25655+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25656 return 0;
25657 fp = *(u64 *)(p->thread.sp);
25658 do {
25659- if (fp < (unsigned long)stack ||
25660- fp >= (unsigned long)stack+THREAD_SIZE)
25661+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25662 return 0;
25663 ip = *(u64 *)(fp+8);
25664 if (!in_sched_functions(ip))
25665diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25666index 7461f50..1334029 100644
25667--- a/arch/x86/kernel/ptrace.c
25668+++ b/arch/x86/kernel/ptrace.c
25669@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25670 {
25671 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25672 unsigned long sp = (unsigned long)&regs->sp;
25673- struct thread_info *tinfo;
25674
25675- if (context == (sp & ~(THREAD_SIZE - 1)))
25676+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25677 return sp;
25678
25679- tinfo = (struct thread_info *)context;
25680- if (tinfo->previous_esp)
25681- return tinfo->previous_esp;
25682+ sp = *(unsigned long *)context;
25683+ if (sp)
25684+ return sp;
25685
25686 return (unsigned long)regs;
25687 }
25688@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25689 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25690 {
25691 int i;
25692- int dr7 = 0;
25693+ unsigned long dr7 = 0;
25694 struct arch_hw_breakpoint *info;
25695
25696 for (i = 0; i < HBP_NUM; i++) {
25697@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
25698 unsigned long addr, unsigned long data)
25699 {
25700 int ret;
25701- unsigned long __user *datap = (unsigned long __user *)data;
25702+ unsigned long __user *datap = (__force unsigned long __user *)data;
25703
25704 switch (request) {
25705 /* read the word at location addr in the USER area. */
25706@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
25707 if ((int) addr < 0)
25708 return -EIO;
25709 ret = do_get_thread_area(child, addr,
25710- (struct user_desc __user *)data);
25711+ (__force struct user_desc __user *) data);
25712 break;
25713
25714 case PTRACE_SET_THREAD_AREA:
25715 if ((int) addr < 0)
25716 return -EIO;
25717 ret = do_set_thread_area(child, addr,
25718- (struct user_desc __user *)data, 0);
25719+ (__force struct user_desc __user *) data, 0);
25720 break;
25721 #endif
25722
25723@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25724
25725 #ifdef CONFIG_X86_64
25726
25727-static struct user_regset x86_64_regsets[] __read_mostly = {
25728+static user_regset_no_const x86_64_regsets[] __read_only = {
25729 [REGSET_GENERAL] = {
25730 .core_note_type = NT_PRSTATUS,
25731 .n = sizeof(struct user_regs_struct) / sizeof(long),
25732@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
25733 #endif /* CONFIG_X86_64 */
25734
25735 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25736-static struct user_regset x86_32_regsets[] __read_mostly = {
25737+static user_regset_no_const x86_32_regsets[] __read_only = {
25738 [REGSET_GENERAL] = {
25739 .core_note_type = NT_PRSTATUS,
25740 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25741@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
25742 */
25743 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25744
25745-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25746+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25747 {
25748 #ifdef CONFIG_X86_64
25749 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25750@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25751 memset(info, 0, sizeof(*info));
25752 info->si_signo = SIGTRAP;
25753 info->si_code = si_code;
25754- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25755+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25756 }
25757
25758 void user_single_step_siginfo(struct task_struct *tsk,
25759@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25760 # define IS_IA32 0
25761 #endif
25762
25763+#ifdef CONFIG_GRKERNSEC_SETXID
25764+extern void gr_delayed_cred_worker(void);
25765+#endif
25766+
25767 /*
25768 * We must return the syscall number to actually look up in the table.
25769 * This can be -1L to skip running any syscall at all.
25770@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25771
25772 user_exit();
25773
25774+#ifdef CONFIG_GRKERNSEC_SETXID
25775+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25776+ gr_delayed_cred_worker();
25777+#endif
25778+
25779 /*
25780 * If we stepped into a sysenter/syscall insn, it trapped in
25781 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25782@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25783 */
25784 user_exit();
25785
25786+#ifdef CONFIG_GRKERNSEC_SETXID
25787+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25788+ gr_delayed_cred_worker();
25789+#endif
25790+
25791 audit_syscall_exit(regs);
25792
25793 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25794diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25795index 2f355d2..e75ed0a 100644
25796--- a/arch/x86/kernel/pvclock.c
25797+++ b/arch/x86/kernel/pvclock.c
25798@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
25799 reset_hung_task_detector();
25800 }
25801
25802-static atomic64_t last_value = ATOMIC64_INIT(0);
25803+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25804
25805 void pvclock_resume(void)
25806 {
25807- atomic64_set(&last_value, 0);
25808+ atomic64_set_unchecked(&last_value, 0);
25809 }
25810
25811 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25812@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25813 * updating at the same time, and one of them could be slightly behind,
25814 * making the assumption that last_value always go forward fail to hold.
25815 */
25816- last = atomic64_read(&last_value);
25817+ last = atomic64_read_unchecked(&last_value);
25818 do {
25819 if (ret < last)
25820 return last;
25821- last = atomic64_cmpxchg(&last_value, last, ret);
25822+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25823 } while (unlikely(last != ret));
25824
25825 return ret;
25826diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25827index c752cb4..866c432 100644
25828--- a/arch/x86/kernel/reboot.c
25829+++ b/arch/x86/kernel/reboot.c
25830@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25831
25832 void __noreturn machine_real_restart(unsigned int type)
25833 {
25834+
25835+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25836+ struct desc_struct *gdt;
25837+#endif
25838+
25839 local_irq_disable();
25840
25841 /*
25842@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25843
25844 /* Jump to the identity-mapped low memory code */
25845 #ifdef CONFIG_X86_32
25846- asm volatile("jmpl *%0" : :
25847+
25848+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25849+ gdt = get_cpu_gdt_table(smp_processor_id());
25850+ pax_open_kernel();
25851+#ifdef CONFIG_PAX_MEMORY_UDEREF
25852+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25853+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25854+ loadsegment(ds, __KERNEL_DS);
25855+ loadsegment(es, __KERNEL_DS);
25856+ loadsegment(ss, __KERNEL_DS);
25857+#endif
25858+#ifdef CONFIG_PAX_KERNEXEC
25859+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25860+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25861+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25862+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25863+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25864+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25865+#endif
25866+ pax_close_kernel();
25867+#endif
25868+
25869+ asm volatile("ljmpl *%0" : :
25870 "rm" (real_mode_header->machine_real_restart_asm),
25871 "a" (type));
25872 #else
25873@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25874 * try to force a triple fault and then cycle between hitting the keyboard
25875 * controller and doing that
25876 */
25877-static void native_machine_emergency_restart(void)
25878+static void __noreturn native_machine_emergency_restart(void)
25879 {
25880 int i;
25881 int attempt = 0;
25882@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
25883 #endif
25884 }
25885
25886-static void __machine_emergency_restart(int emergency)
25887+static void __noreturn __machine_emergency_restart(int emergency)
25888 {
25889 reboot_emergency = emergency;
25890 machine_ops.emergency_restart();
25891 }
25892
25893-static void native_machine_restart(char *__unused)
25894+static void __noreturn native_machine_restart(char *__unused)
25895 {
25896 pr_notice("machine restart\n");
25897
25898@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
25899 __machine_emergency_restart(0);
25900 }
25901
25902-static void native_machine_halt(void)
25903+static void __noreturn native_machine_halt(void)
25904 {
25905 /* Stop other cpus and apics */
25906 machine_shutdown();
25907@@ -618,7 +645,7 @@ static void native_machine_halt(void)
25908 stop_this_cpu(NULL);
25909 }
25910
25911-static void native_machine_power_off(void)
25912+static void __noreturn native_machine_power_off(void)
25913 {
25914 if (pm_power_off) {
25915 if (!reboot_force)
25916@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
25917 }
25918 /* A fallback in case there is no PM info available */
25919 tboot_shutdown(TB_SHUTDOWN_HALT);
25920+ unreachable();
25921 }
25922
25923-struct machine_ops machine_ops = {
25924+struct machine_ops machine_ops __read_only = {
25925 .power_off = native_machine_power_off,
25926 .shutdown = native_machine_shutdown,
25927 .emergency_restart = native_machine_emergency_restart,
25928diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25929index c8e41e9..64049ef 100644
25930--- a/arch/x86/kernel/reboot_fixups_32.c
25931+++ b/arch/x86/kernel/reboot_fixups_32.c
25932@@ -57,7 +57,7 @@ struct device_fixup {
25933 unsigned int vendor;
25934 unsigned int device;
25935 void (*reboot_fixup)(struct pci_dev *);
25936-};
25937+} __do_const;
25938
25939 /*
25940 * PCI ids solely used for fixups_table go here
25941diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25942index 3fd2c69..16ef367 100644
25943--- a/arch/x86/kernel/relocate_kernel_64.S
25944+++ b/arch/x86/kernel/relocate_kernel_64.S
25945@@ -11,6 +11,7 @@
25946 #include <asm/kexec.h>
25947 #include <asm/processor-flags.h>
25948 #include <asm/pgtable_types.h>
25949+#include <asm/alternative-asm.h>
25950
25951 /*
25952 * Must be relocatable PIC code callable as a C function
25953@@ -96,8 +97,7 @@ relocate_kernel:
25954
25955 /* jump to identity mapped page */
25956 addq $(identity_mapped - relocate_kernel), %r8
25957- pushq %r8
25958- ret
25959+ jmp *%r8
25960
25961 identity_mapped:
25962 /* set return address to 0 if not preserving context */
25963@@ -167,6 +167,7 @@ identity_mapped:
25964 xorl %r14d, %r14d
25965 xorl %r15d, %r15d
25966
25967+ pax_force_retaddr 0, 1
25968 ret
25969
25970 1:
25971diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25972index cb233bc..23b4879 100644
25973--- a/arch/x86/kernel/setup.c
25974+++ b/arch/x86/kernel/setup.c
25975@@ -110,6 +110,7 @@
25976 #include <asm/mce.h>
25977 #include <asm/alternative.h>
25978 #include <asm/prom.h>
25979+#include <asm/boot.h>
25980
25981 /*
25982 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25983@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25984 #endif
25985
25986
25987-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25988-__visible unsigned long mmu_cr4_features;
25989+#ifdef CONFIG_X86_64
25990+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25991+#elif defined(CONFIG_X86_PAE)
25992+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25993 #else
25994-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
25995+__visible unsigned long mmu_cr4_features __read_only;
25996 #endif
25997
25998+void set_in_cr4(unsigned long mask)
25999+{
26000+ unsigned long cr4 = read_cr4();
26001+
26002+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26003+ return;
26004+
26005+ pax_open_kernel();
26006+ mmu_cr4_features |= mask;
26007+ pax_close_kernel();
26008+
26009+ if (trampoline_cr4_features)
26010+ *trampoline_cr4_features = mmu_cr4_features;
26011+ cr4 |= mask;
26012+ write_cr4(cr4);
26013+}
26014+EXPORT_SYMBOL(set_in_cr4);
26015+
26016+void clear_in_cr4(unsigned long mask)
26017+{
26018+ unsigned long cr4 = read_cr4();
26019+
26020+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26021+ return;
26022+
26023+ pax_open_kernel();
26024+ mmu_cr4_features &= ~mask;
26025+ pax_close_kernel();
26026+
26027+ if (trampoline_cr4_features)
26028+ *trampoline_cr4_features = mmu_cr4_features;
26029+ cr4 &= ~mask;
26030+ write_cr4(cr4);
26031+}
26032+EXPORT_SYMBOL(clear_in_cr4);
26033+
26034 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26035 int bootloader_type, bootloader_version;
26036
26037@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26038 * area (640->1Mb) as ram even though it is not.
26039 * take them out.
26040 */
26041- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26042+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26043
26044 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26045 }
26046@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26047 /* called before trim_bios_range() to spare extra sanitize */
26048 static void __init e820_add_kernel_range(void)
26049 {
26050- u64 start = __pa_symbol(_text);
26051+ u64 start = __pa_symbol(ktla_ktva(_text));
26052 u64 size = __pa_symbol(_end) - start;
26053
26054 /*
26055@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26056
26057 void __init setup_arch(char **cmdline_p)
26058 {
26059+#ifdef CONFIG_X86_32
26060+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26061+#else
26062 memblock_reserve(__pa_symbol(_text),
26063 (unsigned long)__bss_stop - (unsigned long)_text);
26064+#endif
26065
26066 early_reserve_initrd();
26067
26068@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26069
26070 if (!boot_params.hdr.root_flags)
26071 root_mountflags &= ~MS_RDONLY;
26072- init_mm.start_code = (unsigned long) _text;
26073- init_mm.end_code = (unsigned long) _etext;
26074+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26075+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26076 init_mm.end_data = (unsigned long) _edata;
26077 init_mm.brk = _brk_end;
26078
26079- code_resource.start = __pa_symbol(_text);
26080- code_resource.end = __pa_symbol(_etext)-1;
26081- data_resource.start = __pa_symbol(_etext);
26082+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26083+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26084+ data_resource.start = __pa_symbol(_sdata);
26085 data_resource.end = __pa_symbol(_edata)-1;
26086 bss_resource.start = __pa_symbol(__bss_start);
26087 bss_resource.end = __pa_symbol(__bss_stop)-1;
26088diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26089index 5cdff03..80fa283 100644
26090--- a/arch/x86/kernel/setup_percpu.c
26091+++ b/arch/x86/kernel/setup_percpu.c
26092@@ -21,19 +21,17 @@
26093 #include <asm/cpu.h>
26094 #include <asm/stackprotector.h>
26095
26096-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26097+#ifdef CONFIG_SMP
26098+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26099 EXPORT_PER_CPU_SYMBOL(cpu_number);
26100+#endif
26101
26102-#ifdef CONFIG_X86_64
26103 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26104-#else
26105-#define BOOT_PERCPU_OFFSET 0
26106-#endif
26107
26108 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26109 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26110
26111-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26112+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26113 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26114 };
26115 EXPORT_SYMBOL(__per_cpu_offset);
26116@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26117 {
26118 #ifdef CONFIG_NEED_MULTIPLE_NODES
26119 pg_data_t *last = NULL;
26120- unsigned int cpu;
26121+ int cpu;
26122
26123 for_each_possible_cpu(cpu) {
26124 int node = early_cpu_to_node(cpu);
26125@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26126 {
26127 #ifdef CONFIG_X86_32
26128 struct desc_struct gdt;
26129+ unsigned long base = per_cpu_offset(cpu);
26130
26131- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26132- 0x2 | DESCTYPE_S, 0x8);
26133- gdt.s = 1;
26134+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26135+ 0x83 | DESCTYPE_S, 0xC);
26136 write_gdt_entry(get_cpu_gdt_table(cpu),
26137 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26138 #endif
26139@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26140 /* alrighty, percpu areas up and running */
26141 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26142 for_each_possible_cpu(cpu) {
26143+#ifdef CONFIG_CC_STACKPROTECTOR
26144+#ifdef CONFIG_X86_32
26145+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26146+#endif
26147+#endif
26148 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26149 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26150 per_cpu(cpu_number, cpu) = cpu;
26151@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26152 */
26153 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26154 #endif
26155+#ifdef CONFIG_CC_STACKPROTECTOR
26156+#ifdef CONFIG_X86_32
26157+ if (!cpu)
26158+ per_cpu(stack_canary.canary, cpu) = canary;
26159+#endif
26160+#endif
26161 /*
26162 * Up to this point, the boot CPU has been using .init.data
26163 * area. Reload any changed state for the boot CPU.
26164diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26165index 9e5de68..16c53cb 100644
26166--- a/arch/x86/kernel/signal.c
26167+++ b/arch/x86/kernel/signal.c
26168@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26169 * Align the stack pointer according to the i386 ABI,
26170 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26171 */
26172- sp = ((sp + 4) & -16ul) - 4;
26173+ sp = ((sp - 12) & -16ul) - 4;
26174 #else /* !CONFIG_X86_32 */
26175 sp = round_down(sp, 16) - 8;
26176 #endif
26177@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26178 }
26179
26180 if (current->mm->context.vdso)
26181- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26182+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26183 else
26184- restorer = &frame->retcode;
26185+ restorer = (void __user *)&frame->retcode;
26186 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26187 restorer = ksig->ka.sa.sa_restorer;
26188
26189@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26190 * reasons and because gdb uses it as a signature to notice
26191 * signal handler stack frames.
26192 */
26193- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26194+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26195
26196 if (err)
26197 return -EFAULT;
26198@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26199 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26200
26201 /* Set up to return from userspace. */
26202- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26203+ if (current->mm->context.vdso)
26204+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26205+ else
26206+ restorer = (void __user *)&frame->retcode;
26207 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26208 restorer = ksig->ka.sa.sa_restorer;
26209 put_user_ex(restorer, &frame->pretcode);
26210@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26211 * reasons and because gdb uses it as a signature to notice
26212 * signal handler stack frames.
26213 */
26214- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26215+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26216 } put_user_catch(err);
26217
26218 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26219@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26220 {
26221 int usig = signr_convert(ksig->sig);
26222 sigset_t *set = sigmask_to_save();
26223- compat_sigset_t *cset = (compat_sigset_t *) set;
26224+ sigset_t sigcopy;
26225+ compat_sigset_t *cset;
26226+
26227+ sigcopy = *set;
26228+
26229+ cset = (compat_sigset_t *) &sigcopy;
26230
26231 /* Set up the stack frame */
26232 if (is_ia32_frame()) {
26233@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26234 } else if (is_x32_frame()) {
26235 return x32_setup_rt_frame(ksig, cset, regs);
26236 } else {
26237- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26238+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26239 }
26240 }
26241
26242diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26243index 7c3a5a6..f0a8961 100644
26244--- a/arch/x86/kernel/smp.c
26245+++ b/arch/x86/kernel/smp.c
26246@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26247
26248 __setup("nonmi_ipi", nonmi_ipi_setup);
26249
26250-struct smp_ops smp_ops = {
26251+struct smp_ops smp_ops __read_only = {
26252 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26253 .smp_prepare_cpus = native_smp_prepare_cpus,
26254 .smp_cpus_done = native_smp_cpus_done,
26255diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26256index 85dc05a..1241266 100644
26257--- a/arch/x86/kernel/smpboot.c
26258+++ b/arch/x86/kernel/smpboot.c
26259@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26260
26261 enable_start_cpu0 = 0;
26262
26263-#ifdef CONFIG_X86_32
26264- /* switch away from the initial page table */
26265- load_cr3(swapper_pg_dir);
26266- __flush_tlb_all();
26267-#endif
26268-
26269 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26270 barrier();
26271+
26272+ /* switch away from the initial page table */
26273+#ifdef CONFIG_PAX_PER_CPU_PGD
26274+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26275+ __flush_tlb_all();
26276+#elif defined(CONFIG_X86_32)
26277+ load_cr3(swapper_pg_dir);
26278+ __flush_tlb_all();
26279+#endif
26280+
26281 /*
26282 * Check TSC synchronization with the BP:
26283 */
26284@@ -751,6 +755,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26285 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26286 (THREAD_SIZE + task_stack_page(idle))) - 1);
26287 per_cpu(current_task, cpu) = idle;
26288+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26289
26290 #ifdef CONFIG_X86_32
26291 /* Stack for startup_32 can be just as for start_secondary onwards */
26292@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26293 #else
26294 clear_tsk_thread_flag(idle, TIF_FORK);
26295 initial_gs = per_cpu_offset(cpu);
26296- per_cpu(kernel_stack, cpu) =
26297- (unsigned long)task_stack_page(idle) -
26298- KERNEL_STACK_OFFSET + THREAD_SIZE;
26299+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26300 #endif
26301+
26302+ pax_open_kernel();
26303 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26304+ pax_close_kernel();
26305+
26306 initial_code = (unsigned long)start_secondary;
26307 stack_start = idle->thread.sp;
26308
26309@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26310 /* the FPU context is blank, nobody can own it */
26311 __cpu_disable_lazy_restore(cpu);
26312
26313+#ifdef CONFIG_PAX_PER_CPU_PGD
26314+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26315+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26316+ KERNEL_PGD_PTRS);
26317+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26318+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26319+ KERNEL_PGD_PTRS);
26320+#endif
26321+
26322 err = do_boot_cpu(apicid, cpu, tidle);
26323 if (err) {
26324 pr_debug("do_boot_cpu failed %d\n", err);
26325diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26326index 9b4d51d..5d28b58 100644
26327--- a/arch/x86/kernel/step.c
26328+++ b/arch/x86/kernel/step.c
26329@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26330 struct desc_struct *desc;
26331 unsigned long base;
26332
26333- seg &= ~7UL;
26334+ seg >>= 3;
26335
26336 mutex_lock(&child->mm->context.lock);
26337- if (unlikely((seg >> 3) >= child->mm->context.size))
26338+ if (unlikely(seg >= child->mm->context.size))
26339 addr = -1L; /* bogus selector, access would fault */
26340 else {
26341 desc = child->mm->context.ldt + seg;
26342@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26343 addr += base;
26344 }
26345 mutex_unlock(&child->mm->context.lock);
26346- }
26347+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26348+ addr = ktla_ktva(addr);
26349
26350 return addr;
26351 }
26352@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26353 unsigned char opcode[15];
26354 unsigned long addr = convert_ip_to_linear(child, regs);
26355
26356+ if (addr == -EINVAL)
26357+ return 0;
26358+
26359 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26360 for (i = 0; i < copied; i++) {
26361 switch (opcode[i]) {
26362diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26363new file mode 100644
26364index 0000000..5877189
26365--- /dev/null
26366+++ b/arch/x86/kernel/sys_i386_32.c
26367@@ -0,0 +1,189 @@
26368+/*
26369+ * This file contains various random system calls that
26370+ * have a non-standard calling sequence on the Linux/i386
26371+ * platform.
26372+ */
26373+
26374+#include <linux/errno.h>
26375+#include <linux/sched.h>
26376+#include <linux/mm.h>
26377+#include <linux/fs.h>
26378+#include <linux/smp.h>
26379+#include <linux/sem.h>
26380+#include <linux/msg.h>
26381+#include <linux/shm.h>
26382+#include <linux/stat.h>
26383+#include <linux/syscalls.h>
26384+#include <linux/mman.h>
26385+#include <linux/file.h>
26386+#include <linux/utsname.h>
26387+#include <linux/ipc.h>
26388+#include <linux/elf.h>
26389+
26390+#include <linux/uaccess.h>
26391+#include <linux/unistd.h>
26392+
26393+#include <asm/syscalls.h>
26394+
26395+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26396+{
26397+ unsigned long pax_task_size = TASK_SIZE;
26398+
26399+#ifdef CONFIG_PAX_SEGMEXEC
26400+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26401+ pax_task_size = SEGMEXEC_TASK_SIZE;
26402+#endif
26403+
26404+ if (flags & MAP_FIXED)
26405+ if (len > pax_task_size || addr > pax_task_size - len)
26406+ return -EINVAL;
26407+
26408+ return 0;
26409+}
26410+
26411+/*
26412+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26413+ */
26414+static unsigned long get_align_mask(void)
26415+{
26416+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26417+ return 0;
26418+
26419+ if (!(current->flags & PF_RANDOMIZE))
26420+ return 0;
26421+
26422+ return va_align.mask;
26423+}
26424+
26425+unsigned long
26426+arch_get_unmapped_area(struct file *filp, unsigned long addr,
26427+ unsigned long len, unsigned long pgoff, unsigned long flags)
26428+{
26429+ struct mm_struct *mm = current->mm;
26430+ struct vm_area_struct *vma;
26431+ unsigned long pax_task_size = TASK_SIZE;
26432+ struct vm_unmapped_area_info info;
26433+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26434+
26435+#ifdef CONFIG_PAX_SEGMEXEC
26436+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26437+ pax_task_size = SEGMEXEC_TASK_SIZE;
26438+#endif
26439+
26440+ pax_task_size -= PAGE_SIZE;
26441+
26442+ if (len > pax_task_size)
26443+ return -ENOMEM;
26444+
26445+ if (flags & MAP_FIXED)
26446+ return addr;
26447+
26448+#ifdef CONFIG_PAX_RANDMMAP
26449+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26450+#endif
26451+
26452+ if (addr) {
26453+ addr = PAGE_ALIGN(addr);
26454+ if (pax_task_size - len >= addr) {
26455+ vma = find_vma(mm, addr);
26456+ if (check_heap_stack_gap(vma, addr, len, offset))
26457+ return addr;
26458+ }
26459+ }
26460+
26461+ info.flags = 0;
26462+ info.length = len;
26463+ info.align_mask = filp ? get_align_mask() : 0;
26464+ info.align_offset = pgoff << PAGE_SHIFT;
26465+ info.threadstack_offset = offset;
26466+
26467+#ifdef CONFIG_PAX_PAGEEXEC
26468+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26469+ info.low_limit = 0x00110000UL;
26470+ info.high_limit = mm->start_code;
26471+
26472+#ifdef CONFIG_PAX_RANDMMAP
26473+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26474+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26475+#endif
26476+
26477+ if (info.low_limit < info.high_limit) {
26478+ addr = vm_unmapped_area(&info);
26479+ if (!IS_ERR_VALUE(addr))
26480+ return addr;
26481+ }
26482+ } else
26483+#endif
26484+
26485+ info.low_limit = mm->mmap_base;
26486+ info.high_limit = pax_task_size;
26487+
26488+ return vm_unmapped_area(&info);
26489+}
26490+
26491+unsigned long
26492+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26493+ const unsigned long len, const unsigned long pgoff,
26494+ const unsigned long flags)
26495+{
26496+ struct vm_area_struct *vma;
26497+ struct mm_struct *mm = current->mm;
26498+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
26499+ struct vm_unmapped_area_info info;
26500+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26501+
26502+#ifdef CONFIG_PAX_SEGMEXEC
26503+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26504+ pax_task_size = SEGMEXEC_TASK_SIZE;
26505+#endif
26506+
26507+ pax_task_size -= PAGE_SIZE;
26508+
26509+ /* requested length too big for entire address space */
26510+ if (len > pax_task_size)
26511+ return -ENOMEM;
26512+
26513+ if (flags & MAP_FIXED)
26514+ return addr;
26515+
26516+#ifdef CONFIG_PAX_PAGEEXEC
26517+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
26518+ goto bottomup;
26519+#endif
26520+
26521+#ifdef CONFIG_PAX_RANDMMAP
26522+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26523+#endif
26524+
26525+ /* requesting a specific address */
26526+ if (addr) {
26527+ addr = PAGE_ALIGN(addr);
26528+ if (pax_task_size - len >= addr) {
26529+ vma = find_vma(mm, addr);
26530+ if (check_heap_stack_gap(vma, addr, len, offset))
26531+ return addr;
26532+ }
26533+ }
26534+
26535+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
26536+ info.length = len;
26537+ info.low_limit = PAGE_SIZE;
26538+ info.high_limit = mm->mmap_base;
26539+ info.align_mask = filp ? get_align_mask() : 0;
26540+ info.align_offset = pgoff << PAGE_SHIFT;
26541+ info.threadstack_offset = offset;
26542+
26543+ addr = vm_unmapped_area(&info);
26544+ if (!(addr & ~PAGE_MASK))
26545+ return addr;
26546+ VM_BUG_ON(addr != -ENOMEM);
26547+
26548+bottomup:
26549+ /*
26550+ * A failed mmap() very likely causes application failure,
26551+ * so fall back to the bottom-up function here. This scenario
26552+ * can happen with large stack limits and large mmap()
26553+ * allocations.
26554+ */
26555+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
26556+}
26557diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
26558index 30277e2..5664a29 100644
26559--- a/arch/x86/kernel/sys_x86_64.c
26560+++ b/arch/x86/kernel/sys_x86_64.c
26561@@ -81,8 +81,8 @@ out:
26562 return error;
26563 }
26564
26565-static void find_start_end(unsigned long flags, unsigned long *begin,
26566- unsigned long *end)
26567+static void find_start_end(struct mm_struct *mm, unsigned long flags,
26568+ unsigned long *begin, unsigned long *end)
26569 {
26570 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
26571 unsigned long new_begin;
26572@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
26573 *begin = new_begin;
26574 }
26575 } else {
26576- *begin = current->mm->mmap_legacy_base;
26577+ *begin = mm->mmap_legacy_base;
26578 *end = TASK_SIZE;
26579 }
26580 }
26581@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26582 struct vm_area_struct *vma;
26583 struct vm_unmapped_area_info info;
26584 unsigned long begin, end;
26585+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26586
26587 if (flags & MAP_FIXED)
26588 return addr;
26589
26590- find_start_end(flags, &begin, &end);
26591+ find_start_end(mm, flags, &begin, &end);
26592
26593 if (len > end)
26594 return -ENOMEM;
26595
26596+#ifdef CONFIG_PAX_RANDMMAP
26597+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26598+#endif
26599+
26600 if (addr) {
26601 addr = PAGE_ALIGN(addr);
26602 vma = find_vma(mm, addr);
26603- if (end - len >= addr &&
26604- (!vma || addr + len <= vma->vm_start))
26605+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26606 return addr;
26607 }
26608
26609@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26610 info.high_limit = end;
26611 info.align_mask = filp ? get_align_mask() : 0;
26612 info.align_offset = pgoff << PAGE_SHIFT;
26613+ info.threadstack_offset = offset;
26614 return vm_unmapped_area(&info);
26615 }
26616
26617@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26618 struct mm_struct *mm = current->mm;
26619 unsigned long addr = addr0;
26620 struct vm_unmapped_area_info info;
26621+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26622
26623 /* requested length too big for entire address space */
26624 if (len > TASK_SIZE)
26625@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26626 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26627 goto bottomup;
26628
26629+#ifdef CONFIG_PAX_RANDMMAP
26630+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26631+#endif
26632+
26633 /* requesting a specific address */
26634 if (addr) {
26635 addr = PAGE_ALIGN(addr);
26636 vma = find_vma(mm, addr);
26637- if (TASK_SIZE - len >= addr &&
26638- (!vma || addr + len <= vma->vm_start))
26639+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26640 return addr;
26641 }
26642
26643@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26644 info.high_limit = mm->mmap_base;
26645 info.align_mask = filp ? get_align_mask() : 0;
26646 info.align_offset = pgoff << PAGE_SHIFT;
26647+ info.threadstack_offset = offset;
26648 addr = vm_unmapped_area(&info);
26649 if (!(addr & ~PAGE_MASK))
26650 return addr;
26651diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26652index 91a4496..bb87552 100644
26653--- a/arch/x86/kernel/tboot.c
26654+++ b/arch/x86/kernel/tboot.c
26655@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
26656
26657 void tboot_shutdown(u32 shutdown_type)
26658 {
26659- void (*shutdown)(void);
26660+ void (* __noreturn shutdown)(void);
26661
26662 if (!tboot_enabled())
26663 return;
26664@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
26665
26666 switch_to_tboot_pt();
26667
26668- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26669+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
26670 shutdown();
26671
26672 /* should not reach here */
26673@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
26674 return -ENODEV;
26675 }
26676
26677-static atomic_t ap_wfs_count;
26678+static atomic_unchecked_t ap_wfs_count;
26679
26680 static int tboot_wait_for_aps(int num_aps)
26681 {
26682@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
26683 {
26684 switch (action) {
26685 case CPU_DYING:
26686- atomic_inc(&ap_wfs_count);
26687+ atomic_inc_unchecked(&ap_wfs_count);
26688 if (num_online_cpus() == 1)
26689- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26690+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26691 return NOTIFY_BAD;
26692 break;
26693 }
26694@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
26695
26696 tboot_create_trampoline();
26697
26698- atomic_set(&ap_wfs_count, 0);
26699+ atomic_set_unchecked(&ap_wfs_count, 0);
26700 register_hotcpu_notifier(&tboot_cpu_notifier);
26701
26702 #ifdef CONFIG_DEBUG_FS
26703diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26704index 24d3c91..d06b473 100644
26705--- a/arch/x86/kernel/time.c
26706+++ b/arch/x86/kernel/time.c
26707@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26708 {
26709 unsigned long pc = instruction_pointer(regs);
26710
26711- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26712+ if (!user_mode(regs) && in_lock_functions(pc)) {
26713 #ifdef CONFIG_FRAME_POINTER
26714- return *(unsigned long *)(regs->bp + sizeof(long));
26715+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26716 #else
26717 unsigned long *sp =
26718 (unsigned long *)kernel_stack_pointer(regs);
26719@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26720 * or above a saved flags. Eflags has bits 22-31 zero,
26721 * kernel addresses don't.
26722 */
26723+
26724+#ifdef CONFIG_PAX_KERNEXEC
26725+ return ktla_ktva(sp[0]);
26726+#else
26727 if (sp[0] >> 22)
26728 return sp[0];
26729 if (sp[1] >> 22)
26730 return sp[1];
26731 #endif
26732+
26733+#endif
26734 }
26735 return pc;
26736 }
26737diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26738index f7fec09..9991981 100644
26739--- a/arch/x86/kernel/tls.c
26740+++ b/arch/x86/kernel/tls.c
26741@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26742 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26743 return -EINVAL;
26744
26745+#ifdef CONFIG_PAX_SEGMEXEC
26746+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26747+ return -EINVAL;
26748+#endif
26749+
26750 set_tls_desc(p, idx, &info, 1);
26751
26752 return 0;
26753@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26754
26755 if (kbuf)
26756 info = kbuf;
26757- else if (__copy_from_user(infobuf, ubuf, count))
26758+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26759 return -EFAULT;
26760 else
26761 info = infobuf;
26762diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
26763index 1c113db..287b42e 100644
26764--- a/arch/x86/kernel/tracepoint.c
26765+++ b/arch/x86/kernel/tracepoint.c
26766@@ -9,11 +9,11 @@
26767 #include <linux/atomic.h>
26768
26769 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
26770-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26771+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26772 (unsigned long) trace_idt_table };
26773
26774 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26775-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
26776+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
26777
26778 static int trace_irq_vector_refcount;
26779 static DEFINE_MUTEX(irq_vector_mutex);
26780diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26781index b857ed8..51ae4cb 100644
26782--- a/arch/x86/kernel/traps.c
26783+++ b/arch/x86/kernel/traps.c
26784@@ -66,7 +66,7 @@
26785 #include <asm/proto.h>
26786
26787 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26788-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
26789+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
26790 #else
26791 #include <asm/processor-flags.h>
26792 #include <asm/setup.h>
26793@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
26794 #endif
26795
26796 /* Must be page-aligned because the real IDT is used in a fixmap. */
26797-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
26798+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
26799
26800 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26801 EXPORT_SYMBOL_GPL(used_vectors);
26802@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26803 }
26804
26805 static int __kprobes
26806-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26807+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26808 struct pt_regs *regs, long error_code)
26809 {
26810 #ifdef CONFIG_X86_32
26811- if (regs->flags & X86_VM_MASK) {
26812+ if (v8086_mode(regs)) {
26813 /*
26814 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26815 * On nmi (interrupt 2), do_trap should not be called.
26816@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26817 return -1;
26818 }
26819 #endif
26820- if (!user_mode(regs)) {
26821+ if (!user_mode_novm(regs)) {
26822 if (!fixup_exception(regs)) {
26823 tsk->thread.error_code = error_code;
26824 tsk->thread.trap_nr = trapnr;
26825+
26826+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26827+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26828+ str = "PAX: suspicious stack segment fault";
26829+#endif
26830+
26831 die(str, regs, error_code);
26832 }
26833+
26834+#ifdef CONFIG_PAX_REFCOUNT
26835+ if (trapnr == 4)
26836+ pax_report_refcount_overflow(regs);
26837+#endif
26838+
26839 return 0;
26840 }
26841
26842@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26843 }
26844
26845 static void __kprobes
26846-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26847+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26848 long error_code, siginfo_t *info)
26849 {
26850 struct task_struct *tsk = current;
26851@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26852 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26853 printk_ratelimit()) {
26854 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26855- tsk->comm, tsk->pid, str,
26856+ tsk->comm, task_pid_nr(tsk), str,
26857 regs->ip, regs->sp, error_code);
26858 print_vma_addr(" in ", regs->ip);
26859 pr_cont("\n");
26860@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26861 conditional_sti(regs);
26862
26863 #ifdef CONFIG_X86_32
26864- if (regs->flags & X86_VM_MASK) {
26865+ if (v8086_mode(regs)) {
26866 local_irq_enable();
26867 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26868 goto exit;
26869@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26870 #endif
26871
26872 tsk = current;
26873- if (!user_mode(regs)) {
26874+ if (!user_mode_novm(regs)) {
26875 if (fixup_exception(regs))
26876 goto exit;
26877
26878 tsk->thread.error_code = error_code;
26879 tsk->thread.trap_nr = X86_TRAP_GP;
26880 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26881- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26882+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26883+
26884+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26885+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26886+ die("PAX: suspicious general protection fault", regs, error_code);
26887+ else
26888+#endif
26889+
26890 die("general protection fault", regs, error_code);
26891+ }
26892 goto exit;
26893 }
26894
26895+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26896+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26897+ struct mm_struct *mm = tsk->mm;
26898+ unsigned long limit;
26899+
26900+ down_write(&mm->mmap_sem);
26901+ limit = mm->context.user_cs_limit;
26902+ if (limit < TASK_SIZE) {
26903+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26904+ up_write(&mm->mmap_sem);
26905+ return;
26906+ }
26907+ up_write(&mm->mmap_sem);
26908+ }
26909+#endif
26910+
26911 tsk->thread.error_code = error_code;
26912 tsk->thread.trap_nr = X86_TRAP_GP;
26913
26914@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26915 /* It's safe to allow irq's after DR6 has been saved */
26916 preempt_conditional_sti(regs);
26917
26918- if (regs->flags & X86_VM_MASK) {
26919+ if (v8086_mode(regs)) {
26920 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26921 X86_TRAP_DB);
26922 preempt_conditional_cli(regs);
26923@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26924 * We already checked v86 mode above, so we can check for kernel mode
26925 * by just checking the CPL of CS.
26926 */
26927- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26928+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26929 tsk->thread.debugreg6 &= ~DR_STEP;
26930 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26931 regs->flags &= ~X86_EFLAGS_TF;
26932@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26933 return;
26934 conditional_sti(regs);
26935
26936- if (!user_mode_vm(regs))
26937+ if (!user_mode(regs))
26938 {
26939 if (!fixup_exception(regs)) {
26940 task->thread.error_code = error_code;
26941diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26942index 2ed8459..7cf329f 100644
26943--- a/arch/x86/kernel/uprobes.c
26944+++ b/arch/x86/kernel/uprobes.c
26945@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26946 int ret = NOTIFY_DONE;
26947
26948 /* We are only interested in userspace traps */
26949- if (regs && !user_mode_vm(regs))
26950+ if (regs && !user_mode(regs))
26951 return NOTIFY_DONE;
26952
26953 switch (val) {
26954@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26955
26956 if (ncopied != rasize) {
26957 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26958- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26959+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26960
26961 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26962 }
26963diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26964index b9242ba..50c5edd 100644
26965--- a/arch/x86/kernel/verify_cpu.S
26966+++ b/arch/x86/kernel/verify_cpu.S
26967@@ -20,6 +20,7 @@
26968 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26969 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26970 * arch/x86/kernel/head_32.S: processor startup
26971+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26972 *
26973 * verify_cpu, returns the status of longmode and SSE in register %eax.
26974 * 0: Success 1: Failure
26975diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26976index e8edcf5..27f9344 100644
26977--- a/arch/x86/kernel/vm86_32.c
26978+++ b/arch/x86/kernel/vm86_32.c
26979@@ -44,6 +44,7 @@
26980 #include <linux/ptrace.h>
26981 #include <linux/audit.h>
26982 #include <linux/stddef.h>
26983+#include <linux/grsecurity.h>
26984
26985 #include <asm/uaccess.h>
26986 #include <asm/io.h>
26987@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26988 do_exit(SIGSEGV);
26989 }
26990
26991- tss = &per_cpu(init_tss, get_cpu());
26992+ tss = init_tss + get_cpu();
26993 current->thread.sp0 = current->thread.saved_sp0;
26994 current->thread.sysenter_cs = __KERNEL_CS;
26995 load_sp0(tss, &current->thread);
26996@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26997
26998 if (tsk->thread.saved_sp0)
26999 return -EPERM;
27000+
27001+#ifdef CONFIG_GRKERNSEC_VM86
27002+ if (!capable(CAP_SYS_RAWIO)) {
27003+ gr_handle_vm86();
27004+ return -EPERM;
27005+ }
27006+#endif
27007+
27008 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27009 offsetof(struct kernel_vm86_struct, vm86plus) -
27010 sizeof(info.regs));
27011@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27012 int tmp;
27013 struct vm86plus_struct __user *v86;
27014
27015+#ifdef CONFIG_GRKERNSEC_VM86
27016+ if (!capable(CAP_SYS_RAWIO)) {
27017+ gr_handle_vm86();
27018+ return -EPERM;
27019+ }
27020+#endif
27021+
27022 tsk = current;
27023 switch (cmd) {
27024 case VM86_REQUEST_IRQ:
27025@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27026 tsk->thread.saved_fs = info->regs32->fs;
27027 tsk->thread.saved_gs = get_user_gs(info->regs32);
27028
27029- tss = &per_cpu(init_tss, get_cpu());
27030+ tss = init_tss + get_cpu();
27031 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27032 if (cpu_has_sep)
27033 tsk->thread.sysenter_cs = 0;
27034@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27035 goto cannot_handle;
27036 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27037 goto cannot_handle;
27038- intr_ptr = (unsigned long __user *) (i << 2);
27039+ intr_ptr = (__force unsigned long __user *) (i << 2);
27040 if (get_user(segoffs, intr_ptr))
27041 goto cannot_handle;
27042 if ((segoffs >> 16) == BIOSSEG)
27043diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27044index da6b35a..977e9cf 100644
27045--- a/arch/x86/kernel/vmlinux.lds.S
27046+++ b/arch/x86/kernel/vmlinux.lds.S
27047@@ -26,6 +26,13 @@
27048 #include <asm/page_types.h>
27049 #include <asm/cache.h>
27050 #include <asm/boot.h>
27051+#include <asm/segment.h>
27052+
27053+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27054+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27055+#else
27056+#define __KERNEL_TEXT_OFFSET 0
27057+#endif
27058
27059 #undef i386 /* in case the preprocessor is a 32bit one */
27060
27061@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27062
27063 PHDRS {
27064 text PT_LOAD FLAGS(5); /* R_E */
27065+#ifdef CONFIG_X86_32
27066+ module PT_LOAD FLAGS(5); /* R_E */
27067+#endif
27068+#ifdef CONFIG_XEN
27069+ rodata PT_LOAD FLAGS(5); /* R_E */
27070+#else
27071+ rodata PT_LOAD FLAGS(4); /* R__ */
27072+#endif
27073 data PT_LOAD FLAGS(6); /* RW_ */
27074-#ifdef CONFIG_X86_64
27075+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27076 #ifdef CONFIG_SMP
27077 percpu PT_LOAD FLAGS(6); /* RW_ */
27078 #endif
27079+ text.init PT_LOAD FLAGS(5); /* R_E */
27080+ text.exit PT_LOAD FLAGS(5); /* R_E */
27081 init PT_LOAD FLAGS(7); /* RWE */
27082-#endif
27083 note PT_NOTE FLAGS(0); /* ___ */
27084 }
27085
27086 SECTIONS
27087 {
27088 #ifdef CONFIG_X86_32
27089- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27090- phys_startup_32 = startup_32 - LOAD_OFFSET;
27091+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27092 #else
27093- . = __START_KERNEL;
27094- phys_startup_64 = startup_64 - LOAD_OFFSET;
27095+ . = __START_KERNEL;
27096 #endif
27097
27098 /* Text and read-only data */
27099- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27100- _text = .;
27101+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27102 /* bootstrapping code */
27103+#ifdef CONFIG_X86_32
27104+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27105+#else
27106+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27107+#endif
27108+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27109+ _text = .;
27110 HEAD_TEXT
27111 . = ALIGN(8);
27112 _stext = .;
27113@@ -104,13 +124,47 @@ SECTIONS
27114 IRQENTRY_TEXT
27115 *(.fixup)
27116 *(.gnu.warning)
27117- /* End of text section */
27118- _etext = .;
27119 } :text = 0x9090
27120
27121- NOTES :text :note
27122+ . += __KERNEL_TEXT_OFFSET;
27123
27124- EXCEPTION_TABLE(16) :text = 0x9090
27125+#ifdef CONFIG_X86_32
27126+ . = ALIGN(PAGE_SIZE);
27127+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27128+
27129+#ifdef CONFIG_PAX_KERNEXEC
27130+ MODULES_EXEC_VADDR = .;
27131+ BYTE(0)
27132+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27133+ . = ALIGN(HPAGE_SIZE) - 1;
27134+ MODULES_EXEC_END = .;
27135+#endif
27136+
27137+ } :module
27138+#endif
27139+
27140+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27141+ /* End of text section */
27142+ BYTE(0)
27143+ _etext = . - __KERNEL_TEXT_OFFSET;
27144+ }
27145+
27146+#ifdef CONFIG_X86_32
27147+ . = ALIGN(PAGE_SIZE);
27148+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27149+ . = ALIGN(PAGE_SIZE);
27150+ *(.empty_zero_page)
27151+ *(.initial_pg_fixmap)
27152+ *(.initial_pg_pmd)
27153+ *(.initial_page_table)
27154+ *(.swapper_pg_dir)
27155+ } :rodata
27156+#endif
27157+
27158+ . = ALIGN(PAGE_SIZE);
27159+ NOTES :rodata :note
27160+
27161+ EXCEPTION_TABLE(16) :rodata
27162
27163 #if defined(CONFIG_DEBUG_RODATA)
27164 /* .text should occupy whole number of pages */
27165@@ -122,16 +176,20 @@ SECTIONS
27166
27167 /* Data */
27168 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27169+
27170+#ifdef CONFIG_PAX_KERNEXEC
27171+ . = ALIGN(HPAGE_SIZE);
27172+#else
27173+ . = ALIGN(PAGE_SIZE);
27174+#endif
27175+
27176 /* Start of data section */
27177 _sdata = .;
27178
27179 /* init_task */
27180 INIT_TASK_DATA(THREAD_SIZE)
27181
27182-#ifdef CONFIG_X86_32
27183- /* 32 bit has nosave before _edata */
27184 NOSAVE_DATA
27185-#endif
27186
27187 PAGE_ALIGNED_DATA(PAGE_SIZE)
27188
27189@@ -172,12 +230,19 @@ SECTIONS
27190 #endif /* CONFIG_X86_64 */
27191
27192 /* Init code and data - will be freed after init */
27193- . = ALIGN(PAGE_SIZE);
27194 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27195+ BYTE(0)
27196+
27197+#ifdef CONFIG_PAX_KERNEXEC
27198+ . = ALIGN(HPAGE_SIZE);
27199+#else
27200+ . = ALIGN(PAGE_SIZE);
27201+#endif
27202+
27203 __init_begin = .; /* paired with __init_end */
27204- }
27205+ } :init.begin
27206
27207-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27208+#ifdef CONFIG_SMP
27209 /*
27210 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27211 * output PHDR, so the next output section - .init.text - should
27212@@ -186,12 +251,27 @@ SECTIONS
27213 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27214 #endif
27215
27216- INIT_TEXT_SECTION(PAGE_SIZE)
27217-#ifdef CONFIG_X86_64
27218- :init
27219-#endif
27220+ . = ALIGN(PAGE_SIZE);
27221+ init_begin = .;
27222+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27223+ VMLINUX_SYMBOL(_sinittext) = .;
27224+ INIT_TEXT
27225+ VMLINUX_SYMBOL(_einittext) = .;
27226+ . = ALIGN(PAGE_SIZE);
27227+ } :text.init
27228
27229- INIT_DATA_SECTION(16)
27230+ /*
27231+ * .exit.text is discard at runtime, not link time, to deal with
27232+ * references from .altinstructions and .eh_frame
27233+ */
27234+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27235+ EXIT_TEXT
27236+ . = ALIGN(16);
27237+ } :text.exit
27238+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27239+
27240+ . = ALIGN(PAGE_SIZE);
27241+ INIT_DATA_SECTION(16) :init
27242
27243 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27244 __x86_cpu_dev_start = .;
27245@@ -262,19 +342,12 @@ SECTIONS
27246 }
27247
27248 . = ALIGN(8);
27249- /*
27250- * .exit.text is discard at runtime, not link time, to deal with
27251- * references from .altinstructions and .eh_frame
27252- */
27253- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27254- EXIT_TEXT
27255- }
27256
27257 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27258 EXIT_DATA
27259 }
27260
27261-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27262+#ifndef CONFIG_SMP
27263 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27264 #endif
27265
27266@@ -293,16 +366,10 @@ SECTIONS
27267 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27268 __smp_locks = .;
27269 *(.smp_locks)
27270- . = ALIGN(PAGE_SIZE);
27271 __smp_locks_end = .;
27272+ . = ALIGN(PAGE_SIZE);
27273 }
27274
27275-#ifdef CONFIG_X86_64
27276- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27277- NOSAVE_DATA
27278- }
27279-#endif
27280-
27281 /* BSS */
27282 . = ALIGN(PAGE_SIZE);
27283 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27284@@ -318,6 +385,7 @@ SECTIONS
27285 __brk_base = .;
27286 . += 64 * 1024; /* 64k alignment slop space */
27287 *(.brk_reservation) /* areas brk users have reserved */
27288+ . = ALIGN(HPAGE_SIZE);
27289 __brk_limit = .;
27290 }
27291
27292@@ -344,13 +412,12 @@ SECTIONS
27293 * for the boot processor.
27294 */
27295 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27296-INIT_PER_CPU(gdt_page);
27297 INIT_PER_CPU(irq_stack_union);
27298
27299 /*
27300 * Build-time check on the image size:
27301 */
27302-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27303+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27304 "kernel image bigger than KERNEL_IMAGE_SIZE");
27305
27306 #ifdef CONFIG_SMP
27307diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27308index 1f96f93..d5c8f7a 100644
27309--- a/arch/x86/kernel/vsyscall_64.c
27310+++ b/arch/x86/kernel/vsyscall_64.c
27311@@ -56,15 +56,13 @@
27312 DEFINE_VVAR(int, vgetcpu_mode);
27313 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27314
27315-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27316+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27317
27318 static int __init vsyscall_setup(char *str)
27319 {
27320 if (str) {
27321 if (!strcmp("emulate", str))
27322 vsyscall_mode = EMULATE;
27323- else if (!strcmp("native", str))
27324- vsyscall_mode = NATIVE;
27325 else if (!strcmp("none", str))
27326 vsyscall_mode = NONE;
27327 else
27328@@ -323,8 +321,7 @@ do_ret:
27329 return true;
27330
27331 sigsegv:
27332- force_sig(SIGSEGV, current);
27333- return true;
27334+ do_group_exit(SIGKILL);
27335 }
27336
27337 /*
27338@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27339 extern char __vvar_page;
27340 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27341
27342- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27343- vsyscall_mode == NATIVE
27344- ? PAGE_KERNEL_VSYSCALL
27345- : PAGE_KERNEL_VVAR);
27346+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27347 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27348 (unsigned long)VSYSCALL_START);
27349
27350diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27351index 04068192..4d75aa6 100644
27352--- a/arch/x86/kernel/x8664_ksyms_64.c
27353+++ b/arch/x86/kernel/x8664_ksyms_64.c
27354@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27355 EXPORT_SYMBOL(copy_user_generic_unrolled);
27356 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27357 EXPORT_SYMBOL(__copy_user_nocache);
27358-EXPORT_SYMBOL(_copy_from_user);
27359-EXPORT_SYMBOL(_copy_to_user);
27360
27361 EXPORT_SYMBOL(copy_page);
27362 EXPORT_SYMBOL(clear_page);
27363@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27364 EXPORT_SYMBOL(___preempt_schedule_context);
27365 #endif
27366 #endif
27367+
27368+#ifdef CONFIG_PAX_PER_CPU_PGD
27369+EXPORT_SYMBOL(cpu_pgd);
27370+#endif
27371diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27372index 021783b..6511282 100644
27373--- a/arch/x86/kernel/x86_init.c
27374+++ b/arch/x86/kernel/x86_init.c
27375@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27376 static void default_nmi_init(void) { };
27377 static int default_i8042_detect(void) { return 1; };
27378
27379-struct x86_platform_ops x86_platform = {
27380+struct x86_platform_ops x86_platform __read_only = {
27381 .calibrate_tsc = native_calibrate_tsc,
27382 .get_wallclock = mach_get_cmos_time,
27383 .set_wallclock = mach_set_rtc_mmss,
27384@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27385 EXPORT_SYMBOL_GPL(x86_platform);
27386
27387 #if defined(CONFIG_PCI_MSI)
27388-struct x86_msi_ops x86_msi = {
27389+struct x86_msi_ops x86_msi __read_only = {
27390 .setup_msi_irqs = native_setup_msi_irqs,
27391 .compose_msi_msg = native_compose_msi_msg,
27392 .teardown_msi_irq = native_teardown_msi_irq,
27393@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27394 }
27395 #endif
27396
27397-struct x86_io_apic_ops x86_io_apic_ops = {
27398+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27399 .init = native_io_apic_init_mappings,
27400 .read = native_io_apic_read,
27401 .write = native_io_apic_write,
27402diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27403index 422fd82..b2d262e 100644
27404--- a/arch/x86/kernel/xsave.c
27405+++ b/arch/x86/kernel/xsave.c
27406@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27407
27408 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27409 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27410- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27411+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27412
27413 if (!use_xsave())
27414 return err;
27415
27416- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27417+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27418
27419 /*
27420 * Read the xstate_bv which we copied (directly from the cpu or
27421 * from the state in task struct) to the user buffers.
27422 */
27423- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27424+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27425
27426 /*
27427 * For legacy compatible, we always set FP/SSE bits in the bit
27428@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27429 */
27430 xstate_bv |= XSTATE_FPSSE;
27431
27432- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27433+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27434
27435 return err;
27436 }
27437@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27438 {
27439 int err;
27440
27441+ buf = (struct xsave_struct __user *)____m(buf);
27442 if (use_xsave())
27443 err = xsave_user(buf);
27444 else if (use_fxsr())
27445@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27446 */
27447 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27448 {
27449+ buf = (void __user *)____m(buf);
27450 if (use_xsave()) {
27451 if ((unsigned long)buf % 64 || fx_only) {
27452 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27453diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27454index c697625..a032162 100644
27455--- a/arch/x86/kvm/cpuid.c
27456+++ b/arch/x86/kvm/cpuid.c
27457@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27458 struct kvm_cpuid2 *cpuid,
27459 struct kvm_cpuid_entry2 __user *entries)
27460 {
27461- int r;
27462+ int r, i;
27463
27464 r = -E2BIG;
27465 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27466 goto out;
27467 r = -EFAULT;
27468- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27469- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27470+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27471 goto out;
27472+ for (i = 0; i < cpuid->nent; ++i) {
27473+ struct kvm_cpuid_entry2 cpuid_entry;
27474+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
27475+ goto out;
27476+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
27477+ }
27478 vcpu->arch.cpuid_nent = cpuid->nent;
27479 kvm_apic_set_version(vcpu);
27480 kvm_x86_ops->cpuid_update(vcpu);
27481@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
27482 struct kvm_cpuid2 *cpuid,
27483 struct kvm_cpuid_entry2 __user *entries)
27484 {
27485- int r;
27486+ int r, i;
27487
27488 r = -E2BIG;
27489 if (cpuid->nent < vcpu->arch.cpuid_nent)
27490 goto out;
27491 r = -EFAULT;
27492- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
27493- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27494+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27495 goto out;
27496+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
27497+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
27498+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
27499+ goto out;
27500+ }
27501 return 0;
27502
27503 out:
27504diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
27505index 775702f..737d4a9 100644
27506--- a/arch/x86/kvm/lapic.c
27507+++ b/arch/x86/kvm/lapic.c
27508@@ -55,7 +55,7 @@
27509 #define APIC_BUS_CYCLE_NS 1
27510
27511 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
27512-#define apic_debug(fmt, arg...)
27513+#define apic_debug(fmt, arg...) do {} while (0)
27514
27515 #define APIC_LVT_NUM 6
27516 /* 14 is the version for Xeon and Pentium 8.4.8*/
27517diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
27518index ad75d77..a679d32 100644
27519--- a/arch/x86/kvm/paging_tmpl.h
27520+++ b/arch/x86/kvm/paging_tmpl.h
27521@@ -331,7 +331,7 @@ retry_walk:
27522 if (unlikely(kvm_is_error_hva(host_addr)))
27523 goto error;
27524
27525- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
27526+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
27527 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
27528 goto error;
27529 walker->ptep_user[walker->level - 1] = ptep_user;
27530diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
27531index c7168a5..09070fc 100644
27532--- a/arch/x86/kvm/svm.c
27533+++ b/arch/x86/kvm/svm.c
27534@@ -3497,7 +3497,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
27535 int cpu = raw_smp_processor_id();
27536
27537 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
27538+
27539+ pax_open_kernel();
27540 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
27541+ pax_close_kernel();
27542+
27543 load_TR_desc();
27544 }
27545
27546@@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
27547 #endif
27548 #endif
27549
27550+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27551+ __set_fs(current_thread_info()->addr_limit);
27552+#endif
27553+
27554 reload_tss(vcpu);
27555
27556 local_irq_disable();
27557diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
27558index da7837e..86c6ebf 100644
27559--- a/arch/x86/kvm/vmx.c
27560+++ b/arch/x86/kvm/vmx.c
27561@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
27562 #endif
27563 }
27564
27565-static void vmcs_clear_bits(unsigned long field, u32 mask)
27566+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
27567 {
27568 vmcs_writel(field, vmcs_readl(field) & ~mask);
27569 }
27570
27571-static void vmcs_set_bits(unsigned long field, u32 mask)
27572+static void vmcs_set_bits(unsigned long field, unsigned long mask)
27573 {
27574 vmcs_writel(field, vmcs_readl(field) | mask);
27575 }
27576@@ -1522,7 +1522,11 @@ static void reload_tss(void)
27577 struct desc_struct *descs;
27578
27579 descs = (void *)gdt->address;
27580+
27581+ pax_open_kernel();
27582 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27583+ pax_close_kernel();
27584+
27585 load_TR_desc();
27586 }
27587
27588@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27589 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27590 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27591
27592+#ifdef CONFIG_PAX_PER_CPU_PGD
27593+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27594+#endif
27595+
27596 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27597 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27598 vmx->loaded_vmcs->cpu = cpu;
27599@@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
27600 * reads and returns guest's timestamp counter "register"
27601 * guest_tsc = host_tsc + tsc_offset -- 21.3
27602 */
27603-static u64 guest_read_tsc(void)
27604+static u64 __intentional_overflow(-1) guest_read_tsc(void)
27605 {
27606 u64 host_tsc, tsc_offset;
27607
27608@@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
27609 if (!cpu_has_vmx_flexpriority())
27610 flexpriority_enabled = 0;
27611
27612- if (!cpu_has_vmx_tpr_shadow())
27613- kvm_x86_ops->update_cr8_intercept = NULL;
27614+ if (!cpu_has_vmx_tpr_shadow()) {
27615+ pax_open_kernel();
27616+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27617+ pax_close_kernel();
27618+ }
27619
27620 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27621 kvm_disable_largepages();
27622@@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
27623 if (!cpu_has_vmx_apicv())
27624 enable_apicv = 0;
27625
27626+ pax_open_kernel();
27627 if (enable_apicv)
27628- kvm_x86_ops->update_cr8_intercept = NULL;
27629+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27630 else {
27631- kvm_x86_ops->hwapic_irr_update = NULL;
27632- kvm_x86_ops->deliver_posted_interrupt = NULL;
27633- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27634+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27635+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27636+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27637 }
27638+ pax_close_kernel();
27639
27640 if (nested)
27641 nested_vmx_setup_ctls_msrs();
27642@@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27643
27644 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27645 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27646+
27647+#ifndef CONFIG_PAX_PER_CPU_PGD
27648 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27649+#endif
27650
27651 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27652 #ifdef CONFIG_X86_64
27653@@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27654 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27655 vmx->host_idt_base = dt.address;
27656
27657- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27658+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27659
27660 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27661 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27662@@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27663 "jmp 2f \n\t"
27664 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27665 "2: "
27666+
27667+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27668+ "ljmp %[cs],$3f\n\t"
27669+ "3: "
27670+#endif
27671+
27672 /* Save guest registers, load host registers, keep flags */
27673 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27674 "pop %0 \n\t"
27675@@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27676 #endif
27677 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27678 [wordsize]"i"(sizeof(ulong))
27679+
27680+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27681+ ,[cs]"i"(__KERNEL_CS)
27682+#endif
27683+
27684 : "cc", "memory"
27685 #ifdef CONFIG_X86_64
27686 , "rax", "rbx", "rdi", "rsi"
27687@@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27688 if (debugctlmsr)
27689 update_debugctlmsr(debugctlmsr);
27690
27691-#ifndef CONFIG_X86_64
27692+#ifdef CONFIG_X86_32
27693 /*
27694 * The sysexit path does not restore ds/es, so we must set them to
27695 * a reasonable value ourselves.
27696@@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27697 * may be executed in interrupt context, which saves and restore segments
27698 * around it, nullifying its effect.
27699 */
27700- loadsegment(ds, __USER_DS);
27701- loadsegment(es, __USER_DS);
27702+ loadsegment(ds, __KERNEL_DS);
27703+ loadsegment(es, __KERNEL_DS);
27704+ loadsegment(ss, __KERNEL_DS);
27705+
27706+#ifdef CONFIG_PAX_KERNEXEC
27707+ loadsegment(fs, __KERNEL_PERCPU);
27708+#endif
27709+
27710+#ifdef CONFIG_PAX_MEMORY_UDEREF
27711+ __set_fs(current_thread_info()->addr_limit);
27712+#endif
27713+
27714 #endif
27715
27716 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27717diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27718index 5d004da..0802480 100644
27719--- a/arch/x86/kvm/x86.c
27720+++ b/arch/x86/kvm/x86.c
27721@@ -1788,8 +1788,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27722 {
27723 struct kvm *kvm = vcpu->kvm;
27724 int lm = is_long_mode(vcpu);
27725- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27726- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27727+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27728+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27729 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27730 : kvm->arch.xen_hvm_config.blob_size_32;
27731 u32 page_num = data & ~PAGE_MASK;
27732@@ -2673,6 +2673,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27733 if (n < msr_list.nmsrs)
27734 goto out;
27735 r = -EFAULT;
27736+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27737+ goto out;
27738 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27739 num_msrs_to_save * sizeof(u32)))
27740 goto out;
27741@@ -5482,7 +5484,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27742 };
27743 #endif
27744
27745-int kvm_arch_init(void *opaque)
27746+int kvm_arch_init(const void *opaque)
27747 {
27748 int r;
27749 struct kvm_x86_ops *ops = opaque;
27750diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27751index bdf8532..f63c587 100644
27752--- a/arch/x86/lguest/boot.c
27753+++ b/arch/x86/lguest/boot.c
27754@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27755 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27756 * Launcher to reboot us.
27757 */
27758-static void lguest_restart(char *reason)
27759+static __noreturn void lguest_restart(char *reason)
27760 {
27761 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27762+ BUG();
27763 }
27764
27765 /*G:050
27766diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27767index 00933d5..3a64af9 100644
27768--- a/arch/x86/lib/atomic64_386_32.S
27769+++ b/arch/x86/lib/atomic64_386_32.S
27770@@ -48,6 +48,10 @@ BEGIN(read)
27771 movl (v), %eax
27772 movl 4(v), %edx
27773 RET_ENDP
27774+BEGIN(read_unchecked)
27775+ movl (v), %eax
27776+ movl 4(v), %edx
27777+RET_ENDP
27778 #undef v
27779
27780 #define v %esi
27781@@ -55,6 +59,10 @@ BEGIN(set)
27782 movl %ebx, (v)
27783 movl %ecx, 4(v)
27784 RET_ENDP
27785+BEGIN(set_unchecked)
27786+ movl %ebx, (v)
27787+ movl %ecx, 4(v)
27788+RET_ENDP
27789 #undef v
27790
27791 #define v %esi
27792@@ -70,6 +78,20 @@ RET_ENDP
27793 BEGIN(add)
27794 addl %eax, (v)
27795 adcl %edx, 4(v)
27796+
27797+#ifdef CONFIG_PAX_REFCOUNT
27798+ jno 0f
27799+ subl %eax, (v)
27800+ sbbl %edx, 4(v)
27801+ int $4
27802+0:
27803+ _ASM_EXTABLE(0b, 0b)
27804+#endif
27805+
27806+RET_ENDP
27807+BEGIN(add_unchecked)
27808+ addl %eax, (v)
27809+ adcl %edx, 4(v)
27810 RET_ENDP
27811 #undef v
27812
27813@@ -77,6 +99,24 @@ RET_ENDP
27814 BEGIN(add_return)
27815 addl (v), %eax
27816 adcl 4(v), %edx
27817+
27818+#ifdef CONFIG_PAX_REFCOUNT
27819+ into
27820+1234:
27821+ _ASM_EXTABLE(1234b, 2f)
27822+#endif
27823+
27824+ movl %eax, (v)
27825+ movl %edx, 4(v)
27826+
27827+#ifdef CONFIG_PAX_REFCOUNT
27828+2:
27829+#endif
27830+
27831+RET_ENDP
27832+BEGIN(add_return_unchecked)
27833+ addl (v), %eax
27834+ adcl 4(v), %edx
27835 movl %eax, (v)
27836 movl %edx, 4(v)
27837 RET_ENDP
27838@@ -86,6 +126,20 @@ RET_ENDP
27839 BEGIN(sub)
27840 subl %eax, (v)
27841 sbbl %edx, 4(v)
27842+
27843+#ifdef CONFIG_PAX_REFCOUNT
27844+ jno 0f
27845+ addl %eax, (v)
27846+ adcl %edx, 4(v)
27847+ int $4
27848+0:
27849+ _ASM_EXTABLE(0b, 0b)
27850+#endif
27851+
27852+RET_ENDP
27853+BEGIN(sub_unchecked)
27854+ subl %eax, (v)
27855+ sbbl %edx, 4(v)
27856 RET_ENDP
27857 #undef v
27858
27859@@ -96,6 +150,27 @@ BEGIN(sub_return)
27860 sbbl $0, %edx
27861 addl (v), %eax
27862 adcl 4(v), %edx
27863+
27864+#ifdef CONFIG_PAX_REFCOUNT
27865+ into
27866+1234:
27867+ _ASM_EXTABLE(1234b, 2f)
27868+#endif
27869+
27870+ movl %eax, (v)
27871+ movl %edx, 4(v)
27872+
27873+#ifdef CONFIG_PAX_REFCOUNT
27874+2:
27875+#endif
27876+
27877+RET_ENDP
27878+BEGIN(sub_return_unchecked)
27879+ negl %edx
27880+ negl %eax
27881+ sbbl $0, %edx
27882+ addl (v), %eax
27883+ adcl 4(v), %edx
27884 movl %eax, (v)
27885 movl %edx, 4(v)
27886 RET_ENDP
27887@@ -105,6 +180,20 @@ RET_ENDP
27888 BEGIN(inc)
27889 addl $1, (v)
27890 adcl $0, 4(v)
27891+
27892+#ifdef CONFIG_PAX_REFCOUNT
27893+ jno 0f
27894+ subl $1, (v)
27895+ sbbl $0, 4(v)
27896+ int $4
27897+0:
27898+ _ASM_EXTABLE(0b, 0b)
27899+#endif
27900+
27901+RET_ENDP
27902+BEGIN(inc_unchecked)
27903+ addl $1, (v)
27904+ adcl $0, 4(v)
27905 RET_ENDP
27906 #undef v
27907
27908@@ -114,6 +203,26 @@ BEGIN(inc_return)
27909 movl 4(v), %edx
27910 addl $1, %eax
27911 adcl $0, %edx
27912+
27913+#ifdef CONFIG_PAX_REFCOUNT
27914+ into
27915+1234:
27916+ _ASM_EXTABLE(1234b, 2f)
27917+#endif
27918+
27919+ movl %eax, (v)
27920+ movl %edx, 4(v)
27921+
27922+#ifdef CONFIG_PAX_REFCOUNT
27923+2:
27924+#endif
27925+
27926+RET_ENDP
27927+BEGIN(inc_return_unchecked)
27928+ movl (v), %eax
27929+ movl 4(v), %edx
27930+ addl $1, %eax
27931+ adcl $0, %edx
27932 movl %eax, (v)
27933 movl %edx, 4(v)
27934 RET_ENDP
27935@@ -123,6 +232,20 @@ RET_ENDP
27936 BEGIN(dec)
27937 subl $1, (v)
27938 sbbl $0, 4(v)
27939+
27940+#ifdef CONFIG_PAX_REFCOUNT
27941+ jno 0f
27942+ addl $1, (v)
27943+ adcl $0, 4(v)
27944+ int $4
27945+0:
27946+ _ASM_EXTABLE(0b, 0b)
27947+#endif
27948+
27949+RET_ENDP
27950+BEGIN(dec_unchecked)
27951+ subl $1, (v)
27952+ sbbl $0, 4(v)
27953 RET_ENDP
27954 #undef v
27955
27956@@ -132,6 +255,26 @@ BEGIN(dec_return)
27957 movl 4(v), %edx
27958 subl $1, %eax
27959 sbbl $0, %edx
27960+
27961+#ifdef CONFIG_PAX_REFCOUNT
27962+ into
27963+1234:
27964+ _ASM_EXTABLE(1234b, 2f)
27965+#endif
27966+
27967+ movl %eax, (v)
27968+ movl %edx, 4(v)
27969+
27970+#ifdef CONFIG_PAX_REFCOUNT
27971+2:
27972+#endif
27973+
27974+RET_ENDP
27975+BEGIN(dec_return_unchecked)
27976+ movl (v), %eax
27977+ movl 4(v), %edx
27978+ subl $1, %eax
27979+ sbbl $0, %edx
27980 movl %eax, (v)
27981 movl %edx, 4(v)
27982 RET_ENDP
27983@@ -143,6 +286,13 @@ BEGIN(add_unless)
27984 adcl %edx, %edi
27985 addl (v), %eax
27986 adcl 4(v), %edx
27987+
27988+#ifdef CONFIG_PAX_REFCOUNT
27989+ into
27990+1234:
27991+ _ASM_EXTABLE(1234b, 2f)
27992+#endif
27993+
27994 cmpl %eax, %ecx
27995 je 3f
27996 1:
27997@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27998 1:
27999 addl $1, %eax
28000 adcl $0, %edx
28001+
28002+#ifdef CONFIG_PAX_REFCOUNT
28003+ into
28004+1234:
28005+ _ASM_EXTABLE(1234b, 2f)
28006+#endif
28007+
28008 movl %eax, (v)
28009 movl %edx, 4(v)
28010 movl $1, %eax
28011@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28012 movl 4(v), %edx
28013 subl $1, %eax
28014 sbbl $0, %edx
28015+
28016+#ifdef CONFIG_PAX_REFCOUNT
28017+ into
28018+1234:
28019+ _ASM_EXTABLE(1234b, 1f)
28020+#endif
28021+
28022 js 1f
28023 movl %eax, (v)
28024 movl %edx, 4(v)
28025diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28026index f5cc9eb..51fa319 100644
28027--- a/arch/x86/lib/atomic64_cx8_32.S
28028+++ b/arch/x86/lib/atomic64_cx8_32.S
28029@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28030 CFI_STARTPROC
28031
28032 read64 %ecx
28033+ pax_force_retaddr
28034 ret
28035 CFI_ENDPROC
28036 ENDPROC(atomic64_read_cx8)
28037
28038+ENTRY(atomic64_read_unchecked_cx8)
28039+ CFI_STARTPROC
28040+
28041+ read64 %ecx
28042+ pax_force_retaddr
28043+ ret
28044+ CFI_ENDPROC
28045+ENDPROC(atomic64_read_unchecked_cx8)
28046+
28047 ENTRY(atomic64_set_cx8)
28048 CFI_STARTPROC
28049
28050@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28051 cmpxchg8b (%esi)
28052 jne 1b
28053
28054+ pax_force_retaddr
28055 ret
28056 CFI_ENDPROC
28057 ENDPROC(atomic64_set_cx8)
28058
28059+ENTRY(atomic64_set_unchecked_cx8)
28060+ CFI_STARTPROC
28061+
28062+1:
28063+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28064+ * are atomic on 586 and newer */
28065+ cmpxchg8b (%esi)
28066+ jne 1b
28067+
28068+ pax_force_retaddr
28069+ ret
28070+ CFI_ENDPROC
28071+ENDPROC(atomic64_set_unchecked_cx8)
28072+
28073 ENTRY(atomic64_xchg_cx8)
28074 CFI_STARTPROC
28075
28076@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28077 cmpxchg8b (%esi)
28078 jne 1b
28079
28080+ pax_force_retaddr
28081 ret
28082 CFI_ENDPROC
28083 ENDPROC(atomic64_xchg_cx8)
28084
28085-.macro addsub_return func ins insc
28086-ENTRY(atomic64_\func\()_return_cx8)
28087+.macro addsub_return func ins insc unchecked=""
28088+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28089 CFI_STARTPROC
28090 SAVE ebp
28091 SAVE ebx
28092@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28093 movl %edx, %ecx
28094 \ins\()l %esi, %ebx
28095 \insc\()l %edi, %ecx
28096+
28097+.ifb \unchecked
28098+#ifdef CONFIG_PAX_REFCOUNT
28099+ into
28100+2:
28101+ _ASM_EXTABLE(2b, 3f)
28102+#endif
28103+.endif
28104+
28105 LOCK_PREFIX
28106 cmpxchg8b (%ebp)
28107 jne 1b
28108-
28109-10:
28110 movl %ebx, %eax
28111 movl %ecx, %edx
28112+
28113+.ifb \unchecked
28114+#ifdef CONFIG_PAX_REFCOUNT
28115+3:
28116+#endif
28117+.endif
28118+
28119 RESTORE edi
28120 RESTORE esi
28121 RESTORE ebx
28122 RESTORE ebp
28123+ pax_force_retaddr
28124 ret
28125 CFI_ENDPROC
28126-ENDPROC(atomic64_\func\()_return_cx8)
28127+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28128 .endm
28129
28130 addsub_return add add adc
28131 addsub_return sub sub sbb
28132+addsub_return add add adc _unchecked
28133+addsub_return sub sub sbb _unchecked
28134
28135-.macro incdec_return func ins insc
28136-ENTRY(atomic64_\func\()_return_cx8)
28137+.macro incdec_return func ins insc unchecked=""
28138+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28139 CFI_STARTPROC
28140 SAVE ebx
28141
28142@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28143 movl %edx, %ecx
28144 \ins\()l $1, %ebx
28145 \insc\()l $0, %ecx
28146+
28147+.ifb \unchecked
28148+#ifdef CONFIG_PAX_REFCOUNT
28149+ into
28150+2:
28151+ _ASM_EXTABLE(2b, 3f)
28152+#endif
28153+.endif
28154+
28155 LOCK_PREFIX
28156 cmpxchg8b (%esi)
28157 jne 1b
28158
28159-10:
28160 movl %ebx, %eax
28161 movl %ecx, %edx
28162+
28163+.ifb \unchecked
28164+#ifdef CONFIG_PAX_REFCOUNT
28165+3:
28166+#endif
28167+.endif
28168+
28169 RESTORE ebx
28170+ pax_force_retaddr
28171 ret
28172 CFI_ENDPROC
28173-ENDPROC(atomic64_\func\()_return_cx8)
28174+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28175 .endm
28176
28177 incdec_return inc add adc
28178 incdec_return dec sub sbb
28179+incdec_return inc add adc _unchecked
28180+incdec_return dec sub sbb _unchecked
28181
28182 ENTRY(atomic64_dec_if_positive_cx8)
28183 CFI_STARTPROC
28184@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28185 movl %edx, %ecx
28186 subl $1, %ebx
28187 sbb $0, %ecx
28188+
28189+#ifdef CONFIG_PAX_REFCOUNT
28190+ into
28191+1234:
28192+ _ASM_EXTABLE(1234b, 2f)
28193+#endif
28194+
28195 js 2f
28196 LOCK_PREFIX
28197 cmpxchg8b (%esi)
28198@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28199 movl %ebx, %eax
28200 movl %ecx, %edx
28201 RESTORE ebx
28202+ pax_force_retaddr
28203 ret
28204 CFI_ENDPROC
28205 ENDPROC(atomic64_dec_if_positive_cx8)
28206@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28207 movl %edx, %ecx
28208 addl %ebp, %ebx
28209 adcl %edi, %ecx
28210+
28211+#ifdef CONFIG_PAX_REFCOUNT
28212+ into
28213+1234:
28214+ _ASM_EXTABLE(1234b, 3f)
28215+#endif
28216+
28217 LOCK_PREFIX
28218 cmpxchg8b (%esi)
28219 jne 1b
28220@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28221 CFI_ADJUST_CFA_OFFSET -8
28222 RESTORE ebx
28223 RESTORE ebp
28224+ pax_force_retaddr
28225 ret
28226 4:
28227 cmpl %edx, 4(%esp)
28228@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28229 xorl %ecx, %ecx
28230 addl $1, %ebx
28231 adcl %edx, %ecx
28232+
28233+#ifdef CONFIG_PAX_REFCOUNT
28234+ into
28235+1234:
28236+ _ASM_EXTABLE(1234b, 3f)
28237+#endif
28238+
28239 LOCK_PREFIX
28240 cmpxchg8b (%esi)
28241 jne 1b
28242@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28243 movl $1, %eax
28244 3:
28245 RESTORE ebx
28246+ pax_force_retaddr
28247 ret
28248 CFI_ENDPROC
28249 ENDPROC(atomic64_inc_not_zero_cx8)
28250diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28251index e78b8ee..7e173a8 100644
28252--- a/arch/x86/lib/checksum_32.S
28253+++ b/arch/x86/lib/checksum_32.S
28254@@ -29,7 +29,8 @@
28255 #include <asm/dwarf2.h>
28256 #include <asm/errno.h>
28257 #include <asm/asm.h>
28258-
28259+#include <asm/segment.h>
28260+
28261 /*
28262 * computes a partial checksum, e.g. for TCP/UDP fragments
28263 */
28264@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28265
28266 #define ARGBASE 16
28267 #define FP 12
28268-
28269-ENTRY(csum_partial_copy_generic)
28270+
28271+ENTRY(csum_partial_copy_generic_to_user)
28272 CFI_STARTPROC
28273+
28274+#ifdef CONFIG_PAX_MEMORY_UDEREF
28275+ pushl_cfi %gs
28276+ popl_cfi %es
28277+ jmp csum_partial_copy_generic
28278+#endif
28279+
28280+ENTRY(csum_partial_copy_generic_from_user)
28281+
28282+#ifdef CONFIG_PAX_MEMORY_UDEREF
28283+ pushl_cfi %gs
28284+ popl_cfi %ds
28285+#endif
28286+
28287+ENTRY(csum_partial_copy_generic)
28288 subl $4,%esp
28289 CFI_ADJUST_CFA_OFFSET 4
28290 pushl_cfi %edi
28291@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28292 jmp 4f
28293 SRC(1: movw (%esi), %bx )
28294 addl $2, %esi
28295-DST( movw %bx, (%edi) )
28296+DST( movw %bx, %es:(%edi) )
28297 addl $2, %edi
28298 addw %bx, %ax
28299 adcl $0, %eax
28300@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28301 SRC(1: movl (%esi), %ebx )
28302 SRC( movl 4(%esi), %edx )
28303 adcl %ebx, %eax
28304-DST( movl %ebx, (%edi) )
28305+DST( movl %ebx, %es:(%edi) )
28306 adcl %edx, %eax
28307-DST( movl %edx, 4(%edi) )
28308+DST( movl %edx, %es:4(%edi) )
28309
28310 SRC( movl 8(%esi), %ebx )
28311 SRC( movl 12(%esi), %edx )
28312 adcl %ebx, %eax
28313-DST( movl %ebx, 8(%edi) )
28314+DST( movl %ebx, %es:8(%edi) )
28315 adcl %edx, %eax
28316-DST( movl %edx, 12(%edi) )
28317+DST( movl %edx, %es:12(%edi) )
28318
28319 SRC( movl 16(%esi), %ebx )
28320 SRC( movl 20(%esi), %edx )
28321 adcl %ebx, %eax
28322-DST( movl %ebx, 16(%edi) )
28323+DST( movl %ebx, %es:16(%edi) )
28324 adcl %edx, %eax
28325-DST( movl %edx, 20(%edi) )
28326+DST( movl %edx, %es:20(%edi) )
28327
28328 SRC( movl 24(%esi), %ebx )
28329 SRC( movl 28(%esi), %edx )
28330 adcl %ebx, %eax
28331-DST( movl %ebx, 24(%edi) )
28332+DST( movl %ebx, %es:24(%edi) )
28333 adcl %edx, %eax
28334-DST( movl %edx, 28(%edi) )
28335+DST( movl %edx, %es:28(%edi) )
28336
28337 lea 32(%esi), %esi
28338 lea 32(%edi), %edi
28339@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28340 shrl $2, %edx # This clears CF
28341 SRC(3: movl (%esi), %ebx )
28342 adcl %ebx, %eax
28343-DST( movl %ebx, (%edi) )
28344+DST( movl %ebx, %es:(%edi) )
28345 lea 4(%esi), %esi
28346 lea 4(%edi), %edi
28347 dec %edx
28348@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28349 jb 5f
28350 SRC( movw (%esi), %cx )
28351 leal 2(%esi), %esi
28352-DST( movw %cx, (%edi) )
28353+DST( movw %cx, %es:(%edi) )
28354 leal 2(%edi), %edi
28355 je 6f
28356 shll $16,%ecx
28357 SRC(5: movb (%esi), %cl )
28358-DST( movb %cl, (%edi) )
28359+DST( movb %cl, %es:(%edi) )
28360 6: addl %ecx, %eax
28361 adcl $0, %eax
28362 7:
28363@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28364
28365 6001:
28366 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28367- movl $-EFAULT, (%ebx)
28368+ movl $-EFAULT, %ss:(%ebx)
28369
28370 # zero the complete destination - computing the rest
28371 # is too much work
28372@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28373
28374 6002:
28375 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28376- movl $-EFAULT,(%ebx)
28377+ movl $-EFAULT,%ss:(%ebx)
28378 jmp 5000b
28379
28380 .previous
28381
28382+ pushl_cfi %ss
28383+ popl_cfi %ds
28384+ pushl_cfi %ss
28385+ popl_cfi %es
28386 popl_cfi %ebx
28387 CFI_RESTORE ebx
28388 popl_cfi %esi
28389@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28390 popl_cfi %ecx # equivalent to addl $4,%esp
28391 ret
28392 CFI_ENDPROC
28393-ENDPROC(csum_partial_copy_generic)
28394+ENDPROC(csum_partial_copy_generic_to_user)
28395
28396 #else
28397
28398 /* Version for PentiumII/PPro */
28399
28400 #define ROUND1(x) \
28401+ nop; nop; nop; \
28402 SRC(movl x(%esi), %ebx ) ; \
28403 addl %ebx, %eax ; \
28404- DST(movl %ebx, x(%edi) ) ;
28405+ DST(movl %ebx, %es:x(%edi)) ;
28406
28407 #define ROUND(x) \
28408+ nop; nop; nop; \
28409 SRC(movl x(%esi), %ebx ) ; \
28410 adcl %ebx, %eax ; \
28411- DST(movl %ebx, x(%edi) ) ;
28412+ DST(movl %ebx, %es:x(%edi)) ;
28413
28414 #define ARGBASE 12
28415-
28416-ENTRY(csum_partial_copy_generic)
28417+
28418+ENTRY(csum_partial_copy_generic_to_user)
28419 CFI_STARTPROC
28420+
28421+#ifdef CONFIG_PAX_MEMORY_UDEREF
28422+ pushl_cfi %gs
28423+ popl_cfi %es
28424+ jmp csum_partial_copy_generic
28425+#endif
28426+
28427+ENTRY(csum_partial_copy_generic_from_user)
28428+
28429+#ifdef CONFIG_PAX_MEMORY_UDEREF
28430+ pushl_cfi %gs
28431+ popl_cfi %ds
28432+#endif
28433+
28434+ENTRY(csum_partial_copy_generic)
28435 pushl_cfi %ebx
28436 CFI_REL_OFFSET ebx, 0
28437 pushl_cfi %edi
28438@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28439 subl %ebx, %edi
28440 lea -1(%esi),%edx
28441 andl $-32,%edx
28442- lea 3f(%ebx,%ebx), %ebx
28443+ lea 3f(%ebx,%ebx,2), %ebx
28444 testl %esi, %esi
28445 jmp *%ebx
28446 1: addl $64,%esi
28447@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28448 jb 5f
28449 SRC( movw (%esi), %dx )
28450 leal 2(%esi), %esi
28451-DST( movw %dx, (%edi) )
28452+DST( movw %dx, %es:(%edi) )
28453 leal 2(%edi), %edi
28454 je 6f
28455 shll $16,%edx
28456 5:
28457 SRC( movb (%esi), %dl )
28458-DST( movb %dl, (%edi) )
28459+DST( movb %dl, %es:(%edi) )
28460 6: addl %edx, %eax
28461 adcl $0, %eax
28462 7:
28463 .section .fixup, "ax"
28464 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28465- movl $-EFAULT, (%ebx)
28466+ movl $-EFAULT, %ss:(%ebx)
28467 # zero the complete destination (computing the rest is too much work)
28468 movl ARGBASE+8(%esp),%edi # dst
28469 movl ARGBASE+12(%esp),%ecx # len
28470@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
28471 rep; stosb
28472 jmp 7b
28473 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28474- movl $-EFAULT, (%ebx)
28475+ movl $-EFAULT, %ss:(%ebx)
28476 jmp 7b
28477 .previous
28478
28479+#ifdef CONFIG_PAX_MEMORY_UDEREF
28480+ pushl_cfi %ss
28481+ popl_cfi %ds
28482+ pushl_cfi %ss
28483+ popl_cfi %es
28484+#endif
28485+
28486 popl_cfi %esi
28487 CFI_RESTORE esi
28488 popl_cfi %edi
28489@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
28490 CFI_RESTORE ebx
28491 ret
28492 CFI_ENDPROC
28493-ENDPROC(csum_partial_copy_generic)
28494+ENDPROC(csum_partial_copy_generic_to_user)
28495
28496 #undef ROUND
28497 #undef ROUND1
28498diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
28499index f2145cf..cea889d 100644
28500--- a/arch/x86/lib/clear_page_64.S
28501+++ b/arch/x86/lib/clear_page_64.S
28502@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
28503 movl $4096/8,%ecx
28504 xorl %eax,%eax
28505 rep stosq
28506+ pax_force_retaddr
28507 ret
28508 CFI_ENDPROC
28509 ENDPROC(clear_page_c)
28510@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
28511 movl $4096,%ecx
28512 xorl %eax,%eax
28513 rep stosb
28514+ pax_force_retaddr
28515 ret
28516 CFI_ENDPROC
28517 ENDPROC(clear_page_c_e)
28518@@ -43,6 +45,7 @@ ENTRY(clear_page)
28519 leaq 64(%rdi),%rdi
28520 jnz .Lloop
28521 nop
28522+ pax_force_retaddr
28523 ret
28524 CFI_ENDPROC
28525 .Lclear_page_end:
28526@@ -58,7 +61,7 @@ ENDPROC(clear_page)
28527
28528 #include <asm/cpufeature.h>
28529
28530- .section .altinstr_replacement,"ax"
28531+ .section .altinstr_replacement,"a"
28532 1: .byte 0xeb /* jmp <disp8> */
28533 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
28534 2: .byte 0xeb /* jmp <disp8> */
28535diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
28536index 1e572c5..2a162cd 100644
28537--- a/arch/x86/lib/cmpxchg16b_emu.S
28538+++ b/arch/x86/lib/cmpxchg16b_emu.S
28539@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
28540
28541 popf
28542 mov $1, %al
28543+ pax_force_retaddr
28544 ret
28545
28546 not_same:
28547 popf
28548 xor %al,%al
28549+ pax_force_retaddr
28550 ret
28551
28552 CFI_ENDPROC
28553diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
28554index 176cca6..e0d658e 100644
28555--- a/arch/x86/lib/copy_page_64.S
28556+++ b/arch/x86/lib/copy_page_64.S
28557@@ -9,6 +9,7 @@ copy_page_rep:
28558 CFI_STARTPROC
28559 movl $4096/8, %ecx
28560 rep movsq
28561+ pax_force_retaddr
28562 ret
28563 CFI_ENDPROC
28564 ENDPROC(copy_page_rep)
28565@@ -24,8 +25,8 @@ ENTRY(copy_page)
28566 CFI_ADJUST_CFA_OFFSET 2*8
28567 movq %rbx, (%rsp)
28568 CFI_REL_OFFSET rbx, 0
28569- movq %r12, 1*8(%rsp)
28570- CFI_REL_OFFSET r12, 1*8
28571+ movq %r13, 1*8(%rsp)
28572+ CFI_REL_OFFSET r13, 1*8
28573
28574 movl $(4096/64)-5, %ecx
28575 .p2align 4
28576@@ -38,7 +39,7 @@ ENTRY(copy_page)
28577 movq 0x8*4(%rsi), %r9
28578 movq 0x8*5(%rsi), %r10
28579 movq 0x8*6(%rsi), %r11
28580- movq 0x8*7(%rsi), %r12
28581+ movq 0x8*7(%rsi), %r13
28582
28583 prefetcht0 5*64(%rsi)
28584
28585@@ -49,7 +50,7 @@ ENTRY(copy_page)
28586 movq %r9, 0x8*4(%rdi)
28587 movq %r10, 0x8*5(%rdi)
28588 movq %r11, 0x8*6(%rdi)
28589- movq %r12, 0x8*7(%rdi)
28590+ movq %r13, 0x8*7(%rdi)
28591
28592 leaq 64 (%rsi), %rsi
28593 leaq 64 (%rdi), %rdi
28594@@ -68,7 +69,7 @@ ENTRY(copy_page)
28595 movq 0x8*4(%rsi), %r9
28596 movq 0x8*5(%rsi), %r10
28597 movq 0x8*6(%rsi), %r11
28598- movq 0x8*7(%rsi), %r12
28599+ movq 0x8*7(%rsi), %r13
28600
28601 movq %rax, 0x8*0(%rdi)
28602 movq %rbx, 0x8*1(%rdi)
28603@@ -77,7 +78,7 @@ ENTRY(copy_page)
28604 movq %r9, 0x8*4(%rdi)
28605 movq %r10, 0x8*5(%rdi)
28606 movq %r11, 0x8*6(%rdi)
28607- movq %r12, 0x8*7(%rdi)
28608+ movq %r13, 0x8*7(%rdi)
28609
28610 leaq 64(%rdi), %rdi
28611 leaq 64(%rsi), %rsi
28612@@ -85,10 +86,11 @@ ENTRY(copy_page)
28613
28614 movq (%rsp), %rbx
28615 CFI_RESTORE rbx
28616- movq 1*8(%rsp), %r12
28617- CFI_RESTORE r12
28618+ movq 1*8(%rsp), %r13
28619+ CFI_RESTORE r13
28620 addq $2*8, %rsp
28621 CFI_ADJUST_CFA_OFFSET -2*8
28622+ pax_force_retaddr
28623 ret
28624 .Lcopy_page_end:
28625 CFI_ENDPROC
28626@@ -99,7 +101,7 @@ ENDPROC(copy_page)
28627
28628 #include <asm/cpufeature.h>
28629
28630- .section .altinstr_replacement,"ax"
28631+ .section .altinstr_replacement,"a"
28632 1: .byte 0xeb /* jmp <disp8> */
28633 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28634 2:
28635diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28636index a30ca15..407412b 100644
28637--- a/arch/x86/lib/copy_user_64.S
28638+++ b/arch/x86/lib/copy_user_64.S
28639@@ -18,31 +18,7 @@
28640 #include <asm/alternative-asm.h>
28641 #include <asm/asm.h>
28642 #include <asm/smap.h>
28643-
28644-/*
28645- * By placing feature2 after feature1 in altinstructions section, we logically
28646- * implement:
28647- * If CPU has feature2, jmp to alt2 is used
28648- * else if CPU has feature1, jmp to alt1 is used
28649- * else jmp to orig is used.
28650- */
28651- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28652-0:
28653- .byte 0xe9 /* 32bit jump */
28654- .long \orig-1f /* by default jump to orig */
28655-1:
28656- .section .altinstr_replacement,"ax"
28657-2: .byte 0xe9 /* near jump with 32bit immediate */
28658- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28659-3: .byte 0xe9 /* near jump with 32bit immediate */
28660- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28661- .previous
28662-
28663- .section .altinstructions,"a"
28664- altinstruction_entry 0b,2b,\feature1,5,5
28665- altinstruction_entry 0b,3b,\feature2,5,5
28666- .previous
28667- .endm
28668+#include <asm/pgtable.h>
28669
28670 .macro ALIGN_DESTINATION
28671 #ifdef FIX_ALIGNMENT
28672@@ -70,52 +46,6 @@
28673 #endif
28674 .endm
28675
28676-/* Standard copy_to_user with segment limit checking */
28677-ENTRY(_copy_to_user)
28678- CFI_STARTPROC
28679- GET_THREAD_INFO(%rax)
28680- movq %rdi,%rcx
28681- addq %rdx,%rcx
28682- jc bad_to_user
28683- cmpq TI_addr_limit(%rax),%rcx
28684- ja bad_to_user
28685- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28686- copy_user_generic_unrolled,copy_user_generic_string, \
28687- copy_user_enhanced_fast_string
28688- CFI_ENDPROC
28689-ENDPROC(_copy_to_user)
28690-
28691-/* Standard copy_from_user with segment limit checking */
28692-ENTRY(_copy_from_user)
28693- CFI_STARTPROC
28694- GET_THREAD_INFO(%rax)
28695- movq %rsi,%rcx
28696- addq %rdx,%rcx
28697- jc bad_from_user
28698- cmpq TI_addr_limit(%rax),%rcx
28699- ja bad_from_user
28700- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28701- copy_user_generic_unrolled,copy_user_generic_string, \
28702- copy_user_enhanced_fast_string
28703- CFI_ENDPROC
28704-ENDPROC(_copy_from_user)
28705-
28706- .section .fixup,"ax"
28707- /* must zero dest */
28708-ENTRY(bad_from_user)
28709-bad_from_user:
28710- CFI_STARTPROC
28711- movl %edx,%ecx
28712- xorl %eax,%eax
28713- rep
28714- stosb
28715-bad_to_user:
28716- movl %edx,%eax
28717- ret
28718- CFI_ENDPROC
28719-ENDPROC(bad_from_user)
28720- .previous
28721-
28722 /*
28723 * copy_user_generic_unrolled - memory copy with exception handling.
28724 * This version is for CPUs like P4 that don't have efficient micro
28725@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28726 */
28727 ENTRY(copy_user_generic_unrolled)
28728 CFI_STARTPROC
28729+ ASM_PAX_OPEN_USERLAND
28730 ASM_STAC
28731 cmpl $8,%edx
28732 jb 20f /* less then 8 bytes, go to byte copy loop */
28733@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28734 jnz 21b
28735 23: xor %eax,%eax
28736 ASM_CLAC
28737+ ASM_PAX_CLOSE_USERLAND
28738+ pax_force_retaddr
28739 ret
28740
28741 .section .fixup,"ax"
28742@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28743 */
28744 ENTRY(copy_user_generic_string)
28745 CFI_STARTPROC
28746+ ASM_PAX_OPEN_USERLAND
28747 ASM_STAC
28748 andl %edx,%edx
28749 jz 4f
28750@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28751 movsb
28752 4: xorl %eax,%eax
28753 ASM_CLAC
28754+ ASM_PAX_CLOSE_USERLAND
28755+ pax_force_retaddr
28756 ret
28757
28758 .section .fixup,"ax"
28759@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28760 */
28761 ENTRY(copy_user_enhanced_fast_string)
28762 CFI_STARTPROC
28763+ ASM_PAX_OPEN_USERLAND
28764 ASM_STAC
28765 andl %edx,%edx
28766 jz 2f
28767@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28768 movsb
28769 2: xorl %eax,%eax
28770 ASM_CLAC
28771+ ASM_PAX_CLOSE_USERLAND
28772+ pax_force_retaddr
28773 ret
28774
28775 .section .fixup,"ax"
28776diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28777index 6a4f43c..c70fb52 100644
28778--- a/arch/x86/lib/copy_user_nocache_64.S
28779+++ b/arch/x86/lib/copy_user_nocache_64.S
28780@@ -8,6 +8,7 @@
28781
28782 #include <linux/linkage.h>
28783 #include <asm/dwarf2.h>
28784+#include <asm/alternative-asm.h>
28785
28786 #define FIX_ALIGNMENT 1
28787
28788@@ -16,6 +17,7 @@
28789 #include <asm/thread_info.h>
28790 #include <asm/asm.h>
28791 #include <asm/smap.h>
28792+#include <asm/pgtable.h>
28793
28794 .macro ALIGN_DESTINATION
28795 #ifdef FIX_ALIGNMENT
28796@@ -49,6 +51,16 @@
28797 */
28798 ENTRY(__copy_user_nocache)
28799 CFI_STARTPROC
28800+
28801+#ifdef CONFIG_PAX_MEMORY_UDEREF
28802+ mov pax_user_shadow_base,%rcx
28803+ cmp %rcx,%rsi
28804+ jae 1f
28805+ add %rcx,%rsi
28806+1:
28807+#endif
28808+
28809+ ASM_PAX_OPEN_USERLAND
28810 ASM_STAC
28811 cmpl $8,%edx
28812 jb 20f /* less then 8 bytes, go to byte copy loop */
28813@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28814 jnz 21b
28815 23: xorl %eax,%eax
28816 ASM_CLAC
28817+ ASM_PAX_CLOSE_USERLAND
28818 sfence
28819+ pax_force_retaddr
28820 ret
28821
28822 .section .fixup,"ax"
28823diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28824index 2419d5f..fe52d0e 100644
28825--- a/arch/x86/lib/csum-copy_64.S
28826+++ b/arch/x86/lib/csum-copy_64.S
28827@@ -9,6 +9,7 @@
28828 #include <asm/dwarf2.h>
28829 #include <asm/errno.h>
28830 #include <asm/asm.h>
28831+#include <asm/alternative-asm.h>
28832
28833 /*
28834 * Checksum copy with exception handling.
28835@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
28836 CFI_ADJUST_CFA_OFFSET 7*8
28837 movq %rbx, 2*8(%rsp)
28838 CFI_REL_OFFSET rbx, 2*8
28839- movq %r12, 3*8(%rsp)
28840- CFI_REL_OFFSET r12, 3*8
28841+ movq %r15, 3*8(%rsp)
28842+ CFI_REL_OFFSET r15, 3*8
28843 movq %r14, 4*8(%rsp)
28844 CFI_REL_OFFSET r14, 4*8
28845 movq %r13, 5*8(%rsp)
28846@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
28847 movl %edx, %ecx
28848
28849 xorl %r9d, %r9d
28850- movq %rcx, %r12
28851+ movq %rcx, %r15
28852
28853- shrq $6, %r12
28854+ shrq $6, %r15
28855 jz .Lhandle_tail /* < 64 */
28856
28857 clc
28858
28859 /* main loop. clear in 64 byte blocks */
28860 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
28861- /* r11: temp3, rdx: temp4, r12 loopcnt */
28862+ /* r11: temp3, rdx: temp4, r15 loopcnt */
28863 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
28864 .p2align 4
28865 .Lloop:
28866@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
28867 adcq %r14, %rax
28868 adcq %r13, %rax
28869
28870- decl %r12d
28871+ decl %r15d
28872
28873 dest
28874 movq %rbx, (%rsi)
28875@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
28876 .Lende:
28877 movq 2*8(%rsp), %rbx
28878 CFI_RESTORE rbx
28879- movq 3*8(%rsp), %r12
28880- CFI_RESTORE r12
28881+ movq 3*8(%rsp), %r15
28882+ CFI_RESTORE r15
28883 movq 4*8(%rsp), %r14
28884 CFI_RESTORE r14
28885 movq 5*8(%rsp), %r13
28886@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28887 CFI_RESTORE rbp
28888 addq $7*8, %rsp
28889 CFI_ADJUST_CFA_OFFSET -7*8
28890+ pax_force_retaddr
28891 ret
28892 CFI_RESTORE_STATE
28893
28894diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28895index 7609e0e..b449b98 100644
28896--- a/arch/x86/lib/csum-wrappers_64.c
28897+++ b/arch/x86/lib/csum-wrappers_64.c
28898@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28899 len -= 2;
28900 }
28901 }
28902+ pax_open_userland();
28903 stac();
28904- isum = csum_partial_copy_generic((__force const void *)src,
28905+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28906 dst, len, isum, errp, NULL);
28907 clac();
28908+ pax_close_userland();
28909 if (unlikely(*errp))
28910 goto out_err;
28911
28912@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28913 }
28914
28915 *errp = 0;
28916+ pax_open_userland();
28917 stac();
28918- ret = csum_partial_copy_generic(src, (void __force *)dst,
28919+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28920 len, isum, NULL, errp);
28921 clac();
28922+ pax_close_userland();
28923 return ret;
28924 }
28925 EXPORT_SYMBOL(csum_partial_copy_to_user);
28926diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28927index a451235..1daa956 100644
28928--- a/arch/x86/lib/getuser.S
28929+++ b/arch/x86/lib/getuser.S
28930@@ -33,17 +33,40 @@
28931 #include <asm/thread_info.h>
28932 #include <asm/asm.h>
28933 #include <asm/smap.h>
28934+#include <asm/segment.h>
28935+#include <asm/pgtable.h>
28936+#include <asm/alternative-asm.h>
28937+
28938+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28939+#define __copyuser_seg gs;
28940+#else
28941+#define __copyuser_seg
28942+#endif
28943
28944 .text
28945 ENTRY(__get_user_1)
28946 CFI_STARTPROC
28947+
28948+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28949 GET_THREAD_INFO(%_ASM_DX)
28950 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28951 jae bad_get_user
28952 ASM_STAC
28953-1: movzbl (%_ASM_AX),%edx
28954+
28955+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28956+ mov pax_user_shadow_base,%_ASM_DX
28957+ cmp %_ASM_DX,%_ASM_AX
28958+ jae 1234f
28959+ add %_ASM_DX,%_ASM_AX
28960+1234:
28961+#endif
28962+
28963+#endif
28964+
28965+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28966 xor %eax,%eax
28967 ASM_CLAC
28968+ pax_force_retaddr
28969 ret
28970 CFI_ENDPROC
28971 ENDPROC(__get_user_1)
28972@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28973 ENTRY(__get_user_2)
28974 CFI_STARTPROC
28975 add $1,%_ASM_AX
28976+
28977+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28978 jc bad_get_user
28979 GET_THREAD_INFO(%_ASM_DX)
28980 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28981 jae bad_get_user
28982 ASM_STAC
28983-2: movzwl -1(%_ASM_AX),%edx
28984+
28985+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28986+ mov pax_user_shadow_base,%_ASM_DX
28987+ cmp %_ASM_DX,%_ASM_AX
28988+ jae 1234f
28989+ add %_ASM_DX,%_ASM_AX
28990+1234:
28991+#endif
28992+
28993+#endif
28994+
28995+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28996 xor %eax,%eax
28997 ASM_CLAC
28998+ pax_force_retaddr
28999 ret
29000 CFI_ENDPROC
29001 ENDPROC(__get_user_2)
29002@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29003 ENTRY(__get_user_4)
29004 CFI_STARTPROC
29005 add $3,%_ASM_AX
29006+
29007+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29008 jc bad_get_user
29009 GET_THREAD_INFO(%_ASM_DX)
29010 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29011 jae bad_get_user
29012 ASM_STAC
29013-3: movl -3(%_ASM_AX),%edx
29014+
29015+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29016+ mov pax_user_shadow_base,%_ASM_DX
29017+ cmp %_ASM_DX,%_ASM_AX
29018+ jae 1234f
29019+ add %_ASM_DX,%_ASM_AX
29020+1234:
29021+#endif
29022+
29023+#endif
29024+
29025+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29026 xor %eax,%eax
29027 ASM_CLAC
29028+ pax_force_retaddr
29029 ret
29030 CFI_ENDPROC
29031 ENDPROC(__get_user_4)
29032@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29033 GET_THREAD_INFO(%_ASM_DX)
29034 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29035 jae bad_get_user
29036+
29037+#ifdef CONFIG_PAX_MEMORY_UDEREF
29038+ mov pax_user_shadow_base,%_ASM_DX
29039+ cmp %_ASM_DX,%_ASM_AX
29040+ jae 1234f
29041+ add %_ASM_DX,%_ASM_AX
29042+1234:
29043+#endif
29044+
29045 ASM_STAC
29046 4: movq -7(%_ASM_AX),%rdx
29047 xor %eax,%eax
29048 ASM_CLAC
29049+ pax_force_retaddr
29050 ret
29051 #else
29052 add $7,%_ASM_AX
29053@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29054 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29055 jae bad_get_user_8
29056 ASM_STAC
29057-4: movl -7(%_ASM_AX),%edx
29058-5: movl -3(%_ASM_AX),%ecx
29059+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29060+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29061 xor %eax,%eax
29062 ASM_CLAC
29063+ pax_force_retaddr
29064 ret
29065 #endif
29066 CFI_ENDPROC
29067@@ -113,6 +175,7 @@ bad_get_user:
29068 xor %edx,%edx
29069 mov $(-EFAULT),%_ASM_AX
29070 ASM_CLAC
29071+ pax_force_retaddr
29072 ret
29073 CFI_ENDPROC
29074 END(bad_get_user)
29075@@ -124,6 +187,7 @@ bad_get_user_8:
29076 xor %ecx,%ecx
29077 mov $(-EFAULT),%_ASM_AX
29078 ASM_CLAC
29079+ pax_force_retaddr
29080 ret
29081 CFI_ENDPROC
29082 END(bad_get_user_8)
29083diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29084index 54fcffe..7be149e 100644
29085--- a/arch/x86/lib/insn.c
29086+++ b/arch/x86/lib/insn.c
29087@@ -20,8 +20,10 @@
29088
29089 #ifdef __KERNEL__
29090 #include <linux/string.h>
29091+#include <asm/pgtable_types.h>
29092 #else
29093 #include <string.h>
29094+#define ktla_ktva(addr) addr
29095 #endif
29096 #include <asm/inat.h>
29097 #include <asm/insn.h>
29098@@ -53,8 +55,8 @@
29099 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29100 {
29101 memset(insn, 0, sizeof(*insn));
29102- insn->kaddr = kaddr;
29103- insn->next_byte = kaddr;
29104+ insn->kaddr = ktla_ktva(kaddr);
29105+ insn->next_byte = ktla_ktva(kaddr);
29106 insn->x86_64 = x86_64 ? 1 : 0;
29107 insn->opnd_bytes = 4;
29108 if (x86_64)
29109diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29110index 05a95e7..326f2fa 100644
29111--- a/arch/x86/lib/iomap_copy_64.S
29112+++ b/arch/x86/lib/iomap_copy_64.S
29113@@ -17,6 +17,7 @@
29114
29115 #include <linux/linkage.h>
29116 #include <asm/dwarf2.h>
29117+#include <asm/alternative-asm.h>
29118
29119 /*
29120 * override generic version in lib/iomap_copy.c
29121@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29122 CFI_STARTPROC
29123 movl %edx,%ecx
29124 rep movsd
29125+ pax_force_retaddr
29126 ret
29127 CFI_ENDPROC
29128 ENDPROC(__iowrite32_copy)
29129diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29130index 56313a3..0db417e 100644
29131--- a/arch/x86/lib/memcpy_64.S
29132+++ b/arch/x86/lib/memcpy_64.S
29133@@ -24,7 +24,7 @@
29134 * This gets patched over the unrolled variant (below) via the
29135 * alternative instructions framework:
29136 */
29137- .section .altinstr_replacement, "ax", @progbits
29138+ .section .altinstr_replacement, "a", @progbits
29139 .Lmemcpy_c:
29140 movq %rdi, %rax
29141 movq %rdx, %rcx
29142@@ -33,6 +33,7 @@
29143 rep movsq
29144 movl %edx, %ecx
29145 rep movsb
29146+ pax_force_retaddr
29147 ret
29148 .Lmemcpy_e:
29149 .previous
29150@@ -44,11 +45,12 @@
29151 * This gets patched over the unrolled variant (below) via the
29152 * alternative instructions framework:
29153 */
29154- .section .altinstr_replacement, "ax", @progbits
29155+ .section .altinstr_replacement, "a", @progbits
29156 .Lmemcpy_c_e:
29157 movq %rdi, %rax
29158 movq %rdx, %rcx
29159 rep movsb
29160+ pax_force_retaddr
29161 ret
29162 .Lmemcpy_e_e:
29163 .previous
29164@@ -136,6 +138,7 @@ ENTRY(memcpy)
29165 movq %r9, 1*8(%rdi)
29166 movq %r10, -2*8(%rdi, %rdx)
29167 movq %r11, -1*8(%rdi, %rdx)
29168+ pax_force_retaddr
29169 retq
29170 .p2align 4
29171 .Lless_16bytes:
29172@@ -148,6 +151,7 @@ ENTRY(memcpy)
29173 movq -1*8(%rsi, %rdx), %r9
29174 movq %r8, 0*8(%rdi)
29175 movq %r9, -1*8(%rdi, %rdx)
29176+ pax_force_retaddr
29177 retq
29178 .p2align 4
29179 .Lless_8bytes:
29180@@ -161,6 +165,7 @@ ENTRY(memcpy)
29181 movl -4(%rsi, %rdx), %r8d
29182 movl %ecx, (%rdi)
29183 movl %r8d, -4(%rdi, %rdx)
29184+ pax_force_retaddr
29185 retq
29186 .p2align 4
29187 .Lless_3bytes:
29188@@ -179,6 +184,7 @@ ENTRY(memcpy)
29189 movb %cl, (%rdi)
29190
29191 .Lend:
29192+ pax_force_retaddr
29193 retq
29194 CFI_ENDPROC
29195 ENDPROC(memcpy)
29196diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29197index 65268a6..dd1de11 100644
29198--- a/arch/x86/lib/memmove_64.S
29199+++ b/arch/x86/lib/memmove_64.S
29200@@ -202,14 +202,16 @@ ENTRY(memmove)
29201 movb (%rsi), %r11b
29202 movb %r11b, (%rdi)
29203 13:
29204+ pax_force_retaddr
29205 retq
29206 CFI_ENDPROC
29207
29208- .section .altinstr_replacement,"ax"
29209+ .section .altinstr_replacement,"a"
29210 .Lmemmove_begin_forward_efs:
29211 /* Forward moving data. */
29212 movq %rdx, %rcx
29213 rep movsb
29214+ pax_force_retaddr
29215 retq
29216 .Lmemmove_end_forward_efs:
29217 .previous
29218diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29219index 2dcb380..2eb79fe 100644
29220--- a/arch/x86/lib/memset_64.S
29221+++ b/arch/x86/lib/memset_64.S
29222@@ -16,7 +16,7 @@
29223 *
29224 * rax original destination
29225 */
29226- .section .altinstr_replacement, "ax", @progbits
29227+ .section .altinstr_replacement, "a", @progbits
29228 .Lmemset_c:
29229 movq %rdi,%r9
29230 movq %rdx,%rcx
29231@@ -30,6 +30,7 @@
29232 movl %edx,%ecx
29233 rep stosb
29234 movq %r9,%rax
29235+ pax_force_retaddr
29236 ret
29237 .Lmemset_e:
29238 .previous
29239@@ -45,13 +46,14 @@
29240 *
29241 * rax original destination
29242 */
29243- .section .altinstr_replacement, "ax", @progbits
29244+ .section .altinstr_replacement, "a", @progbits
29245 .Lmemset_c_e:
29246 movq %rdi,%r9
29247 movb %sil,%al
29248 movq %rdx,%rcx
29249 rep stosb
29250 movq %r9,%rax
29251+ pax_force_retaddr
29252 ret
29253 .Lmemset_e_e:
29254 .previous
29255@@ -118,6 +120,7 @@ ENTRY(__memset)
29256
29257 .Lende:
29258 movq %r10,%rax
29259+ pax_force_retaddr
29260 ret
29261
29262 CFI_RESTORE_STATE
29263diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29264index c9f2d9b..e7fd2c0 100644
29265--- a/arch/x86/lib/mmx_32.c
29266+++ b/arch/x86/lib/mmx_32.c
29267@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29268 {
29269 void *p;
29270 int i;
29271+ unsigned long cr0;
29272
29273 if (unlikely(in_interrupt()))
29274 return __memcpy(to, from, len);
29275@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29276 kernel_fpu_begin();
29277
29278 __asm__ __volatile__ (
29279- "1: prefetch (%0)\n" /* This set is 28 bytes */
29280- " prefetch 64(%0)\n"
29281- " prefetch 128(%0)\n"
29282- " prefetch 192(%0)\n"
29283- " prefetch 256(%0)\n"
29284+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29285+ " prefetch 64(%1)\n"
29286+ " prefetch 128(%1)\n"
29287+ " prefetch 192(%1)\n"
29288+ " prefetch 256(%1)\n"
29289 "2: \n"
29290 ".section .fixup, \"ax\"\n"
29291- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29292+ "3: \n"
29293+
29294+#ifdef CONFIG_PAX_KERNEXEC
29295+ " movl %%cr0, %0\n"
29296+ " movl %0, %%eax\n"
29297+ " andl $0xFFFEFFFF, %%eax\n"
29298+ " movl %%eax, %%cr0\n"
29299+#endif
29300+
29301+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29302+
29303+#ifdef CONFIG_PAX_KERNEXEC
29304+ " movl %0, %%cr0\n"
29305+#endif
29306+
29307 " jmp 2b\n"
29308 ".previous\n"
29309 _ASM_EXTABLE(1b, 3b)
29310- : : "r" (from));
29311+ : "=&r" (cr0) : "r" (from) : "ax");
29312
29313 for ( ; i > 5; i--) {
29314 __asm__ __volatile__ (
29315- "1: prefetch 320(%0)\n"
29316- "2: movq (%0), %%mm0\n"
29317- " movq 8(%0), %%mm1\n"
29318- " movq 16(%0), %%mm2\n"
29319- " movq 24(%0), %%mm3\n"
29320- " movq %%mm0, (%1)\n"
29321- " movq %%mm1, 8(%1)\n"
29322- " movq %%mm2, 16(%1)\n"
29323- " movq %%mm3, 24(%1)\n"
29324- " movq 32(%0), %%mm0\n"
29325- " movq 40(%0), %%mm1\n"
29326- " movq 48(%0), %%mm2\n"
29327- " movq 56(%0), %%mm3\n"
29328- " movq %%mm0, 32(%1)\n"
29329- " movq %%mm1, 40(%1)\n"
29330- " movq %%mm2, 48(%1)\n"
29331- " movq %%mm3, 56(%1)\n"
29332+ "1: prefetch 320(%1)\n"
29333+ "2: movq (%1), %%mm0\n"
29334+ " movq 8(%1), %%mm1\n"
29335+ " movq 16(%1), %%mm2\n"
29336+ " movq 24(%1), %%mm3\n"
29337+ " movq %%mm0, (%2)\n"
29338+ " movq %%mm1, 8(%2)\n"
29339+ " movq %%mm2, 16(%2)\n"
29340+ " movq %%mm3, 24(%2)\n"
29341+ " movq 32(%1), %%mm0\n"
29342+ " movq 40(%1), %%mm1\n"
29343+ " movq 48(%1), %%mm2\n"
29344+ " movq 56(%1), %%mm3\n"
29345+ " movq %%mm0, 32(%2)\n"
29346+ " movq %%mm1, 40(%2)\n"
29347+ " movq %%mm2, 48(%2)\n"
29348+ " movq %%mm3, 56(%2)\n"
29349 ".section .fixup, \"ax\"\n"
29350- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29351+ "3:\n"
29352+
29353+#ifdef CONFIG_PAX_KERNEXEC
29354+ " movl %%cr0, %0\n"
29355+ " movl %0, %%eax\n"
29356+ " andl $0xFFFEFFFF, %%eax\n"
29357+ " movl %%eax, %%cr0\n"
29358+#endif
29359+
29360+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29361+
29362+#ifdef CONFIG_PAX_KERNEXEC
29363+ " movl %0, %%cr0\n"
29364+#endif
29365+
29366 " jmp 2b\n"
29367 ".previous\n"
29368 _ASM_EXTABLE(1b, 3b)
29369- : : "r" (from), "r" (to) : "memory");
29370+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29371
29372 from += 64;
29373 to += 64;
29374@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29375 static void fast_copy_page(void *to, void *from)
29376 {
29377 int i;
29378+ unsigned long cr0;
29379
29380 kernel_fpu_begin();
29381
29382@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29383 * but that is for later. -AV
29384 */
29385 __asm__ __volatile__(
29386- "1: prefetch (%0)\n"
29387- " prefetch 64(%0)\n"
29388- " prefetch 128(%0)\n"
29389- " prefetch 192(%0)\n"
29390- " prefetch 256(%0)\n"
29391+ "1: prefetch (%1)\n"
29392+ " prefetch 64(%1)\n"
29393+ " prefetch 128(%1)\n"
29394+ " prefetch 192(%1)\n"
29395+ " prefetch 256(%1)\n"
29396 "2: \n"
29397 ".section .fixup, \"ax\"\n"
29398- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29399+ "3: \n"
29400+
29401+#ifdef CONFIG_PAX_KERNEXEC
29402+ " movl %%cr0, %0\n"
29403+ " movl %0, %%eax\n"
29404+ " andl $0xFFFEFFFF, %%eax\n"
29405+ " movl %%eax, %%cr0\n"
29406+#endif
29407+
29408+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29409+
29410+#ifdef CONFIG_PAX_KERNEXEC
29411+ " movl %0, %%cr0\n"
29412+#endif
29413+
29414 " jmp 2b\n"
29415 ".previous\n"
29416- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29417+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29418
29419 for (i = 0; i < (4096-320)/64; i++) {
29420 __asm__ __volatile__ (
29421- "1: prefetch 320(%0)\n"
29422- "2: movq (%0), %%mm0\n"
29423- " movntq %%mm0, (%1)\n"
29424- " movq 8(%0), %%mm1\n"
29425- " movntq %%mm1, 8(%1)\n"
29426- " movq 16(%0), %%mm2\n"
29427- " movntq %%mm2, 16(%1)\n"
29428- " movq 24(%0), %%mm3\n"
29429- " movntq %%mm3, 24(%1)\n"
29430- " movq 32(%0), %%mm4\n"
29431- " movntq %%mm4, 32(%1)\n"
29432- " movq 40(%0), %%mm5\n"
29433- " movntq %%mm5, 40(%1)\n"
29434- " movq 48(%0), %%mm6\n"
29435- " movntq %%mm6, 48(%1)\n"
29436- " movq 56(%0), %%mm7\n"
29437- " movntq %%mm7, 56(%1)\n"
29438+ "1: prefetch 320(%1)\n"
29439+ "2: movq (%1), %%mm0\n"
29440+ " movntq %%mm0, (%2)\n"
29441+ " movq 8(%1), %%mm1\n"
29442+ " movntq %%mm1, 8(%2)\n"
29443+ " movq 16(%1), %%mm2\n"
29444+ " movntq %%mm2, 16(%2)\n"
29445+ " movq 24(%1), %%mm3\n"
29446+ " movntq %%mm3, 24(%2)\n"
29447+ " movq 32(%1), %%mm4\n"
29448+ " movntq %%mm4, 32(%2)\n"
29449+ " movq 40(%1), %%mm5\n"
29450+ " movntq %%mm5, 40(%2)\n"
29451+ " movq 48(%1), %%mm6\n"
29452+ " movntq %%mm6, 48(%2)\n"
29453+ " movq 56(%1), %%mm7\n"
29454+ " movntq %%mm7, 56(%2)\n"
29455 ".section .fixup, \"ax\"\n"
29456- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29457+ "3:\n"
29458+
29459+#ifdef CONFIG_PAX_KERNEXEC
29460+ " movl %%cr0, %0\n"
29461+ " movl %0, %%eax\n"
29462+ " andl $0xFFFEFFFF, %%eax\n"
29463+ " movl %%eax, %%cr0\n"
29464+#endif
29465+
29466+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29467+
29468+#ifdef CONFIG_PAX_KERNEXEC
29469+ " movl %0, %%cr0\n"
29470+#endif
29471+
29472 " jmp 2b\n"
29473 ".previous\n"
29474- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29475+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29476
29477 from += 64;
29478 to += 64;
29479@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29480 static void fast_copy_page(void *to, void *from)
29481 {
29482 int i;
29483+ unsigned long cr0;
29484
29485 kernel_fpu_begin();
29486
29487 __asm__ __volatile__ (
29488- "1: prefetch (%0)\n"
29489- " prefetch 64(%0)\n"
29490- " prefetch 128(%0)\n"
29491- " prefetch 192(%0)\n"
29492- " prefetch 256(%0)\n"
29493+ "1: prefetch (%1)\n"
29494+ " prefetch 64(%1)\n"
29495+ " prefetch 128(%1)\n"
29496+ " prefetch 192(%1)\n"
29497+ " prefetch 256(%1)\n"
29498 "2: \n"
29499 ".section .fixup, \"ax\"\n"
29500- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29501+ "3: \n"
29502+
29503+#ifdef CONFIG_PAX_KERNEXEC
29504+ " movl %%cr0, %0\n"
29505+ " movl %0, %%eax\n"
29506+ " andl $0xFFFEFFFF, %%eax\n"
29507+ " movl %%eax, %%cr0\n"
29508+#endif
29509+
29510+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29511+
29512+#ifdef CONFIG_PAX_KERNEXEC
29513+ " movl %0, %%cr0\n"
29514+#endif
29515+
29516 " jmp 2b\n"
29517 ".previous\n"
29518- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29519+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29520
29521 for (i = 0; i < 4096/64; i++) {
29522 __asm__ __volatile__ (
29523- "1: prefetch 320(%0)\n"
29524- "2: movq (%0), %%mm0\n"
29525- " movq 8(%0), %%mm1\n"
29526- " movq 16(%0), %%mm2\n"
29527- " movq 24(%0), %%mm3\n"
29528- " movq %%mm0, (%1)\n"
29529- " movq %%mm1, 8(%1)\n"
29530- " movq %%mm2, 16(%1)\n"
29531- " movq %%mm3, 24(%1)\n"
29532- " movq 32(%0), %%mm0\n"
29533- " movq 40(%0), %%mm1\n"
29534- " movq 48(%0), %%mm2\n"
29535- " movq 56(%0), %%mm3\n"
29536- " movq %%mm0, 32(%1)\n"
29537- " movq %%mm1, 40(%1)\n"
29538- " movq %%mm2, 48(%1)\n"
29539- " movq %%mm3, 56(%1)\n"
29540+ "1: prefetch 320(%1)\n"
29541+ "2: movq (%1), %%mm0\n"
29542+ " movq 8(%1), %%mm1\n"
29543+ " movq 16(%1), %%mm2\n"
29544+ " movq 24(%1), %%mm3\n"
29545+ " movq %%mm0, (%2)\n"
29546+ " movq %%mm1, 8(%2)\n"
29547+ " movq %%mm2, 16(%2)\n"
29548+ " movq %%mm3, 24(%2)\n"
29549+ " movq 32(%1), %%mm0\n"
29550+ " movq 40(%1), %%mm1\n"
29551+ " movq 48(%1), %%mm2\n"
29552+ " movq 56(%1), %%mm3\n"
29553+ " movq %%mm0, 32(%2)\n"
29554+ " movq %%mm1, 40(%2)\n"
29555+ " movq %%mm2, 48(%2)\n"
29556+ " movq %%mm3, 56(%2)\n"
29557 ".section .fixup, \"ax\"\n"
29558- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29559+ "3:\n"
29560+
29561+#ifdef CONFIG_PAX_KERNEXEC
29562+ " movl %%cr0, %0\n"
29563+ " movl %0, %%eax\n"
29564+ " andl $0xFFFEFFFF, %%eax\n"
29565+ " movl %%eax, %%cr0\n"
29566+#endif
29567+
29568+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29569+
29570+#ifdef CONFIG_PAX_KERNEXEC
29571+ " movl %0, %%cr0\n"
29572+#endif
29573+
29574 " jmp 2b\n"
29575 ".previous\n"
29576 _ASM_EXTABLE(1b, 3b)
29577- : : "r" (from), "r" (to) : "memory");
29578+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29579
29580 from += 64;
29581 to += 64;
29582diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29583index f6d13ee..d789440 100644
29584--- a/arch/x86/lib/msr-reg.S
29585+++ b/arch/x86/lib/msr-reg.S
29586@@ -3,6 +3,7 @@
29587 #include <asm/dwarf2.h>
29588 #include <asm/asm.h>
29589 #include <asm/msr.h>
29590+#include <asm/alternative-asm.h>
29591
29592 #ifdef CONFIG_X86_64
29593 /*
29594@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
29595 movl %edi, 28(%r10)
29596 popq_cfi %rbp
29597 popq_cfi %rbx
29598+ pax_force_retaddr
29599 ret
29600 3:
29601 CFI_RESTORE_STATE
29602diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29603index fc6ba17..d4d989d 100644
29604--- a/arch/x86/lib/putuser.S
29605+++ b/arch/x86/lib/putuser.S
29606@@ -16,7 +16,9 @@
29607 #include <asm/errno.h>
29608 #include <asm/asm.h>
29609 #include <asm/smap.h>
29610-
29611+#include <asm/segment.h>
29612+#include <asm/pgtable.h>
29613+#include <asm/alternative-asm.h>
29614
29615 /*
29616 * __put_user_X
29617@@ -30,57 +32,125 @@
29618 * as they get called from within inline assembly.
29619 */
29620
29621-#define ENTER CFI_STARTPROC ; \
29622- GET_THREAD_INFO(%_ASM_BX)
29623-#define EXIT ASM_CLAC ; \
29624- ret ; \
29625+#define ENTER CFI_STARTPROC
29626+#define EXIT ASM_CLAC ; \
29627+ pax_force_retaddr ; \
29628+ ret ; \
29629 CFI_ENDPROC
29630
29631+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29632+#define _DEST %_ASM_CX,%_ASM_BX
29633+#else
29634+#define _DEST %_ASM_CX
29635+#endif
29636+
29637+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29638+#define __copyuser_seg gs;
29639+#else
29640+#define __copyuser_seg
29641+#endif
29642+
29643 .text
29644 ENTRY(__put_user_1)
29645 ENTER
29646+
29647+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29648+ GET_THREAD_INFO(%_ASM_BX)
29649 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29650 jae bad_put_user
29651 ASM_STAC
29652-1: movb %al,(%_ASM_CX)
29653+
29654+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29655+ mov pax_user_shadow_base,%_ASM_BX
29656+ cmp %_ASM_BX,%_ASM_CX
29657+ jb 1234f
29658+ xor %ebx,%ebx
29659+1234:
29660+#endif
29661+
29662+#endif
29663+
29664+1: __copyuser_seg movb %al,(_DEST)
29665 xor %eax,%eax
29666 EXIT
29667 ENDPROC(__put_user_1)
29668
29669 ENTRY(__put_user_2)
29670 ENTER
29671+
29672+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29673+ GET_THREAD_INFO(%_ASM_BX)
29674 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29675 sub $1,%_ASM_BX
29676 cmp %_ASM_BX,%_ASM_CX
29677 jae bad_put_user
29678 ASM_STAC
29679-2: movw %ax,(%_ASM_CX)
29680+
29681+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29682+ mov pax_user_shadow_base,%_ASM_BX
29683+ cmp %_ASM_BX,%_ASM_CX
29684+ jb 1234f
29685+ xor %ebx,%ebx
29686+1234:
29687+#endif
29688+
29689+#endif
29690+
29691+2: __copyuser_seg movw %ax,(_DEST)
29692 xor %eax,%eax
29693 EXIT
29694 ENDPROC(__put_user_2)
29695
29696 ENTRY(__put_user_4)
29697 ENTER
29698+
29699+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29700+ GET_THREAD_INFO(%_ASM_BX)
29701 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29702 sub $3,%_ASM_BX
29703 cmp %_ASM_BX,%_ASM_CX
29704 jae bad_put_user
29705 ASM_STAC
29706-3: movl %eax,(%_ASM_CX)
29707+
29708+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29709+ mov pax_user_shadow_base,%_ASM_BX
29710+ cmp %_ASM_BX,%_ASM_CX
29711+ jb 1234f
29712+ xor %ebx,%ebx
29713+1234:
29714+#endif
29715+
29716+#endif
29717+
29718+3: __copyuser_seg movl %eax,(_DEST)
29719 xor %eax,%eax
29720 EXIT
29721 ENDPROC(__put_user_4)
29722
29723 ENTRY(__put_user_8)
29724 ENTER
29725+
29726+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29727+ GET_THREAD_INFO(%_ASM_BX)
29728 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29729 sub $7,%_ASM_BX
29730 cmp %_ASM_BX,%_ASM_CX
29731 jae bad_put_user
29732 ASM_STAC
29733-4: mov %_ASM_AX,(%_ASM_CX)
29734+
29735+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29736+ mov pax_user_shadow_base,%_ASM_BX
29737+ cmp %_ASM_BX,%_ASM_CX
29738+ jb 1234f
29739+ xor %ebx,%ebx
29740+1234:
29741+#endif
29742+
29743+#endif
29744+
29745+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29746 #ifdef CONFIG_X86_32
29747-5: movl %edx,4(%_ASM_CX)
29748+5: __copyuser_seg movl %edx,4(_DEST)
29749 #endif
29750 xor %eax,%eax
29751 EXIT
29752diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29753index 1cad221..de671ee 100644
29754--- a/arch/x86/lib/rwlock.S
29755+++ b/arch/x86/lib/rwlock.S
29756@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29757 FRAME
29758 0: LOCK_PREFIX
29759 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29760+
29761+#ifdef CONFIG_PAX_REFCOUNT
29762+ jno 1234f
29763+ LOCK_PREFIX
29764+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29765+ int $4
29766+1234:
29767+ _ASM_EXTABLE(1234b, 1234b)
29768+#endif
29769+
29770 1: rep; nop
29771 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29772 jne 1b
29773 LOCK_PREFIX
29774 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29775+
29776+#ifdef CONFIG_PAX_REFCOUNT
29777+ jno 1234f
29778+ LOCK_PREFIX
29779+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29780+ int $4
29781+1234:
29782+ _ASM_EXTABLE(1234b, 1234b)
29783+#endif
29784+
29785 jnz 0b
29786 ENDFRAME
29787+ pax_force_retaddr
29788 ret
29789 CFI_ENDPROC
29790 END(__write_lock_failed)
29791@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29792 FRAME
29793 0: LOCK_PREFIX
29794 READ_LOCK_SIZE(inc) (%__lock_ptr)
29795+
29796+#ifdef CONFIG_PAX_REFCOUNT
29797+ jno 1234f
29798+ LOCK_PREFIX
29799+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29800+ int $4
29801+1234:
29802+ _ASM_EXTABLE(1234b, 1234b)
29803+#endif
29804+
29805 1: rep; nop
29806 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29807 js 1b
29808 LOCK_PREFIX
29809 READ_LOCK_SIZE(dec) (%__lock_ptr)
29810+
29811+#ifdef CONFIG_PAX_REFCOUNT
29812+ jno 1234f
29813+ LOCK_PREFIX
29814+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29815+ int $4
29816+1234:
29817+ _ASM_EXTABLE(1234b, 1234b)
29818+#endif
29819+
29820 js 0b
29821 ENDFRAME
29822+ pax_force_retaddr
29823 ret
29824 CFI_ENDPROC
29825 END(__read_lock_failed)
29826diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29827index 5dff5f0..cadebf4 100644
29828--- a/arch/x86/lib/rwsem.S
29829+++ b/arch/x86/lib/rwsem.S
29830@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29831 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29832 CFI_RESTORE __ASM_REG(dx)
29833 restore_common_regs
29834+ pax_force_retaddr
29835 ret
29836 CFI_ENDPROC
29837 ENDPROC(call_rwsem_down_read_failed)
29838@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29839 movq %rax,%rdi
29840 call rwsem_down_write_failed
29841 restore_common_regs
29842+ pax_force_retaddr
29843 ret
29844 CFI_ENDPROC
29845 ENDPROC(call_rwsem_down_write_failed)
29846@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29847 movq %rax,%rdi
29848 call rwsem_wake
29849 restore_common_regs
29850-1: ret
29851+1: pax_force_retaddr
29852+ ret
29853 CFI_ENDPROC
29854 ENDPROC(call_rwsem_wake)
29855
29856@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29857 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29858 CFI_RESTORE __ASM_REG(dx)
29859 restore_common_regs
29860+ pax_force_retaddr
29861 ret
29862 CFI_ENDPROC
29863 ENDPROC(call_rwsem_downgrade_wake)
29864diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29865index a63efd6..8149fbe 100644
29866--- a/arch/x86/lib/thunk_64.S
29867+++ b/arch/x86/lib/thunk_64.S
29868@@ -8,6 +8,7 @@
29869 #include <linux/linkage.h>
29870 #include <asm/dwarf2.h>
29871 #include <asm/calling.h>
29872+#include <asm/alternative-asm.h>
29873
29874 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29875 .macro THUNK name, func, put_ret_addr_in_rdi=0
29876@@ -15,11 +16,11 @@
29877 \name:
29878 CFI_STARTPROC
29879
29880- /* this one pushes 9 elems, the next one would be %rIP */
29881- SAVE_ARGS
29882+ /* this one pushes 15+1 elems, the next one would be %rIP */
29883+ SAVE_ARGS 8
29884
29885 .if \put_ret_addr_in_rdi
29886- movq_cfi_restore 9*8, rdi
29887+ movq_cfi_restore RIP, rdi
29888 .endif
29889
29890 call \func
29891@@ -38,8 +39,9 @@
29892
29893 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
29894 CFI_STARTPROC
29895- SAVE_ARGS
29896+ SAVE_ARGS 8
29897 restore:
29898- RESTORE_ARGS
29899+ RESTORE_ARGS 1,8
29900+ pax_force_retaddr
29901 ret
29902 CFI_ENDPROC
29903diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29904index e2f5e21..4b22130 100644
29905--- a/arch/x86/lib/usercopy_32.c
29906+++ b/arch/x86/lib/usercopy_32.c
29907@@ -42,11 +42,13 @@ do { \
29908 int __d0; \
29909 might_fault(); \
29910 __asm__ __volatile__( \
29911+ __COPYUSER_SET_ES \
29912 ASM_STAC "\n" \
29913 "0: rep; stosl\n" \
29914 " movl %2,%0\n" \
29915 "1: rep; stosb\n" \
29916 "2: " ASM_CLAC "\n" \
29917+ __COPYUSER_RESTORE_ES \
29918 ".section .fixup,\"ax\"\n" \
29919 "3: lea 0(%2,%0,4),%0\n" \
29920 " jmp 2b\n" \
29921@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29922
29923 #ifdef CONFIG_X86_INTEL_USERCOPY
29924 static unsigned long
29925-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29926+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29927 {
29928 int d0, d1;
29929 __asm__ __volatile__(
29930@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29931 " .align 2,0x90\n"
29932 "3: movl 0(%4), %%eax\n"
29933 "4: movl 4(%4), %%edx\n"
29934- "5: movl %%eax, 0(%3)\n"
29935- "6: movl %%edx, 4(%3)\n"
29936+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29937+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29938 "7: movl 8(%4), %%eax\n"
29939 "8: movl 12(%4),%%edx\n"
29940- "9: movl %%eax, 8(%3)\n"
29941- "10: movl %%edx, 12(%3)\n"
29942+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29943+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29944 "11: movl 16(%4), %%eax\n"
29945 "12: movl 20(%4), %%edx\n"
29946- "13: movl %%eax, 16(%3)\n"
29947- "14: movl %%edx, 20(%3)\n"
29948+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29949+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29950 "15: movl 24(%4), %%eax\n"
29951 "16: movl 28(%4), %%edx\n"
29952- "17: movl %%eax, 24(%3)\n"
29953- "18: movl %%edx, 28(%3)\n"
29954+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29955+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29956 "19: movl 32(%4), %%eax\n"
29957 "20: movl 36(%4), %%edx\n"
29958- "21: movl %%eax, 32(%3)\n"
29959- "22: movl %%edx, 36(%3)\n"
29960+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29961+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29962 "23: movl 40(%4), %%eax\n"
29963 "24: movl 44(%4), %%edx\n"
29964- "25: movl %%eax, 40(%3)\n"
29965- "26: movl %%edx, 44(%3)\n"
29966+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29967+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29968 "27: movl 48(%4), %%eax\n"
29969 "28: movl 52(%4), %%edx\n"
29970- "29: movl %%eax, 48(%3)\n"
29971- "30: movl %%edx, 52(%3)\n"
29972+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29973+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29974 "31: movl 56(%4), %%eax\n"
29975 "32: movl 60(%4), %%edx\n"
29976- "33: movl %%eax, 56(%3)\n"
29977- "34: movl %%edx, 60(%3)\n"
29978+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29979+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29980 " addl $-64, %0\n"
29981 " addl $64, %4\n"
29982 " addl $64, %3\n"
29983@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29984 " shrl $2, %0\n"
29985 " andl $3, %%eax\n"
29986 " cld\n"
29987+ __COPYUSER_SET_ES
29988 "99: rep; movsl\n"
29989 "36: movl %%eax, %0\n"
29990 "37: rep; movsb\n"
29991 "100:\n"
29992+ __COPYUSER_RESTORE_ES
29993+ ".section .fixup,\"ax\"\n"
29994+ "101: lea 0(%%eax,%0,4),%0\n"
29995+ " jmp 100b\n"
29996+ ".previous\n"
29997+ _ASM_EXTABLE(1b,100b)
29998+ _ASM_EXTABLE(2b,100b)
29999+ _ASM_EXTABLE(3b,100b)
30000+ _ASM_EXTABLE(4b,100b)
30001+ _ASM_EXTABLE(5b,100b)
30002+ _ASM_EXTABLE(6b,100b)
30003+ _ASM_EXTABLE(7b,100b)
30004+ _ASM_EXTABLE(8b,100b)
30005+ _ASM_EXTABLE(9b,100b)
30006+ _ASM_EXTABLE(10b,100b)
30007+ _ASM_EXTABLE(11b,100b)
30008+ _ASM_EXTABLE(12b,100b)
30009+ _ASM_EXTABLE(13b,100b)
30010+ _ASM_EXTABLE(14b,100b)
30011+ _ASM_EXTABLE(15b,100b)
30012+ _ASM_EXTABLE(16b,100b)
30013+ _ASM_EXTABLE(17b,100b)
30014+ _ASM_EXTABLE(18b,100b)
30015+ _ASM_EXTABLE(19b,100b)
30016+ _ASM_EXTABLE(20b,100b)
30017+ _ASM_EXTABLE(21b,100b)
30018+ _ASM_EXTABLE(22b,100b)
30019+ _ASM_EXTABLE(23b,100b)
30020+ _ASM_EXTABLE(24b,100b)
30021+ _ASM_EXTABLE(25b,100b)
30022+ _ASM_EXTABLE(26b,100b)
30023+ _ASM_EXTABLE(27b,100b)
30024+ _ASM_EXTABLE(28b,100b)
30025+ _ASM_EXTABLE(29b,100b)
30026+ _ASM_EXTABLE(30b,100b)
30027+ _ASM_EXTABLE(31b,100b)
30028+ _ASM_EXTABLE(32b,100b)
30029+ _ASM_EXTABLE(33b,100b)
30030+ _ASM_EXTABLE(34b,100b)
30031+ _ASM_EXTABLE(35b,100b)
30032+ _ASM_EXTABLE(36b,100b)
30033+ _ASM_EXTABLE(37b,100b)
30034+ _ASM_EXTABLE(99b,101b)
30035+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30036+ : "1"(to), "2"(from), "0"(size)
30037+ : "eax", "edx", "memory");
30038+ return size;
30039+}
30040+
30041+static unsigned long
30042+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30043+{
30044+ int d0, d1;
30045+ __asm__ __volatile__(
30046+ " .align 2,0x90\n"
30047+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30048+ " cmpl $67, %0\n"
30049+ " jbe 3f\n"
30050+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30051+ " .align 2,0x90\n"
30052+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30053+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30054+ "5: movl %%eax, 0(%3)\n"
30055+ "6: movl %%edx, 4(%3)\n"
30056+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30057+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30058+ "9: movl %%eax, 8(%3)\n"
30059+ "10: movl %%edx, 12(%3)\n"
30060+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30061+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30062+ "13: movl %%eax, 16(%3)\n"
30063+ "14: movl %%edx, 20(%3)\n"
30064+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30065+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30066+ "17: movl %%eax, 24(%3)\n"
30067+ "18: movl %%edx, 28(%3)\n"
30068+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30069+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30070+ "21: movl %%eax, 32(%3)\n"
30071+ "22: movl %%edx, 36(%3)\n"
30072+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30073+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30074+ "25: movl %%eax, 40(%3)\n"
30075+ "26: movl %%edx, 44(%3)\n"
30076+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30077+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30078+ "29: movl %%eax, 48(%3)\n"
30079+ "30: movl %%edx, 52(%3)\n"
30080+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30081+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30082+ "33: movl %%eax, 56(%3)\n"
30083+ "34: movl %%edx, 60(%3)\n"
30084+ " addl $-64, %0\n"
30085+ " addl $64, %4\n"
30086+ " addl $64, %3\n"
30087+ " cmpl $63, %0\n"
30088+ " ja 1b\n"
30089+ "35: movl %0, %%eax\n"
30090+ " shrl $2, %0\n"
30091+ " andl $3, %%eax\n"
30092+ " cld\n"
30093+ "99: rep; "__copyuser_seg" movsl\n"
30094+ "36: movl %%eax, %0\n"
30095+ "37: rep; "__copyuser_seg" movsb\n"
30096+ "100:\n"
30097 ".section .fixup,\"ax\"\n"
30098 "101: lea 0(%%eax,%0,4),%0\n"
30099 " jmp 100b\n"
30100@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30101 int d0, d1;
30102 __asm__ __volatile__(
30103 " .align 2,0x90\n"
30104- "0: movl 32(%4), %%eax\n"
30105+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30106 " cmpl $67, %0\n"
30107 " jbe 2f\n"
30108- "1: movl 64(%4), %%eax\n"
30109+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30110 " .align 2,0x90\n"
30111- "2: movl 0(%4), %%eax\n"
30112- "21: movl 4(%4), %%edx\n"
30113+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30114+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30115 " movl %%eax, 0(%3)\n"
30116 " movl %%edx, 4(%3)\n"
30117- "3: movl 8(%4), %%eax\n"
30118- "31: movl 12(%4),%%edx\n"
30119+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30120+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30121 " movl %%eax, 8(%3)\n"
30122 " movl %%edx, 12(%3)\n"
30123- "4: movl 16(%4), %%eax\n"
30124- "41: movl 20(%4), %%edx\n"
30125+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30126+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30127 " movl %%eax, 16(%3)\n"
30128 " movl %%edx, 20(%3)\n"
30129- "10: movl 24(%4), %%eax\n"
30130- "51: movl 28(%4), %%edx\n"
30131+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30132+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30133 " movl %%eax, 24(%3)\n"
30134 " movl %%edx, 28(%3)\n"
30135- "11: movl 32(%4), %%eax\n"
30136- "61: movl 36(%4), %%edx\n"
30137+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30138+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30139 " movl %%eax, 32(%3)\n"
30140 " movl %%edx, 36(%3)\n"
30141- "12: movl 40(%4), %%eax\n"
30142- "71: movl 44(%4), %%edx\n"
30143+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30144+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30145 " movl %%eax, 40(%3)\n"
30146 " movl %%edx, 44(%3)\n"
30147- "13: movl 48(%4), %%eax\n"
30148- "81: movl 52(%4), %%edx\n"
30149+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30150+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30151 " movl %%eax, 48(%3)\n"
30152 " movl %%edx, 52(%3)\n"
30153- "14: movl 56(%4), %%eax\n"
30154- "91: movl 60(%4), %%edx\n"
30155+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30156+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30157 " movl %%eax, 56(%3)\n"
30158 " movl %%edx, 60(%3)\n"
30159 " addl $-64, %0\n"
30160@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30161 " shrl $2, %0\n"
30162 " andl $3, %%eax\n"
30163 " cld\n"
30164- "6: rep; movsl\n"
30165+ "6: rep; "__copyuser_seg" movsl\n"
30166 " movl %%eax,%0\n"
30167- "7: rep; movsb\n"
30168+ "7: rep; "__copyuser_seg" movsb\n"
30169 "8:\n"
30170 ".section .fixup,\"ax\"\n"
30171 "9: lea 0(%%eax,%0,4),%0\n"
30172@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30173
30174 __asm__ __volatile__(
30175 " .align 2,0x90\n"
30176- "0: movl 32(%4), %%eax\n"
30177+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30178 " cmpl $67, %0\n"
30179 " jbe 2f\n"
30180- "1: movl 64(%4), %%eax\n"
30181+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30182 " .align 2,0x90\n"
30183- "2: movl 0(%4), %%eax\n"
30184- "21: movl 4(%4), %%edx\n"
30185+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30186+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30187 " movnti %%eax, 0(%3)\n"
30188 " movnti %%edx, 4(%3)\n"
30189- "3: movl 8(%4), %%eax\n"
30190- "31: movl 12(%4),%%edx\n"
30191+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30192+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30193 " movnti %%eax, 8(%3)\n"
30194 " movnti %%edx, 12(%3)\n"
30195- "4: movl 16(%4), %%eax\n"
30196- "41: movl 20(%4), %%edx\n"
30197+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30198+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30199 " movnti %%eax, 16(%3)\n"
30200 " movnti %%edx, 20(%3)\n"
30201- "10: movl 24(%4), %%eax\n"
30202- "51: movl 28(%4), %%edx\n"
30203+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30204+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30205 " movnti %%eax, 24(%3)\n"
30206 " movnti %%edx, 28(%3)\n"
30207- "11: movl 32(%4), %%eax\n"
30208- "61: movl 36(%4), %%edx\n"
30209+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30210+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30211 " movnti %%eax, 32(%3)\n"
30212 " movnti %%edx, 36(%3)\n"
30213- "12: movl 40(%4), %%eax\n"
30214- "71: movl 44(%4), %%edx\n"
30215+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30216+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30217 " movnti %%eax, 40(%3)\n"
30218 " movnti %%edx, 44(%3)\n"
30219- "13: movl 48(%4), %%eax\n"
30220- "81: movl 52(%4), %%edx\n"
30221+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30222+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30223 " movnti %%eax, 48(%3)\n"
30224 " movnti %%edx, 52(%3)\n"
30225- "14: movl 56(%4), %%eax\n"
30226- "91: movl 60(%4), %%edx\n"
30227+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30228+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30229 " movnti %%eax, 56(%3)\n"
30230 " movnti %%edx, 60(%3)\n"
30231 " addl $-64, %0\n"
30232@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30233 " shrl $2, %0\n"
30234 " andl $3, %%eax\n"
30235 " cld\n"
30236- "6: rep; movsl\n"
30237+ "6: rep; "__copyuser_seg" movsl\n"
30238 " movl %%eax,%0\n"
30239- "7: rep; movsb\n"
30240+ "7: rep; "__copyuser_seg" movsb\n"
30241 "8:\n"
30242 ".section .fixup,\"ax\"\n"
30243 "9: lea 0(%%eax,%0,4),%0\n"
30244@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30245
30246 __asm__ __volatile__(
30247 " .align 2,0x90\n"
30248- "0: movl 32(%4), %%eax\n"
30249+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30250 " cmpl $67, %0\n"
30251 " jbe 2f\n"
30252- "1: movl 64(%4), %%eax\n"
30253+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30254 " .align 2,0x90\n"
30255- "2: movl 0(%4), %%eax\n"
30256- "21: movl 4(%4), %%edx\n"
30257+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30258+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30259 " movnti %%eax, 0(%3)\n"
30260 " movnti %%edx, 4(%3)\n"
30261- "3: movl 8(%4), %%eax\n"
30262- "31: movl 12(%4),%%edx\n"
30263+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30264+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30265 " movnti %%eax, 8(%3)\n"
30266 " movnti %%edx, 12(%3)\n"
30267- "4: movl 16(%4), %%eax\n"
30268- "41: movl 20(%4), %%edx\n"
30269+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30270+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30271 " movnti %%eax, 16(%3)\n"
30272 " movnti %%edx, 20(%3)\n"
30273- "10: movl 24(%4), %%eax\n"
30274- "51: movl 28(%4), %%edx\n"
30275+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30276+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30277 " movnti %%eax, 24(%3)\n"
30278 " movnti %%edx, 28(%3)\n"
30279- "11: movl 32(%4), %%eax\n"
30280- "61: movl 36(%4), %%edx\n"
30281+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30282+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30283 " movnti %%eax, 32(%3)\n"
30284 " movnti %%edx, 36(%3)\n"
30285- "12: movl 40(%4), %%eax\n"
30286- "71: movl 44(%4), %%edx\n"
30287+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30288+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30289 " movnti %%eax, 40(%3)\n"
30290 " movnti %%edx, 44(%3)\n"
30291- "13: movl 48(%4), %%eax\n"
30292- "81: movl 52(%4), %%edx\n"
30293+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30294+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30295 " movnti %%eax, 48(%3)\n"
30296 " movnti %%edx, 52(%3)\n"
30297- "14: movl 56(%4), %%eax\n"
30298- "91: movl 60(%4), %%edx\n"
30299+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30300+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30301 " movnti %%eax, 56(%3)\n"
30302 " movnti %%edx, 60(%3)\n"
30303 " addl $-64, %0\n"
30304@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30305 " shrl $2, %0\n"
30306 " andl $3, %%eax\n"
30307 " cld\n"
30308- "6: rep; movsl\n"
30309+ "6: rep; "__copyuser_seg" movsl\n"
30310 " movl %%eax,%0\n"
30311- "7: rep; movsb\n"
30312+ "7: rep; "__copyuser_seg" movsb\n"
30313 "8:\n"
30314 ".section .fixup,\"ax\"\n"
30315 "9: lea 0(%%eax,%0,4),%0\n"
30316@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30317 */
30318 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30319 unsigned long size);
30320-unsigned long __copy_user_intel(void __user *to, const void *from,
30321+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30322+ unsigned long size);
30323+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30324 unsigned long size);
30325 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30326 const void __user *from, unsigned long size);
30327 #endif /* CONFIG_X86_INTEL_USERCOPY */
30328
30329 /* Generic arbitrary sized copy. */
30330-#define __copy_user(to, from, size) \
30331+#define __copy_user(to, from, size, prefix, set, restore) \
30332 do { \
30333 int __d0, __d1, __d2; \
30334 __asm__ __volatile__( \
30335+ set \
30336 " cmp $7,%0\n" \
30337 " jbe 1f\n" \
30338 " movl %1,%0\n" \
30339 " negl %0\n" \
30340 " andl $7,%0\n" \
30341 " subl %0,%3\n" \
30342- "4: rep; movsb\n" \
30343+ "4: rep; "prefix"movsb\n" \
30344 " movl %3,%0\n" \
30345 " shrl $2,%0\n" \
30346 " andl $3,%3\n" \
30347 " .align 2,0x90\n" \
30348- "0: rep; movsl\n" \
30349+ "0: rep; "prefix"movsl\n" \
30350 " movl %3,%0\n" \
30351- "1: rep; movsb\n" \
30352+ "1: rep; "prefix"movsb\n" \
30353 "2:\n" \
30354+ restore \
30355 ".section .fixup,\"ax\"\n" \
30356 "5: addl %3,%0\n" \
30357 " jmp 2b\n" \
30358@@ -538,14 +650,14 @@ do { \
30359 " negl %0\n" \
30360 " andl $7,%0\n" \
30361 " subl %0,%3\n" \
30362- "4: rep; movsb\n" \
30363+ "4: rep; "__copyuser_seg"movsb\n" \
30364 " movl %3,%0\n" \
30365 " shrl $2,%0\n" \
30366 " andl $3,%3\n" \
30367 " .align 2,0x90\n" \
30368- "0: rep; movsl\n" \
30369+ "0: rep; "__copyuser_seg"movsl\n" \
30370 " movl %3,%0\n" \
30371- "1: rep; movsb\n" \
30372+ "1: rep; "__copyuser_seg"movsb\n" \
30373 "2:\n" \
30374 ".section .fixup,\"ax\"\n" \
30375 "5: addl %3,%0\n" \
30376@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30377 {
30378 stac();
30379 if (movsl_is_ok(to, from, n))
30380- __copy_user(to, from, n);
30381+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30382 else
30383- n = __copy_user_intel(to, from, n);
30384+ n = __generic_copy_to_user_intel(to, from, n);
30385 clac();
30386 return n;
30387 }
30388@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30389 {
30390 stac();
30391 if (movsl_is_ok(to, from, n))
30392- __copy_user(to, from, n);
30393+ __copy_user(to, from, n, __copyuser_seg, "", "");
30394 else
30395- n = __copy_user_intel((void __user *)to,
30396- (const void *)from, n);
30397+ n = __generic_copy_from_user_intel(to, from, n);
30398 clac();
30399 return n;
30400 }
30401@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30402 if (n > 64 && cpu_has_xmm2)
30403 n = __copy_user_intel_nocache(to, from, n);
30404 else
30405- __copy_user(to, from, n);
30406+ __copy_user(to, from, n, __copyuser_seg, "", "");
30407 #else
30408- __copy_user(to, from, n);
30409+ __copy_user(to, from, n, __copyuser_seg, "", "");
30410 #endif
30411 clac();
30412 return n;
30413 }
30414 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30415
30416-/**
30417- * copy_to_user: - Copy a block of data into user space.
30418- * @to: Destination address, in user space.
30419- * @from: Source address, in kernel space.
30420- * @n: Number of bytes to copy.
30421- *
30422- * Context: User context only. This function may sleep.
30423- *
30424- * Copy data from kernel space to user space.
30425- *
30426- * Returns number of bytes that could not be copied.
30427- * On success, this will be zero.
30428- */
30429-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30430+#ifdef CONFIG_PAX_MEMORY_UDEREF
30431+void __set_fs(mm_segment_t x)
30432 {
30433- if (access_ok(VERIFY_WRITE, to, n))
30434- n = __copy_to_user(to, from, n);
30435- return n;
30436+ switch (x.seg) {
30437+ case 0:
30438+ loadsegment(gs, 0);
30439+ break;
30440+ case TASK_SIZE_MAX:
30441+ loadsegment(gs, __USER_DS);
30442+ break;
30443+ case -1UL:
30444+ loadsegment(gs, __KERNEL_DS);
30445+ break;
30446+ default:
30447+ BUG();
30448+ }
30449 }
30450-EXPORT_SYMBOL(_copy_to_user);
30451+EXPORT_SYMBOL(__set_fs);
30452
30453-/**
30454- * copy_from_user: - Copy a block of data from user space.
30455- * @to: Destination address, in kernel space.
30456- * @from: Source address, in user space.
30457- * @n: Number of bytes to copy.
30458- *
30459- * Context: User context only. This function may sleep.
30460- *
30461- * Copy data from user space to kernel space.
30462- *
30463- * Returns number of bytes that could not be copied.
30464- * On success, this will be zero.
30465- *
30466- * If some data could not be copied, this function will pad the copied
30467- * data to the requested size using zero bytes.
30468- */
30469-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
30470+void set_fs(mm_segment_t x)
30471 {
30472- if (access_ok(VERIFY_READ, from, n))
30473- n = __copy_from_user(to, from, n);
30474- else
30475- memset(to, 0, n);
30476- return n;
30477+ current_thread_info()->addr_limit = x;
30478+ __set_fs(x);
30479 }
30480-EXPORT_SYMBOL(_copy_from_user);
30481+EXPORT_SYMBOL(set_fs);
30482+#endif
30483diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30484index c905e89..01ab928 100644
30485--- a/arch/x86/lib/usercopy_64.c
30486+++ b/arch/x86/lib/usercopy_64.c
30487@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30488 might_fault();
30489 /* no memory constraint because it doesn't change any memory gcc knows
30490 about */
30491+ pax_open_userland();
30492 stac();
30493 asm volatile(
30494 " testq %[size8],%[size8]\n"
30495@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30496 _ASM_EXTABLE(0b,3b)
30497 _ASM_EXTABLE(1b,2b)
30498 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30499- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30500+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30501 [zero] "r" (0UL), [eight] "r" (8UL));
30502 clac();
30503+ pax_close_userland();
30504 return size;
30505 }
30506 EXPORT_SYMBOL(__clear_user);
30507@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30508 }
30509 EXPORT_SYMBOL(clear_user);
30510
30511-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30512+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30513 {
30514- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30515- return copy_user_generic((__force void *)to, (__force void *)from, len);
30516- }
30517- return len;
30518+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30519+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30520+ return len;
30521 }
30522 EXPORT_SYMBOL(copy_in_user);
30523
30524@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30525 * it is not necessary to optimize tail handling.
30526 */
30527 __visible unsigned long
30528-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30529+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30530 {
30531 char c;
30532 unsigned zero_len;
30533
30534+ clac();
30535+ pax_close_userland();
30536 for (; len; --len, to++) {
30537 if (__get_user_nocheck(c, from++, sizeof(char)))
30538 break;
30539@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30540 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30541 if (__put_user_nocheck(c, to++, sizeof(char)))
30542 break;
30543- clac();
30544 return len;
30545 }
30546diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30547index 6a19ad9..1c48f9a 100644
30548--- a/arch/x86/mm/Makefile
30549+++ b/arch/x86/mm/Makefile
30550@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30551 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30552
30553 obj-$(CONFIG_MEMTEST) += memtest.o
30554+
30555+quote:="
30556+obj-$(CONFIG_X86_64) += uderef_64.o
30557+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30558diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30559index 903ec1e..c4166b2 100644
30560--- a/arch/x86/mm/extable.c
30561+++ b/arch/x86/mm/extable.c
30562@@ -6,12 +6,24 @@
30563 static inline unsigned long
30564 ex_insn_addr(const struct exception_table_entry *x)
30565 {
30566- return (unsigned long)&x->insn + x->insn;
30567+ unsigned long reloc = 0;
30568+
30569+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30570+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30571+#endif
30572+
30573+ return (unsigned long)&x->insn + x->insn + reloc;
30574 }
30575 static inline unsigned long
30576 ex_fixup_addr(const struct exception_table_entry *x)
30577 {
30578- return (unsigned long)&x->fixup + x->fixup;
30579+ unsigned long reloc = 0;
30580+
30581+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30582+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30583+#endif
30584+
30585+ return (unsigned long)&x->fixup + x->fixup + reloc;
30586 }
30587
30588 int fixup_exception(struct pt_regs *regs)
30589@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30590 unsigned long new_ip;
30591
30592 #ifdef CONFIG_PNPBIOS
30593- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30594+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30595 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30596 extern u32 pnp_bios_is_utter_crap;
30597 pnp_bios_is_utter_crap = 1;
30598@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30599 i += 4;
30600 p->fixup -= i;
30601 i += 4;
30602+
30603+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30604+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30605+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30606+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30607+#endif
30608+
30609 }
30610 }
30611
30612diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30613index 9d591c8..2e61790 100644
30614--- a/arch/x86/mm/fault.c
30615+++ b/arch/x86/mm/fault.c
30616@@ -14,11 +14,18 @@
30617 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30618 #include <linux/prefetch.h> /* prefetchw */
30619 #include <linux/context_tracking.h> /* exception_enter(), ... */
30620+#include <linux/unistd.h>
30621+#include <linux/compiler.h>
30622
30623 #include <asm/traps.h> /* dotraplinkage, ... */
30624 #include <asm/pgalloc.h> /* pgd_*(), ... */
30625 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30626 #include <asm/fixmap.h> /* VSYSCALL_START */
30627+#include <asm/tlbflush.h>
30628+
30629+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30630+#include <asm/stacktrace.h>
30631+#endif
30632
30633 #define CREATE_TRACE_POINTS
30634 #include <asm/trace/exceptions.h>
30635@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
30636 int ret = 0;
30637
30638 /* kprobe_running() needs smp_processor_id() */
30639- if (kprobes_built_in() && !user_mode_vm(regs)) {
30640+ if (kprobes_built_in() && !user_mode(regs)) {
30641 preempt_disable();
30642 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30643 ret = 1;
30644@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30645 return !instr_lo || (instr_lo>>1) == 1;
30646 case 0x00:
30647 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30648- if (probe_kernel_address(instr, opcode))
30649+ if (user_mode(regs)) {
30650+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30651+ return 0;
30652+ } else if (probe_kernel_address(instr, opcode))
30653 return 0;
30654
30655 *prefetch = (instr_lo == 0xF) &&
30656@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30657 while (instr < max_instr) {
30658 unsigned char opcode;
30659
30660- if (probe_kernel_address(instr, opcode))
30661+ if (user_mode(regs)) {
30662+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30663+ break;
30664+ } else if (probe_kernel_address(instr, opcode))
30665 break;
30666
30667 instr++;
30668@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30669 force_sig_info(si_signo, &info, tsk);
30670 }
30671
30672+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30673+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30674+#endif
30675+
30676+#ifdef CONFIG_PAX_EMUTRAMP
30677+static int pax_handle_fetch_fault(struct pt_regs *regs);
30678+#endif
30679+
30680+#ifdef CONFIG_PAX_PAGEEXEC
30681+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30682+{
30683+ pgd_t *pgd;
30684+ pud_t *pud;
30685+ pmd_t *pmd;
30686+
30687+ pgd = pgd_offset(mm, address);
30688+ if (!pgd_present(*pgd))
30689+ return NULL;
30690+ pud = pud_offset(pgd, address);
30691+ if (!pud_present(*pud))
30692+ return NULL;
30693+ pmd = pmd_offset(pud, address);
30694+ if (!pmd_present(*pmd))
30695+ return NULL;
30696+ return pmd;
30697+}
30698+#endif
30699+
30700 DEFINE_SPINLOCK(pgd_lock);
30701 LIST_HEAD(pgd_list);
30702
30703@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
30704 for (address = VMALLOC_START & PMD_MASK;
30705 address >= TASK_SIZE && address < FIXADDR_TOP;
30706 address += PMD_SIZE) {
30707+
30708+#ifdef CONFIG_PAX_PER_CPU_PGD
30709+ unsigned long cpu;
30710+#else
30711 struct page *page;
30712+#endif
30713
30714 spin_lock(&pgd_lock);
30715+
30716+#ifdef CONFIG_PAX_PER_CPU_PGD
30717+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30718+ pgd_t *pgd = get_cpu_pgd(cpu, user);
30719+ pmd_t *ret;
30720+
30721+ ret = vmalloc_sync_one(pgd, address);
30722+ if (!ret)
30723+ break;
30724+ pgd = get_cpu_pgd(cpu, kernel);
30725+#else
30726 list_for_each_entry(page, &pgd_list, lru) {
30727+ pgd_t *pgd;
30728 spinlock_t *pgt_lock;
30729 pmd_t *ret;
30730
30731@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
30732 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30733
30734 spin_lock(pgt_lock);
30735- ret = vmalloc_sync_one(page_address(page), address);
30736+ pgd = page_address(page);
30737+#endif
30738+
30739+ ret = vmalloc_sync_one(pgd, address);
30740+
30741+#ifndef CONFIG_PAX_PER_CPU_PGD
30742 spin_unlock(pgt_lock);
30743+#endif
30744
30745 if (!ret)
30746 break;
30747@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30748 * an interrupt in the middle of a task switch..
30749 */
30750 pgd_paddr = read_cr3();
30751+
30752+#ifdef CONFIG_PAX_PER_CPU_PGD
30753+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30754+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30755+#endif
30756+
30757 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30758 if (!pmd_k)
30759 return -1;
30760@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30761 * happen within a race in page table update. In the later
30762 * case just flush:
30763 */
30764- pgd = pgd_offset(current->active_mm, address);
30765+
30766 pgd_ref = pgd_offset_k(address);
30767 if (pgd_none(*pgd_ref))
30768 return -1;
30769
30770+#ifdef CONFIG_PAX_PER_CPU_PGD
30771+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30772+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30773+ if (pgd_none(*pgd)) {
30774+ set_pgd(pgd, *pgd_ref);
30775+ arch_flush_lazy_mmu_mode();
30776+ } else {
30777+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30778+ }
30779+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30780+#else
30781+ pgd = pgd_offset(current->active_mm, address);
30782+#endif
30783+
30784 if (pgd_none(*pgd)) {
30785 set_pgd(pgd, *pgd_ref);
30786 arch_flush_lazy_mmu_mode();
30787@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30788 static int is_errata100(struct pt_regs *regs, unsigned long address)
30789 {
30790 #ifdef CONFIG_X86_64
30791- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30792+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30793 return 1;
30794 #endif
30795 return 0;
30796@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30797 }
30798
30799 static const char nx_warning[] = KERN_CRIT
30800-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30801+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30802
30803 static void
30804 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30805@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30806 if (!oops_may_print())
30807 return;
30808
30809- if (error_code & PF_INSTR) {
30810+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30811 unsigned int level;
30812
30813 pte_t *pte = lookup_address(address, &level);
30814
30815 if (pte && pte_present(*pte) && !pte_exec(*pte))
30816- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30817+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30818 }
30819
30820+#ifdef CONFIG_PAX_KERNEXEC
30821+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30822+ if (current->signal->curr_ip)
30823+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30824+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30825+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30826+ else
30827+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30828+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30829+ }
30830+#endif
30831+
30832 printk(KERN_ALERT "BUG: unable to handle kernel ");
30833 if (address < PAGE_SIZE)
30834 printk(KERN_CONT "NULL pointer dereference");
30835@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30836 return;
30837 }
30838 #endif
30839+
30840+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30841+ if (pax_is_fetch_fault(regs, error_code, address)) {
30842+
30843+#ifdef CONFIG_PAX_EMUTRAMP
30844+ switch (pax_handle_fetch_fault(regs)) {
30845+ case 2:
30846+ return;
30847+ }
30848+#endif
30849+
30850+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30851+ do_group_exit(SIGKILL);
30852+ }
30853+#endif
30854+
30855 /* Kernel addresses are always protection faults: */
30856 if (address >= TASK_SIZE)
30857 error_code |= PF_PROT;
30858@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30859 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30860 printk(KERN_ERR
30861 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30862- tsk->comm, tsk->pid, address);
30863+ tsk->comm, task_pid_nr(tsk), address);
30864 code = BUS_MCEERR_AR;
30865 }
30866 #endif
30867@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30868 return 1;
30869 }
30870
30871+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30872+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30873+{
30874+ pte_t *pte;
30875+ pmd_t *pmd;
30876+ spinlock_t *ptl;
30877+ unsigned char pte_mask;
30878+
30879+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30880+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30881+ return 0;
30882+
30883+ /* PaX: it's our fault, let's handle it if we can */
30884+
30885+ /* PaX: take a look at read faults before acquiring any locks */
30886+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30887+ /* instruction fetch attempt from a protected page in user mode */
30888+ up_read(&mm->mmap_sem);
30889+
30890+#ifdef CONFIG_PAX_EMUTRAMP
30891+ switch (pax_handle_fetch_fault(regs)) {
30892+ case 2:
30893+ return 1;
30894+ }
30895+#endif
30896+
30897+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30898+ do_group_exit(SIGKILL);
30899+ }
30900+
30901+ pmd = pax_get_pmd(mm, address);
30902+ if (unlikely(!pmd))
30903+ return 0;
30904+
30905+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30906+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30907+ pte_unmap_unlock(pte, ptl);
30908+ return 0;
30909+ }
30910+
30911+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30912+ /* write attempt to a protected page in user mode */
30913+ pte_unmap_unlock(pte, ptl);
30914+ return 0;
30915+ }
30916+
30917+#ifdef CONFIG_SMP
30918+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30919+#else
30920+ if (likely(address > get_limit(regs->cs)))
30921+#endif
30922+ {
30923+ set_pte(pte, pte_mkread(*pte));
30924+ __flush_tlb_one(address);
30925+ pte_unmap_unlock(pte, ptl);
30926+ up_read(&mm->mmap_sem);
30927+ return 1;
30928+ }
30929+
30930+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30931+
30932+ /*
30933+ * PaX: fill DTLB with user rights and retry
30934+ */
30935+ __asm__ __volatile__ (
30936+ "orb %2,(%1)\n"
30937+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30938+/*
30939+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30940+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30941+ * page fault when examined during a TLB load attempt. this is true not only
30942+ * for PTEs holding a non-present entry but also present entries that will
30943+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30944+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30945+ * for our target pages since their PTEs are simply not in the TLBs at all.
30946+
30947+ * the best thing in omitting it is that we gain around 15-20% speed in the
30948+ * fast path of the page fault handler and can get rid of tracing since we
30949+ * can no longer flush unintended entries.
30950+ */
30951+ "invlpg (%0)\n"
30952+#endif
30953+ __copyuser_seg"testb $0,(%0)\n"
30954+ "xorb %3,(%1)\n"
30955+ :
30956+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30957+ : "memory", "cc");
30958+ pte_unmap_unlock(pte, ptl);
30959+ up_read(&mm->mmap_sem);
30960+ return 1;
30961+}
30962+#endif
30963+
30964 /*
30965 * Handle a spurious fault caused by a stale TLB entry.
30966 *
30967@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
30968 static inline int
30969 access_error(unsigned long error_code, struct vm_area_struct *vma)
30970 {
30971+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30972+ return 1;
30973+
30974 if (error_code & PF_WRITE) {
30975 /* write, present and write, not present: */
30976 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30977@@ -1004,7 +1212,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30978 if (error_code & PF_USER)
30979 return false;
30980
30981- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30982+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30983 return false;
30984
30985 return true;
30986@@ -1031,6 +1239,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30987 /* Get the faulting address: */
30988 address = read_cr2();
30989
30990+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30991+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30992+ if (!search_exception_tables(regs->ip)) {
30993+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30994+ bad_area_nosemaphore(regs, error_code, address);
30995+ return;
30996+ }
30997+ if (address < pax_user_shadow_base) {
30998+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30999+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31000+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31001+ } else
31002+ address -= pax_user_shadow_base;
31003+ }
31004+#endif
31005+
31006 /*
31007 * Detect and handle instructions that would cause a page fault for
31008 * both a tracked kernel page and a userspace page.
31009@@ -1110,7 +1334,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31010 * User-mode registers count as a user access even for any
31011 * potential system fault or CPU buglet:
31012 */
31013- if (user_mode_vm(regs)) {
31014+ if (user_mode(regs)) {
31015 local_irq_enable();
31016 error_code |= PF_USER;
31017 flags |= FAULT_FLAG_USER;
31018@@ -1157,6 +1381,11 @@ retry:
31019 might_sleep();
31020 }
31021
31022+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31023+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31024+ return;
31025+#endif
31026+
31027 vma = find_vma(mm, address);
31028 if (unlikely(!vma)) {
31029 bad_area(regs, error_code, address);
31030@@ -1168,18 +1397,24 @@ retry:
31031 bad_area(regs, error_code, address);
31032 return;
31033 }
31034- if (error_code & PF_USER) {
31035- /*
31036- * Accessing the stack below %sp is always a bug.
31037- * The large cushion allows instructions like enter
31038- * and pusha to work. ("enter $65535, $31" pushes
31039- * 32 pointers and then decrements %sp by 65535.)
31040- */
31041- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31042- bad_area(regs, error_code, address);
31043- return;
31044- }
31045+ /*
31046+ * Accessing the stack below %sp is always a bug.
31047+ * The large cushion allows instructions like enter
31048+ * and pusha to work. ("enter $65535, $31" pushes
31049+ * 32 pointers and then decrements %sp by 65535.)
31050+ */
31051+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31052+ bad_area(regs, error_code, address);
31053+ return;
31054 }
31055+
31056+#ifdef CONFIG_PAX_SEGMEXEC
31057+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31058+ bad_area(regs, error_code, address);
31059+ return;
31060+ }
31061+#endif
31062+
31063 if (unlikely(expand_stack(vma, address))) {
31064 bad_area(regs, error_code, address);
31065 return;
31066@@ -1273,3 +1508,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31067 __do_page_fault(regs, error_code);
31068 exception_exit(prev_state);
31069 }
31070+
31071+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31072+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31073+{
31074+ struct mm_struct *mm = current->mm;
31075+ unsigned long ip = regs->ip;
31076+
31077+ if (v8086_mode(regs))
31078+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31079+
31080+#ifdef CONFIG_PAX_PAGEEXEC
31081+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31082+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31083+ return true;
31084+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31085+ return true;
31086+ return false;
31087+ }
31088+#endif
31089+
31090+#ifdef CONFIG_PAX_SEGMEXEC
31091+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31092+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31093+ return true;
31094+ return false;
31095+ }
31096+#endif
31097+
31098+ return false;
31099+}
31100+#endif
31101+
31102+#ifdef CONFIG_PAX_EMUTRAMP
31103+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31104+{
31105+ int err;
31106+
31107+ do { /* PaX: libffi trampoline emulation */
31108+ unsigned char mov, jmp;
31109+ unsigned int addr1, addr2;
31110+
31111+#ifdef CONFIG_X86_64
31112+ if ((regs->ip + 9) >> 32)
31113+ break;
31114+#endif
31115+
31116+ err = get_user(mov, (unsigned char __user *)regs->ip);
31117+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31118+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31119+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31120+
31121+ if (err)
31122+ break;
31123+
31124+ if (mov == 0xB8 && jmp == 0xE9) {
31125+ regs->ax = addr1;
31126+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31127+ return 2;
31128+ }
31129+ } while (0);
31130+
31131+ do { /* PaX: gcc trampoline emulation #1 */
31132+ unsigned char mov1, mov2;
31133+ unsigned short jmp;
31134+ unsigned int addr1, addr2;
31135+
31136+#ifdef CONFIG_X86_64
31137+ if ((regs->ip + 11) >> 32)
31138+ break;
31139+#endif
31140+
31141+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31142+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31143+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31144+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31145+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31146+
31147+ if (err)
31148+ break;
31149+
31150+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31151+ regs->cx = addr1;
31152+ regs->ax = addr2;
31153+ regs->ip = addr2;
31154+ return 2;
31155+ }
31156+ } while (0);
31157+
31158+ do { /* PaX: gcc trampoline emulation #2 */
31159+ unsigned char mov, jmp;
31160+ unsigned int addr1, addr2;
31161+
31162+#ifdef CONFIG_X86_64
31163+ if ((regs->ip + 9) >> 32)
31164+ break;
31165+#endif
31166+
31167+ err = get_user(mov, (unsigned char __user *)regs->ip);
31168+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31169+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31170+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31171+
31172+ if (err)
31173+ break;
31174+
31175+ if (mov == 0xB9 && jmp == 0xE9) {
31176+ regs->cx = addr1;
31177+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31178+ return 2;
31179+ }
31180+ } while (0);
31181+
31182+ return 1; /* PaX in action */
31183+}
31184+
31185+#ifdef CONFIG_X86_64
31186+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31187+{
31188+ int err;
31189+
31190+ do { /* PaX: libffi trampoline emulation */
31191+ unsigned short mov1, mov2, jmp1;
31192+ unsigned char stcclc, jmp2;
31193+ unsigned long addr1, addr2;
31194+
31195+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31196+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31197+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31198+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31199+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31200+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31201+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31202+
31203+ if (err)
31204+ break;
31205+
31206+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31207+ regs->r11 = addr1;
31208+ regs->r10 = addr2;
31209+ if (stcclc == 0xF8)
31210+ regs->flags &= ~X86_EFLAGS_CF;
31211+ else
31212+ regs->flags |= X86_EFLAGS_CF;
31213+ regs->ip = addr1;
31214+ return 2;
31215+ }
31216+ } while (0);
31217+
31218+ do { /* PaX: gcc trampoline emulation #1 */
31219+ unsigned short mov1, mov2, jmp1;
31220+ unsigned char jmp2;
31221+ unsigned int addr1;
31222+ unsigned long addr2;
31223+
31224+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31225+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31226+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31227+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31228+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31229+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31230+
31231+ if (err)
31232+ break;
31233+
31234+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31235+ regs->r11 = addr1;
31236+ regs->r10 = addr2;
31237+ regs->ip = addr1;
31238+ return 2;
31239+ }
31240+ } while (0);
31241+
31242+ do { /* PaX: gcc trampoline emulation #2 */
31243+ unsigned short mov1, mov2, jmp1;
31244+ unsigned char jmp2;
31245+ unsigned long addr1, addr2;
31246+
31247+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31248+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31249+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31250+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31251+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31252+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31253+
31254+ if (err)
31255+ break;
31256+
31257+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31258+ regs->r11 = addr1;
31259+ regs->r10 = addr2;
31260+ regs->ip = addr1;
31261+ return 2;
31262+ }
31263+ } while (0);
31264+
31265+ return 1; /* PaX in action */
31266+}
31267+#endif
31268+
31269+/*
31270+ * PaX: decide what to do with offenders (regs->ip = fault address)
31271+ *
31272+ * returns 1 when task should be killed
31273+ * 2 when gcc trampoline was detected
31274+ */
31275+static int pax_handle_fetch_fault(struct pt_regs *regs)
31276+{
31277+ if (v8086_mode(regs))
31278+ return 1;
31279+
31280+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31281+ return 1;
31282+
31283+#ifdef CONFIG_X86_32
31284+ return pax_handle_fetch_fault_32(regs);
31285+#else
31286+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31287+ return pax_handle_fetch_fault_32(regs);
31288+ else
31289+ return pax_handle_fetch_fault_64(regs);
31290+#endif
31291+}
31292+#endif
31293+
31294+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31295+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31296+{
31297+ long i;
31298+
31299+ printk(KERN_ERR "PAX: bytes at PC: ");
31300+ for (i = 0; i < 20; i++) {
31301+ unsigned char c;
31302+ if (get_user(c, (unsigned char __force_user *)pc+i))
31303+ printk(KERN_CONT "?? ");
31304+ else
31305+ printk(KERN_CONT "%02x ", c);
31306+ }
31307+ printk("\n");
31308+
31309+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31310+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31311+ unsigned long c;
31312+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31313+#ifdef CONFIG_X86_32
31314+ printk(KERN_CONT "???????? ");
31315+#else
31316+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31317+ printk(KERN_CONT "???????? ???????? ");
31318+ else
31319+ printk(KERN_CONT "???????????????? ");
31320+#endif
31321+ } else {
31322+#ifdef CONFIG_X86_64
31323+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31324+ printk(KERN_CONT "%08x ", (unsigned int)c);
31325+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31326+ } else
31327+#endif
31328+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31329+ }
31330+ }
31331+ printk("\n");
31332+}
31333+#endif
31334+
31335+/**
31336+ * probe_kernel_write(): safely attempt to write to a location
31337+ * @dst: address to write to
31338+ * @src: pointer to the data that shall be written
31339+ * @size: size of the data chunk
31340+ *
31341+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31342+ * happens, handle that and return -EFAULT.
31343+ */
31344+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31345+{
31346+ long ret;
31347+ mm_segment_t old_fs = get_fs();
31348+
31349+ set_fs(KERNEL_DS);
31350+ pagefault_disable();
31351+ pax_open_kernel();
31352+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31353+ pax_close_kernel();
31354+ pagefault_enable();
31355+ set_fs(old_fs);
31356+
31357+ return ret ? -EFAULT : 0;
31358+}
31359diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31360index 0596e8e..9de0b1c 100644
31361--- a/arch/x86/mm/gup.c
31362+++ b/arch/x86/mm/gup.c
31363@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31364 addr = start;
31365 len = (unsigned long) nr_pages << PAGE_SHIFT;
31366 end = start + len;
31367- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31368+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31369 (void __user *)start, len)))
31370 return 0;
31371
31372@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31373 goto slow_irqon;
31374 #endif
31375
31376+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31377+ (void __user *)start, len)))
31378+ return 0;
31379+
31380 /*
31381 * XXX: batch / limit 'nr', to avoid large irq off latency
31382 * needs some instrumenting to determine the common sizes used by
31383diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31384index 4500142..53a363c 100644
31385--- a/arch/x86/mm/highmem_32.c
31386+++ b/arch/x86/mm/highmem_32.c
31387@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31388 idx = type + KM_TYPE_NR*smp_processor_id();
31389 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31390 BUG_ON(!pte_none(*(kmap_pte-idx)));
31391+
31392+ pax_open_kernel();
31393 set_pte(kmap_pte-idx, mk_pte(page, prot));
31394+ pax_close_kernel();
31395+
31396 arch_flush_lazy_mmu_mode();
31397
31398 return (void *)vaddr;
31399diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31400index 9d980d8..6bbfacb 100644
31401--- a/arch/x86/mm/hugetlbpage.c
31402+++ b/arch/x86/mm/hugetlbpage.c
31403@@ -92,23 +92,30 @@ int pmd_huge_support(void)
31404 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31405 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31406 unsigned long addr, unsigned long len,
31407- unsigned long pgoff, unsigned long flags)
31408+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31409 {
31410 struct hstate *h = hstate_file(file);
31411 struct vm_unmapped_area_info info;
31412-
31413+
31414 info.flags = 0;
31415 info.length = len;
31416 info.low_limit = TASK_UNMAPPED_BASE;
31417+
31418+#ifdef CONFIG_PAX_RANDMMAP
31419+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31420+ info.low_limit += current->mm->delta_mmap;
31421+#endif
31422+
31423 info.high_limit = TASK_SIZE;
31424 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31425 info.align_offset = 0;
31426+ info.threadstack_offset = offset;
31427 return vm_unmapped_area(&info);
31428 }
31429
31430 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31431 unsigned long addr0, unsigned long len,
31432- unsigned long pgoff, unsigned long flags)
31433+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31434 {
31435 struct hstate *h = hstate_file(file);
31436 struct vm_unmapped_area_info info;
31437@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31438 info.high_limit = current->mm->mmap_base;
31439 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31440 info.align_offset = 0;
31441+ info.threadstack_offset = offset;
31442 addr = vm_unmapped_area(&info);
31443
31444 /*
31445@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31446 VM_BUG_ON(addr != -ENOMEM);
31447 info.flags = 0;
31448 info.low_limit = TASK_UNMAPPED_BASE;
31449+
31450+#ifdef CONFIG_PAX_RANDMMAP
31451+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31452+ info.low_limit += current->mm->delta_mmap;
31453+#endif
31454+
31455 info.high_limit = TASK_SIZE;
31456 addr = vm_unmapped_area(&info);
31457 }
31458@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31459 struct hstate *h = hstate_file(file);
31460 struct mm_struct *mm = current->mm;
31461 struct vm_area_struct *vma;
31462+ unsigned long pax_task_size = TASK_SIZE;
31463+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31464
31465 if (len & ~huge_page_mask(h))
31466 return -EINVAL;
31467- if (len > TASK_SIZE)
31468+
31469+#ifdef CONFIG_PAX_SEGMEXEC
31470+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31471+ pax_task_size = SEGMEXEC_TASK_SIZE;
31472+#endif
31473+
31474+ pax_task_size -= PAGE_SIZE;
31475+
31476+ if (len > pax_task_size)
31477 return -ENOMEM;
31478
31479 if (flags & MAP_FIXED) {
31480@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31481 return addr;
31482 }
31483
31484+#ifdef CONFIG_PAX_RANDMMAP
31485+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31486+#endif
31487+
31488 if (addr) {
31489 addr = ALIGN(addr, huge_page_size(h));
31490 vma = find_vma(mm, addr);
31491- if (TASK_SIZE - len >= addr &&
31492- (!vma || addr + len <= vma->vm_start))
31493+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31494 return addr;
31495 }
31496 if (mm->get_unmapped_area == arch_get_unmapped_area)
31497 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31498- pgoff, flags);
31499+ pgoff, flags, offset);
31500 else
31501 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31502- pgoff, flags);
31503+ pgoff, flags, offset);
31504 }
31505
31506 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31507diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31508index f971306..e83e0f6 100644
31509--- a/arch/x86/mm/init.c
31510+++ b/arch/x86/mm/init.c
31511@@ -4,6 +4,7 @@
31512 #include <linux/swap.h>
31513 #include <linux/memblock.h>
31514 #include <linux/bootmem.h> /* for max_low_pfn */
31515+#include <linux/tboot.h>
31516
31517 #include <asm/cacheflush.h>
31518 #include <asm/e820.h>
31519@@ -17,6 +18,8 @@
31520 #include <asm/proto.h>
31521 #include <asm/dma.h> /* for MAX_DMA_PFN */
31522 #include <asm/microcode.h>
31523+#include <asm/desc.h>
31524+#include <asm/bios_ebda.h>
31525
31526 #include "mm_internal.h"
31527
31528@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
31529 early_ioremap_page_table_range_init();
31530 #endif
31531
31532+#ifdef CONFIG_PAX_PER_CPU_PGD
31533+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31534+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31535+ KERNEL_PGD_PTRS);
31536+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31537+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31538+ KERNEL_PGD_PTRS);
31539+ load_cr3(get_cpu_pgd(0, kernel));
31540+#else
31541 load_cr3(swapper_pg_dir);
31542+#endif
31543+
31544 __flush_tlb_all();
31545
31546 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31547@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
31548 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31549 * mmio resources as well as potential bios/acpi data regions.
31550 */
31551+
31552+#ifdef CONFIG_GRKERNSEC_KMEM
31553+static unsigned int ebda_start __read_only;
31554+static unsigned int ebda_end __read_only;
31555+#endif
31556+
31557 int devmem_is_allowed(unsigned long pagenr)
31558 {
31559- if (pagenr < 256)
31560+#ifdef CONFIG_GRKERNSEC_KMEM
31561+ /* allow BDA */
31562+ if (!pagenr)
31563 return 1;
31564+ /* allow EBDA */
31565+ if (pagenr >= ebda_start && pagenr < ebda_end)
31566+ return 1;
31567+ /* if tboot is in use, allow access to its hardcoded serial log range */
31568+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31569+ return 1;
31570+#else
31571+ if (!pagenr)
31572+ return 1;
31573+#ifdef CONFIG_VM86
31574+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31575+ return 1;
31576+#endif
31577+#endif
31578+
31579+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31580+ return 1;
31581+#ifdef CONFIG_GRKERNSEC_KMEM
31582+ /* throw out everything else below 1MB */
31583+ if (pagenr <= 256)
31584+ return 0;
31585+#endif
31586 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31587 return 0;
31588 if (!page_is_ram(pagenr))
31589@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31590 #endif
31591 }
31592
31593+#ifdef CONFIG_GRKERNSEC_KMEM
31594+static inline void gr_init_ebda(void)
31595+{
31596+ unsigned int ebda_addr;
31597+ unsigned int ebda_size = 0;
31598+
31599+ ebda_addr = get_bios_ebda();
31600+ if (ebda_addr) {
31601+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31602+ ebda_size <<= 10;
31603+ }
31604+ if (ebda_addr && ebda_size) {
31605+ ebda_start = ebda_addr >> PAGE_SHIFT;
31606+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31607+ } else {
31608+ ebda_start = 0x9f000 >> PAGE_SHIFT;
31609+ ebda_end = 0xa0000 >> PAGE_SHIFT;
31610+ }
31611+}
31612+#else
31613+static inline void gr_init_ebda(void) { }
31614+#endif
31615+
31616 void free_initmem(void)
31617 {
31618+#ifdef CONFIG_PAX_KERNEXEC
31619+#ifdef CONFIG_X86_32
31620+ /* PaX: limit KERNEL_CS to actual size */
31621+ unsigned long addr, limit;
31622+ struct desc_struct d;
31623+ int cpu;
31624+#else
31625+ pgd_t *pgd;
31626+ pud_t *pud;
31627+ pmd_t *pmd;
31628+ unsigned long addr, end;
31629+#endif
31630+#endif
31631+
31632+ gr_init_ebda();
31633+
31634+#ifdef CONFIG_PAX_KERNEXEC
31635+#ifdef CONFIG_X86_32
31636+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31637+ limit = (limit - 1UL) >> PAGE_SHIFT;
31638+
31639+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31640+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31641+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31642+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31643+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31644+ }
31645+
31646+ /* PaX: make KERNEL_CS read-only */
31647+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31648+ if (!paravirt_enabled())
31649+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31650+/*
31651+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31652+ pgd = pgd_offset_k(addr);
31653+ pud = pud_offset(pgd, addr);
31654+ pmd = pmd_offset(pud, addr);
31655+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31656+ }
31657+*/
31658+#ifdef CONFIG_X86_PAE
31659+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31660+/*
31661+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31662+ pgd = pgd_offset_k(addr);
31663+ pud = pud_offset(pgd, addr);
31664+ pmd = pmd_offset(pud, addr);
31665+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31666+ }
31667+*/
31668+#endif
31669+
31670+#ifdef CONFIG_MODULES
31671+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31672+#endif
31673+
31674+#else
31675+ /* PaX: make kernel code/rodata read-only, rest non-executable */
31676+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31677+ pgd = pgd_offset_k(addr);
31678+ pud = pud_offset(pgd, addr);
31679+ pmd = pmd_offset(pud, addr);
31680+ if (!pmd_present(*pmd))
31681+ continue;
31682+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31683+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31684+ else
31685+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31686+ }
31687+
31688+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31689+ end = addr + KERNEL_IMAGE_SIZE;
31690+ for (; addr < end; addr += PMD_SIZE) {
31691+ pgd = pgd_offset_k(addr);
31692+ pud = pud_offset(pgd, addr);
31693+ pmd = pmd_offset(pud, addr);
31694+ if (!pmd_present(*pmd))
31695+ continue;
31696+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31697+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31698+ }
31699+#endif
31700+
31701+ flush_tlb_all();
31702+#endif
31703+
31704 free_init_pages("unused kernel",
31705 (unsigned long)(&__init_begin),
31706 (unsigned long)(&__init_end));
31707diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31708index 4287f1f..3b99c71 100644
31709--- a/arch/x86/mm/init_32.c
31710+++ b/arch/x86/mm/init_32.c
31711@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31712 bool __read_mostly __vmalloc_start_set = false;
31713
31714 /*
31715- * Creates a middle page table and puts a pointer to it in the
31716- * given global directory entry. This only returns the gd entry
31717- * in non-PAE compilation mode, since the middle layer is folded.
31718- */
31719-static pmd_t * __init one_md_table_init(pgd_t *pgd)
31720-{
31721- pud_t *pud;
31722- pmd_t *pmd_table;
31723-
31724-#ifdef CONFIG_X86_PAE
31725- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31726- pmd_table = (pmd_t *)alloc_low_page();
31727- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31728- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31729- pud = pud_offset(pgd, 0);
31730- BUG_ON(pmd_table != pmd_offset(pud, 0));
31731-
31732- return pmd_table;
31733- }
31734-#endif
31735- pud = pud_offset(pgd, 0);
31736- pmd_table = pmd_offset(pud, 0);
31737-
31738- return pmd_table;
31739-}
31740-
31741-/*
31742 * Create a page table and place a pointer to it in a middle page
31743 * directory entry:
31744 */
31745@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31746 pte_t *page_table = (pte_t *)alloc_low_page();
31747
31748 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31749+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31750+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31751+#else
31752 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31753+#endif
31754 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31755 }
31756
31757 return pte_offset_kernel(pmd, 0);
31758 }
31759
31760+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31761+{
31762+ pud_t *pud;
31763+ pmd_t *pmd_table;
31764+
31765+ pud = pud_offset(pgd, 0);
31766+ pmd_table = pmd_offset(pud, 0);
31767+
31768+ return pmd_table;
31769+}
31770+
31771 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31772 {
31773 int pgd_idx = pgd_index(vaddr);
31774@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31775 int pgd_idx, pmd_idx;
31776 unsigned long vaddr;
31777 pgd_t *pgd;
31778+ pud_t *pud;
31779 pmd_t *pmd;
31780 pte_t *pte = NULL;
31781 unsigned long count = page_table_range_init_count(start, end);
31782@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31783 pgd = pgd_base + pgd_idx;
31784
31785 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31786- pmd = one_md_table_init(pgd);
31787- pmd = pmd + pmd_index(vaddr);
31788+ pud = pud_offset(pgd, vaddr);
31789+ pmd = pmd_offset(pud, vaddr);
31790+
31791+#ifdef CONFIG_X86_PAE
31792+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31793+#endif
31794+
31795 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31796 pmd++, pmd_idx++) {
31797 pte = page_table_kmap_check(one_page_table_init(pmd),
31798@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31799 }
31800 }
31801
31802-static inline int is_kernel_text(unsigned long addr)
31803+static inline int is_kernel_text(unsigned long start, unsigned long end)
31804 {
31805- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31806- return 1;
31807- return 0;
31808+ if ((start > ktla_ktva((unsigned long)_etext) ||
31809+ end <= ktla_ktva((unsigned long)_stext)) &&
31810+ (start > ktla_ktva((unsigned long)_einittext) ||
31811+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31812+
31813+#ifdef CONFIG_ACPI_SLEEP
31814+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31815+#endif
31816+
31817+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31818+ return 0;
31819+ return 1;
31820 }
31821
31822 /*
31823@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31824 unsigned long last_map_addr = end;
31825 unsigned long start_pfn, end_pfn;
31826 pgd_t *pgd_base = swapper_pg_dir;
31827- int pgd_idx, pmd_idx, pte_ofs;
31828+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31829 unsigned long pfn;
31830 pgd_t *pgd;
31831+ pud_t *pud;
31832 pmd_t *pmd;
31833 pte_t *pte;
31834 unsigned pages_2m, pages_4k;
31835@@ -291,8 +295,13 @@ repeat:
31836 pfn = start_pfn;
31837 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31838 pgd = pgd_base + pgd_idx;
31839- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31840- pmd = one_md_table_init(pgd);
31841+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31842+ pud = pud_offset(pgd, 0);
31843+ pmd = pmd_offset(pud, 0);
31844+
31845+#ifdef CONFIG_X86_PAE
31846+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31847+#endif
31848
31849 if (pfn >= end_pfn)
31850 continue;
31851@@ -304,14 +313,13 @@ repeat:
31852 #endif
31853 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31854 pmd++, pmd_idx++) {
31855- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31856+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31857
31858 /*
31859 * Map with big pages if possible, otherwise
31860 * create normal page tables:
31861 */
31862 if (use_pse) {
31863- unsigned int addr2;
31864 pgprot_t prot = PAGE_KERNEL_LARGE;
31865 /*
31866 * first pass will use the same initial
31867@@ -322,11 +330,7 @@ repeat:
31868 _PAGE_PSE);
31869
31870 pfn &= PMD_MASK >> PAGE_SHIFT;
31871- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31872- PAGE_OFFSET + PAGE_SIZE-1;
31873-
31874- if (is_kernel_text(addr) ||
31875- is_kernel_text(addr2))
31876+ if (is_kernel_text(address, address + PMD_SIZE))
31877 prot = PAGE_KERNEL_LARGE_EXEC;
31878
31879 pages_2m++;
31880@@ -343,7 +347,7 @@ repeat:
31881 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31882 pte += pte_ofs;
31883 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31884- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31885+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31886 pgprot_t prot = PAGE_KERNEL;
31887 /*
31888 * first pass will use the same initial
31889@@ -351,7 +355,7 @@ repeat:
31890 */
31891 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31892
31893- if (is_kernel_text(addr))
31894+ if (is_kernel_text(address, address + PAGE_SIZE))
31895 prot = PAGE_KERNEL_EXEC;
31896
31897 pages_4k++;
31898@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31899
31900 pud = pud_offset(pgd, va);
31901 pmd = pmd_offset(pud, va);
31902- if (!pmd_present(*pmd))
31903+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31904 break;
31905
31906 /* should not be large page here */
31907@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31908
31909 static void __init pagetable_init(void)
31910 {
31911- pgd_t *pgd_base = swapper_pg_dir;
31912-
31913- permanent_kmaps_init(pgd_base);
31914+ permanent_kmaps_init(swapper_pg_dir);
31915 }
31916
31917-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31918+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31919 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31920
31921 /* user-defined highmem size */
31922@@ -787,10 +789,10 @@ void __init mem_init(void)
31923 ((unsigned long)&__init_end -
31924 (unsigned long)&__init_begin) >> 10,
31925
31926- (unsigned long)&_etext, (unsigned long)&_edata,
31927- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31928+ (unsigned long)&_sdata, (unsigned long)&_edata,
31929+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31930
31931- (unsigned long)&_text, (unsigned long)&_etext,
31932+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31933 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31934
31935 /*
31936@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31937 if (!kernel_set_to_readonly)
31938 return;
31939
31940+ start = ktla_ktva(start);
31941 pr_debug("Set kernel text: %lx - %lx for read write\n",
31942 start, start+size);
31943
31944@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31945 if (!kernel_set_to_readonly)
31946 return;
31947
31948+ start = ktla_ktva(start);
31949 pr_debug("Set kernel text: %lx - %lx for read only\n",
31950 start, start+size);
31951
31952@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31953 unsigned long start = PFN_ALIGN(_text);
31954 unsigned long size = PFN_ALIGN(_etext) - start;
31955
31956+ start = ktla_ktva(start);
31957 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31958 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31959 size >> 10);
31960diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31961index 104d56a..62ba13f1 100644
31962--- a/arch/x86/mm/init_64.c
31963+++ b/arch/x86/mm/init_64.c
31964@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31965 * around without checking the pgd every time.
31966 */
31967
31968-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31969+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31970 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31971
31972 int force_personality32;
31973@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31974
31975 for (address = start; address <= end; address += PGDIR_SIZE) {
31976 const pgd_t *pgd_ref = pgd_offset_k(address);
31977+
31978+#ifdef CONFIG_PAX_PER_CPU_PGD
31979+ unsigned long cpu;
31980+#else
31981 struct page *page;
31982+#endif
31983
31984 if (pgd_none(*pgd_ref))
31985 continue;
31986
31987 spin_lock(&pgd_lock);
31988+
31989+#ifdef CONFIG_PAX_PER_CPU_PGD
31990+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31991+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31992+
31993+ if (pgd_none(*pgd))
31994+ set_pgd(pgd, *pgd_ref);
31995+ else
31996+ BUG_ON(pgd_page_vaddr(*pgd)
31997+ != pgd_page_vaddr(*pgd_ref));
31998+ pgd = pgd_offset_cpu(cpu, kernel, address);
31999+#else
32000 list_for_each_entry(page, &pgd_list, lru) {
32001 pgd_t *pgd;
32002 spinlock_t *pgt_lock;
32003@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32004 /* the pgt_lock only for Xen */
32005 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32006 spin_lock(pgt_lock);
32007+#endif
32008
32009 if (pgd_none(*pgd))
32010 set_pgd(pgd, *pgd_ref);
32011@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32012 BUG_ON(pgd_page_vaddr(*pgd)
32013 != pgd_page_vaddr(*pgd_ref));
32014
32015+#ifndef CONFIG_PAX_PER_CPU_PGD
32016 spin_unlock(pgt_lock);
32017+#endif
32018+
32019 }
32020 spin_unlock(&pgd_lock);
32021 }
32022@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32023 {
32024 if (pgd_none(*pgd)) {
32025 pud_t *pud = (pud_t *)spp_getpage();
32026- pgd_populate(&init_mm, pgd, pud);
32027+ pgd_populate_kernel(&init_mm, pgd, pud);
32028 if (pud != pud_offset(pgd, 0))
32029 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32030 pud, pud_offset(pgd, 0));
32031@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32032 {
32033 if (pud_none(*pud)) {
32034 pmd_t *pmd = (pmd_t *) spp_getpage();
32035- pud_populate(&init_mm, pud, pmd);
32036+ pud_populate_kernel(&init_mm, pud, pmd);
32037 if (pmd != pmd_offset(pud, 0))
32038 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32039 pmd, pmd_offset(pud, 0));
32040@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32041 pmd = fill_pmd(pud, vaddr);
32042 pte = fill_pte(pmd, vaddr);
32043
32044+ pax_open_kernel();
32045 set_pte(pte, new_pte);
32046+ pax_close_kernel();
32047
32048 /*
32049 * It's enough to flush this one mapping.
32050@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32051 pgd = pgd_offset_k((unsigned long)__va(phys));
32052 if (pgd_none(*pgd)) {
32053 pud = (pud_t *) spp_getpage();
32054- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32055- _PAGE_USER));
32056+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32057 }
32058 pud = pud_offset(pgd, (unsigned long)__va(phys));
32059 if (pud_none(*pud)) {
32060 pmd = (pmd_t *) spp_getpage();
32061- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32062- _PAGE_USER));
32063+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32064 }
32065 pmd = pmd_offset(pud, phys);
32066 BUG_ON(!pmd_none(*pmd));
32067@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32068 prot);
32069
32070 spin_lock(&init_mm.page_table_lock);
32071- pud_populate(&init_mm, pud, pmd);
32072+ pud_populate_kernel(&init_mm, pud, pmd);
32073 spin_unlock(&init_mm.page_table_lock);
32074 }
32075 __flush_tlb_all();
32076@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32077 page_size_mask);
32078
32079 spin_lock(&init_mm.page_table_lock);
32080- pgd_populate(&init_mm, pgd, pud);
32081+ pgd_populate_kernel(&init_mm, pgd, pud);
32082 spin_unlock(&init_mm.page_table_lock);
32083 pgd_changed = true;
32084 }
32085@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32086 static struct vm_area_struct gate_vma = {
32087 .vm_start = VSYSCALL_START,
32088 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32089- .vm_page_prot = PAGE_READONLY_EXEC,
32090- .vm_flags = VM_READ | VM_EXEC
32091+ .vm_page_prot = PAGE_READONLY,
32092+ .vm_flags = VM_READ
32093 };
32094
32095 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32096@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32097
32098 const char *arch_vma_name(struct vm_area_struct *vma)
32099 {
32100- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32101+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32102 return "[vdso]";
32103 if (vma == &gate_vma)
32104 return "[vsyscall]";
32105diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32106index 7b179b4..6bd17777 100644
32107--- a/arch/x86/mm/iomap_32.c
32108+++ b/arch/x86/mm/iomap_32.c
32109@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32110 type = kmap_atomic_idx_push();
32111 idx = type + KM_TYPE_NR * smp_processor_id();
32112 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32113+
32114+ pax_open_kernel();
32115 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32116+ pax_close_kernel();
32117+
32118 arch_flush_lazy_mmu_mode();
32119
32120 return (void *)vaddr;
32121diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32122index 799580c..72f9fe0 100644
32123--- a/arch/x86/mm/ioremap.c
32124+++ b/arch/x86/mm/ioremap.c
32125@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32126 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32127 int is_ram = page_is_ram(pfn);
32128
32129- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32130+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32131 return NULL;
32132 WARN_ON_ONCE(is_ram);
32133 }
32134@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32135 *
32136 * Caller must ensure there is only one unmapping for the same pointer.
32137 */
32138-void iounmap(volatile void __iomem *addr)
32139+void iounmap(const volatile void __iomem *addr)
32140 {
32141 struct vm_struct *p, *o;
32142
32143@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32144
32145 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32146 if (page_is_ram(start >> PAGE_SHIFT))
32147+#ifdef CONFIG_HIGHMEM
32148+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32149+#endif
32150 return __va(phys);
32151
32152 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32153@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32154 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32155 {
32156 if (page_is_ram(phys >> PAGE_SHIFT))
32157+#ifdef CONFIG_HIGHMEM
32158+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32159+#endif
32160 return;
32161
32162 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32163@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32164 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32165
32166 static __initdata int after_paging_init;
32167-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32168+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32169
32170 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32171 {
32172@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32173 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32174
32175 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32176- memset(bm_pte, 0, sizeof(bm_pte));
32177- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32178+ pmd_populate_user(&init_mm, pmd, bm_pte);
32179
32180 /*
32181 * The boot-ioremap range spans multiple pmds, for which
32182diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32183index d87dd6d..bf3fa66 100644
32184--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32185+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32186@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32187 * memory (e.g. tracked pages)? For now, we need this to avoid
32188 * invoking kmemcheck for PnP BIOS calls.
32189 */
32190- if (regs->flags & X86_VM_MASK)
32191+ if (v8086_mode(regs))
32192 return false;
32193- if (regs->cs != __KERNEL_CS)
32194+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32195 return false;
32196
32197 pte = kmemcheck_pte_lookup(address);
32198diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32199index 25e7e13..1964579 100644
32200--- a/arch/x86/mm/mmap.c
32201+++ b/arch/x86/mm/mmap.c
32202@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32203 * Leave an at least ~128 MB hole with possible stack randomization.
32204 */
32205 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32206-#define MAX_GAP (TASK_SIZE/6*5)
32207+#define MAX_GAP (pax_task_size/6*5)
32208
32209 static int mmap_is_legacy(void)
32210 {
32211@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32212 return rnd << PAGE_SHIFT;
32213 }
32214
32215-static unsigned long mmap_base(void)
32216+static unsigned long mmap_base(struct mm_struct *mm)
32217 {
32218 unsigned long gap = rlimit(RLIMIT_STACK);
32219+ unsigned long pax_task_size = TASK_SIZE;
32220+
32221+#ifdef CONFIG_PAX_SEGMEXEC
32222+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32223+ pax_task_size = SEGMEXEC_TASK_SIZE;
32224+#endif
32225
32226 if (gap < MIN_GAP)
32227 gap = MIN_GAP;
32228 else if (gap > MAX_GAP)
32229 gap = MAX_GAP;
32230
32231- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32232+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32233 }
32234
32235 /*
32236 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32237 * does, but not when emulating X86_32
32238 */
32239-static unsigned long mmap_legacy_base(void)
32240+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32241 {
32242- if (mmap_is_ia32())
32243+ if (mmap_is_ia32()) {
32244+
32245+#ifdef CONFIG_PAX_SEGMEXEC
32246+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32247+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32248+ else
32249+#endif
32250+
32251 return TASK_UNMAPPED_BASE;
32252- else
32253+ } else
32254 return TASK_UNMAPPED_BASE + mmap_rnd();
32255 }
32256
32257@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32258 */
32259 void arch_pick_mmap_layout(struct mm_struct *mm)
32260 {
32261- mm->mmap_legacy_base = mmap_legacy_base();
32262- mm->mmap_base = mmap_base();
32263+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32264+ mm->mmap_base = mmap_base(mm);
32265+
32266+#ifdef CONFIG_PAX_RANDMMAP
32267+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32268+ mm->mmap_legacy_base += mm->delta_mmap;
32269+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32270+ }
32271+#endif
32272
32273 if (mmap_is_legacy()) {
32274 mm->mmap_base = mm->mmap_legacy_base;
32275diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32276index 0057a7a..95c7edd 100644
32277--- a/arch/x86/mm/mmio-mod.c
32278+++ b/arch/x86/mm/mmio-mod.c
32279@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32280 break;
32281 default:
32282 {
32283- unsigned char *ip = (unsigned char *)instptr;
32284+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32285 my_trace->opcode = MMIO_UNKNOWN_OP;
32286 my_trace->width = 0;
32287 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32288@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32289 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32290 void __iomem *addr)
32291 {
32292- static atomic_t next_id;
32293+ static atomic_unchecked_t next_id;
32294 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32295 /* These are page-unaligned. */
32296 struct mmiotrace_map map = {
32297@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32298 .private = trace
32299 },
32300 .phys = offset,
32301- .id = atomic_inc_return(&next_id)
32302+ .id = atomic_inc_return_unchecked(&next_id)
32303 };
32304 map.map_id = trace->id;
32305
32306@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32307 ioremap_trace_core(offset, size, addr);
32308 }
32309
32310-static void iounmap_trace_core(volatile void __iomem *addr)
32311+static void iounmap_trace_core(const volatile void __iomem *addr)
32312 {
32313 struct mmiotrace_map map = {
32314 .phys = 0,
32315@@ -328,7 +328,7 @@ not_enabled:
32316 }
32317 }
32318
32319-void mmiotrace_iounmap(volatile void __iomem *addr)
32320+void mmiotrace_iounmap(const volatile void __iomem *addr)
32321 {
32322 might_sleep();
32323 if (is_enabled()) /* recheck and proper locking in *_core() */
32324diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32325index 24aec58..c39fe8b 100644
32326--- a/arch/x86/mm/numa.c
32327+++ b/arch/x86/mm/numa.c
32328@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32329 return true;
32330 }
32331
32332-static int __init numa_register_memblks(struct numa_meminfo *mi)
32333+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32334 {
32335 unsigned long uninitialized_var(pfn_align);
32336 int i, nid;
32337diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32338index d0b1773..4c3327c 100644
32339--- a/arch/x86/mm/pageattr-test.c
32340+++ b/arch/x86/mm/pageattr-test.c
32341@@ -36,7 +36,7 @@ enum {
32342
32343 static int pte_testbit(pte_t pte)
32344 {
32345- return pte_flags(pte) & _PAGE_UNUSED1;
32346+ return pte_flags(pte) & _PAGE_CPA_TEST;
32347 }
32348
32349 struct split_state {
32350diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32351index bb32480..75f2f5e 100644
32352--- a/arch/x86/mm/pageattr.c
32353+++ b/arch/x86/mm/pageattr.c
32354@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32355 */
32356 #ifdef CONFIG_PCI_BIOS
32357 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32358- pgprot_val(forbidden) |= _PAGE_NX;
32359+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32360 #endif
32361
32362 /*
32363@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32364 * Does not cover __inittext since that is gone later on. On
32365 * 64bit we do not enforce !NX on the low mapping
32366 */
32367- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32368- pgprot_val(forbidden) |= _PAGE_NX;
32369+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32370+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32371
32372+#ifdef CONFIG_DEBUG_RODATA
32373 /*
32374 * The .rodata section needs to be read-only. Using the pfn
32375 * catches all aliases.
32376@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32377 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32378 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32379 pgprot_val(forbidden) |= _PAGE_RW;
32380+#endif
32381
32382 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32383 /*
32384@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32385 }
32386 #endif
32387
32388+#ifdef CONFIG_PAX_KERNEXEC
32389+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32390+ pgprot_val(forbidden) |= _PAGE_RW;
32391+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32392+ }
32393+#endif
32394+
32395 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32396
32397 return prot;
32398@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32399 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32400 {
32401 /* change init_mm */
32402+ pax_open_kernel();
32403 set_pte_atomic(kpte, pte);
32404+
32405 #ifdef CONFIG_X86_32
32406 if (!SHARED_KERNEL_PMD) {
32407+
32408+#ifdef CONFIG_PAX_PER_CPU_PGD
32409+ unsigned long cpu;
32410+#else
32411 struct page *page;
32412+#endif
32413
32414+#ifdef CONFIG_PAX_PER_CPU_PGD
32415+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32416+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32417+#else
32418 list_for_each_entry(page, &pgd_list, lru) {
32419- pgd_t *pgd;
32420+ pgd_t *pgd = (pgd_t *)page_address(page);
32421+#endif
32422+
32423 pud_t *pud;
32424 pmd_t *pmd;
32425
32426- pgd = (pgd_t *)page_address(page) + pgd_index(address);
32427+ pgd += pgd_index(address);
32428 pud = pud_offset(pgd, address);
32429 pmd = pmd_offset(pud, address);
32430 set_pte_atomic((pte_t *)pmd, pte);
32431 }
32432 }
32433 #endif
32434+ pax_close_kernel();
32435 }
32436
32437 static int
32438diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32439index 6574388..87e9bef 100644
32440--- a/arch/x86/mm/pat.c
32441+++ b/arch/x86/mm/pat.c
32442@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32443
32444 if (!entry) {
32445 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32446- current->comm, current->pid, start, end - 1);
32447+ current->comm, task_pid_nr(current), start, end - 1);
32448 return -EINVAL;
32449 }
32450
32451@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32452
32453 while (cursor < to) {
32454 if (!devmem_is_allowed(pfn)) {
32455- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32456- current->comm, from, to - 1);
32457+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32458+ current->comm, from, to - 1, cursor);
32459 return 0;
32460 }
32461 cursor += PAGE_SIZE;
32462@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32463 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32464 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32465 "for [mem %#010Lx-%#010Lx]\n",
32466- current->comm, current->pid,
32467+ current->comm, task_pid_nr(current),
32468 cattr_name(flags),
32469 base, (unsigned long long)(base + size-1));
32470 return -EINVAL;
32471@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32472 flags = lookup_memtype(paddr);
32473 if (want_flags != flags) {
32474 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32475- current->comm, current->pid,
32476+ current->comm, task_pid_nr(current),
32477 cattr_name(want_flags),
32478 (unsigned long long)paddr,
32479 (unsigned long long)(paddr + size - 1),
32480@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32481 free_memtype(paddr, paddr + size);
32482 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32483 " for [mem %#010Lx-%#010Lx], got %s\n",
32484- current->comm, current->pid,
32485+ current->comm, task_pid_nr(current),
32486 cattr_name(want_flags),
32487 (unsigned long long)paddr,
32488 (unsigned long long)(paddr + size - 1),
32489diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32490index 415f6c4..d319983 100644
32491--- a/arch/x86/mm/pat_rbtree.c
32492+++ b/arch/x86/mm/pat_rbtree.c
32493@@ -160,7 +160,7 @@ success:
32494
32495 failure:
32496 printk(KERN_INFO "%s:%d conflicting memory types "
32497- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32498+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32499 end, cattr_name(found_type), cattr_name(match->type));
32500 return -EBUSY;
32501 }
32502diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32503index 9f0614d..92ae64a 100644
32504--- a/arch/x86/mm/pf_in.c
32505+++ b/arch/x86/mm/pf_in.c
32506@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32507 int i;
32508 enum reason_type rv = OTHERS;
32509
32510- p = (unsigned char *)ins_addr;
32511+ p = (unsigned char *)ktla_ktva(ins_addr);
32512 p += skip_prefix(p, &prf);
32513 p += get_opcode(p, &opcode);
32514
32515@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32516 struct prefix_bits prf;
32517 int i;
32518
32519- p = (unsigned char *)ins_addr;
32520+ p = (unsigned char *)ktla_ktva(ins_addr);
32521 p += skip_prefix(p, &prf);
32522 p += get_opcode(p, &opcode);
32523
32524@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32525 struct prefix_bits prf;
32526 int i;
32527
32528- p = (unsigned char *)ins_addr;
32529+ p = (unsigned char *)ktla_ktva(ins_addr);
32530 p += skip_prefix(p, &prf);
32531 p += get_opcode(p, &opcode);
32532
32533@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32534 struct prefix_bits prf;
32535 int i;
32536
32537- p = (unsigned char *)ins_addr;
32538+ p = (unsigned char *)ktla_ktva(ins_addr);
32539 p += skip_prefix(p, &prf);
32540 p += get_opcode(p, &opcode);
32541 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32542@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32543 struct prefix_bits prf;
32544 int i;
32545
32546- p = (unsigned char *)ins_addr;
32547+ p = (unsigned char *)ktla_ktva(ins_addr);
32548 p += skip_prefix(p, &prf);
32549 p += get_opcode(p, &opcode);
32550 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32551diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32552index c96314a..433b127 100644
32553--- a/arch/x86/mm/pgtable.c
32554+++ b/arch/x86/mm/pgtable.c
32555@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
32556 list_del(&page->lru);
32557 }
32558
32559-#define UNSHARED_PTRS_PER_PGD \
32560- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32561+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32562+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32563
32564+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32565+{
32566+ unsigned int count = USER_PGD_PTRS;
32567
32568+ if (!pax_user_shadow_base)
32569+ return;
32570+
32571+ while (count--)
32572+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32573+}
32574+#endif
32575+
32576+#ifdef CONFIG_PAX_PER_CPU_PGD
32577+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32578+{
32579+ unsigned int count = USER_PGD_PTRS;
32580+
32581+ while (count--) {
32582+ pgd_t pgd;
32583+
32584+#ifdef CONFIG_X86_64
32585+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32586+#else
32587+ pgd = *src++;
32588+#endif
32589+
32590+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32591+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32592+#endif
32593+
32594+ *dst++ = pgd;
32595+ }
32596+
32597+}
32598+#endif
32599+
32600+#ifdef CONFIG_X86_64
32601+#define pxd_t pud_t
32602+#define pyd_t pgd_t
32603+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32604+#define pgtable_pxd_page_ctor(page) true
32605+#define pgtable_pxd_page_dtor(page)
32606+#define pxd_free(mm, pud) pud_free((mm), (pud))
32607+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32608+#define pyd_offset(mm, address) pgd_offset((mm), (address))
32609+#define PYD_SIZE PGDIR_SIZE
32610+#else
32611+#define pxd_t pmd_t
32612+#define pyd_t pud_t
32613+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32614+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
32615+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
32616+#define pxd_free(mm, pud) pmd_free((mm), (pud))
32617+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32618+#define pyd_offset(mm, address) pud_offset((mm), (address))
32619+#define PYD_SIZE PUD_SIZE
32620+#endif
32621+
32622+#ifdef CONFIG_PAX_PER_CPU_PGD
32623+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32624+static inline void pgd_dtor(pgd_t *pgd) {}
32625+#else
32626 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32627 {
32628 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32629@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
32630 pgd_list_del(pgd);
32631 spin_unlock(&pgd_lock);
32632 }
32633+#endif
32634
32635 /*
32636 * List of all pgd's needed for non-PAE so it can invalidate entries
32637@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
32638 * -- nyc
32639 */
32640
32641-#ifdef CONFIG_X86_PAE
32642+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32643 /*
32644 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32645 * updating the top-level pagetable entries to guarantee the
32646@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
32647 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32648 * and initialize the kernel pmds here.
32649 */
32650-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32651+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32652
32653 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32654 {
32655@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32656 */
32657 flush_tlb_mm(mm);
32658 }
32659+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32660+#define PREALLOCATED_PXDS USER_PGD_PTRS
32661 #else /* !CONFIG_X86_PAE */
32662
32663 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32664-#define PREALLOCATED_PMDS 0
32665+#define PREALLOCATED_PXDS 0
32666
32667 #endif /* CONFIG_X86_PAE */
32668
32669-static void free_pmds(pmd_t *pmds[])
32670+static void free_pxds(pxd_t *pxds[])
32671 {
32672 int i;
32673
32674- for(i = 0; i < PREALLOCATED_PMDS; i++)
32675- if (pmds[i]) {
32676- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
32677- free_page((unsigned long)pmds[i]);
32678+ for(i = 0; i < PREALLOCATED_PXDS; i++)
32679+ if (pxds[i]) {
32680+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
32681+ free_page((unsigned long)pxds[i]);
32682 }
32683 }
32684
32685-static int preallocate_pmds(pmd_t *pmds[])
32686+static int preallocate_pxds(pxd_t *pxds[])
32687 {
32688 int i;
32689 bool failed = false;
32690
32691- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32692- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32693- if (!pmd)
32694+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32695+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32696+ if (!pxd)
32697 failed = true;
32698- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
32699- free_page((unsigned long)pmd);
32700- pmd = NULL;
32701+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
32702+ free_page((unsigned long)pxd);
32703+ pxd = NULL;
32704 failed = true;
32705 }
32706- pmds[i] = pmd;
32707+ pxds[i] = pxd;
32708 }
32709
32710 if (failed) {
32711- free_pmds(pmds);
32712+ free_pxds(pxds);
32713 return -ENOMEM;
32714 }
32715
32716@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32717 * preallocate which never got a corresponding vma will need to be
32718 * freed manually.
32719 */
32720-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32721+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32722 {
32723 int i;
32724
32725- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32726+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32727 pgd_t pgd = pgdp[i];
32728
32729 if (pgd_val(pgd) != 0) {
32730- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32731+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32732
32733- pgdp[i] = native_make_pgd(0);
32734+ set_pgd(pgdp + i, native_make_pgd(0));
32735
32736- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32737- pmd_free(mm, pmd);
32738+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32739+ pxd_free(mm, pxd);
32740 }
32741 }
32742 }
32743
32744-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32745+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32746 {
32747- pud_t *pud;
32748+ pyd_t *pyd;
32749 int i;
32750
32751- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32752+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32753 return;
32754
32755- pud = pud_offset(pgd, 0);
32756-
32757- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32758- pmd_t *pmd = pmds[i];
32759+#ifdef CONFIG_X86_64
32760+ pyd = pyd_offset(mm, 0L);
32761+#else
32762+ pyd = pyd_offset(pgd, 0L);
32763+#endif
32764
32765+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32766+ pxd_t *pxd = pxds[i];
32767 if (i >= KERNEL_PGD_BOUNDARY)
32768- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32769- sizeof(pmd_t) * PTRS_PER_PMD);
32770+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32771+ sizeof(pxd_t) * PTRS_PER_PMD);
32772
32773- pud_populate(mm, pud, pmd);
32774+ pyd_populate(mm, pyd, pxd);
32775 }
32776 }
32777
32778 pgd_t *pgd_alloc(struct mm_struct *mm)
32779 {
32780 pgd_t *pgd;
32781- pmd_t *pmds[PREALLOCATED_PMDS];
32782+ pxd_t *pxds[PREALLOCATED_PXDS];
32783
32784 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32785
32786@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32787
32788 mm->pgd = pgd;
32789
32790- if (preallocate_pmds(pmds) != 0)
32791+ if (preallocate_pxds(pxds) != 0)
32792 goto out_free_pgd;
32793
32794 if (paravirt_pgd_alloc(mm) != 0)
32795- goto out_free_pmds;
32796+ goto out_free_pxds;
32797
32798 /*
32799 * Make sure that pre-populating the pmds is atomic with
32800@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32801 spin_lock(&pgd_lock);
32802
32803 pgd_ctor(mm, pgd);
32804- pgd_prepopulate_pmd(mm, pgd, pmds);
32805+ pgd_prepopulate_pxd(mm, pgd, pxds);
32806
32807 spin_unlock(&pgd_lock);
32808
32809 return pgd;
32810
32811-out_free_pmds:
32812- free_pmds(pmds);
32813+out_free_pxds:
32814+ free_pxds(pxds);
32815 out_free_pgd:
32816 free_page((unsigned long)pgd);
32817 out:
32818@@ -313,7 +380,7 @@ out:
32819
32820 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32821 {
32822- pgd_mop_up_pmds(mm, pgd);
32823+ pgd_mop_up_pxds(mm, pgd);
32824 pgd_dtor(pgd);
32825 paravirt_pgd_free(mm, pgd);
32826 free_page((unsigned long)pgd);
32827diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32828index a69bcb8..19068ab 100644
32829--- a/arch/x86/mm/pgtable_32.c
32830+++ b/arch/x86/mm/pgtable_32.c
32831@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32832 return;
32833 }
32834 pte = pte_offset_kernel(pmd, vaddr);
32835+
32836+ pax_open_kernel();
32837 if (pte_val(pteval))
32838 set_pte_at(&init_mm, vaddr, pte, pteval);
32839 else
32840 pte_clear(&init_mm, vaddr, pte);
32841+ pax_close_kernel();
32842
32843 /*
32844 * It's enough to flush this one mapping.
32845diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32846index e666cbb..61788c45 100644
32847--- a/arch/x86/mm/physaddr.c
32848+++ b/arch/x86/mm/physaddr.c
32849@@ -10,7 +10,7 @@
32850 #ifdef CONFIG_X86_64
32851
32852 #ifdef CONFIG_DEBUG_VIRTUAL
32853-unsigned long __phys_addr(unsigned long x)
32854+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32855 {
32856 unsigned long y = x - __START_KERNEL_map;
32857
32858@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32859 #else
32860
32861 #ifdef CONFIG_DEBUG_VIRTUAL
32862-unsigned long __phys_addr(unsigned long x)
32863+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32864 {
32865 unsigned long phys_addr = x - PAGE_OFFSET;
32866 /* VMALLOC_* aren't constants */
32867diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32868index 90555bf..f5f1828 100644
32869--- a/arch/x86/mm/setup_nx.c
32870+++ b/arch/x86/mm/setup_nx.c
32871@@ -5,8 +5,10 @@
32872 #include <asm/pgtable.h>
32873 #include <asm/proto.h>
32874
32875+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32876 static int disable_nx;
32877
32878+#ifndef CONFIG_PAX_PAGEEXEC
32879 /*
32880 * noexec = on|off
32881 *
32882@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32883 return 0;
32884 }
32885 early_param("noexec", noexec_setup);
32886+#endif
32887+
32888+#endif
32889
32890 void x86_configure_nx(void)
32891 {
32892+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32893 if (cpu_has_nx && !disable_nx)
32894 __supported_pte_mask |= _PAGE_NX;
32895 else
32896+#endif
32897 __supported_pte_mask &= ~_PAGE_NX;
32898 }
32899
32900diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32901index ae699b3..f1b2ad2 100644
32902--- a/arch/x86/mm/tlb.c
32903+++ b/arch/x86/mm/tlb.c
32904@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32905 BUG();
32906 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32907 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32908+
32909+#ifndef CONFIG_PAX_PER_CPU_PGD
32910 load_cr3(swapper_pg_dir);
32911+#endif
32912+
32913 }
32914 }
32915 EXPORT_SYMBOL_GPL(leave_mm);
32916diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32917new file mode 100644
32918index 0000000..dace51c
32919--- /dev/null
32920+++ b/arch/x86/mm/uderef_64.c
32921@@ -0,0 +1,37 @@
32922+#include <linux/mm.h>
32923+#include <asm/pgtable.h>
32924+#include <asm/uaccess.h>
32925+
32926+#ifdef CONFIG_PAX_MEMORY_UDEREF
32927+/* PaX: due to the special call convention these functions must
32928+ * - remain leaf functions under all configurations,
32929+ * - never be called directly, only dereferenced from the wrappers.
32930+ */
32931+void __pax_open_userland(void)
32932+{
32933+ unsigned int cpu;
32934+
32935+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32936+ return;
32937+
32938+ cpu = raw_get_cpu();
32939+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32940+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32941+ raw_put_cpu_no_resched();
32942+}
32943+EXPORT_SYMBOL(__pax_open_userland);
32944+
32945+void __pax_close_userland(void)
32946+{
32947+ unsigned int cpu;
32948+
32949+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32950+ return;
32951+
32952+ cpu = raw_get_cpu();
32953+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32954+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32955+ raw_put_cpu_no_resched();
32956+}
32957+EXPORT_SYMBOL(__pax_close_userland);
32958+#endif
32959diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32960index 877b9a1..a8ecf42 100644
32961--- a/arch/x86/net/bpf_jit.S
32962+++ b/arch/x86/net/bpf_jit.S
32963@@ -9,6 +9,7 @@
32964 */
32965 #include <linux/linkage.h>
32966 #include <asm/dwarf2.h>
32967+#include <asm/alternative-asm.h>
32968
32969 /*
32970 * Calling convention :
32971@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32972 jle bpf_slow_path_word
32973 mov (SKBDATA,%rsi),%eax
32974 bswap %eax /* ntohl() */
32975+ pax_force_retaddr
32976 ret
32977
32978 sk_load_half:
32979@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32980 jle bpf_slow_path_half
32981 movzwl (SKBDATA,%rsi),%eax
32982 rol $8,%ax # ntohs()
32983+ pax_force_retaddr
32984 ret
32985
32986 sk_load_byte:
32987@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32988 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32989 jle bpf_slow_path_byte
32990 movzbl (SKBDATA,%rsi),%eax
32991+ pax_force_retaddr
32992 ret
32993
32994 /**
32995@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32996 movzbl (SKBDATA,%rsi),%ebx
32997 and $15,%bl
32998 shl $2,%bl
32999+ pax_force_retaddr
33000 ret
33001
33002 /* rsi contains offset and can be scratched */
33003@@ -109,6 +114,7 @@ bpf_slow_path_word:
33004 js bpf_error
33005 mov -12(%rbp),%eax
33006 bswap %eax
33007+ pax_force_retaddr
33008 ret
33009
33010 bpf_slow_path_half:
33011@@ -117,12 +123,14 @@ bpf_slow_path_half:
33012 mov -12(%rbp),%ax
33013 rol $8,%ax
33014 movzwl %ax,%eax
33015+ pax_force_retaddr
33016 ret
33017
33018 bpf_slow_path_byte:
33019 bpf_slow_path_common(1)
33020 js bpf_error
33021 movzbl -12(%rbp),%eax
33022+ pax_force_retaddr
33023 ret
33024
33025 bpf_slow_path_byte_msh:
33026@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33027 and $15,%al
33028 shl $2,%al
33029 xchg %eax,%ebx
33030+ pax_force_retaddr
33031 ret
33032
33033 #define sk_negative_common(SIZE) \
33034@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33035 sk_negative_common(4)
33036 mov (%rax), %eax
33037 bswap %eax
33038+ pax_force_retaddr
33039 ret
33040
33041 bpf_slow_path_half_neg:
33042@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33043 mov (%rax),%ax
33044 rol $8,%ax
33045 movzwl %ax,%eax
33046+ pax_force_retaddr
33047 ret
33048
33049 bpf_slow_path_byte_neg:
33050@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33051 .globl sk_load_byte_negative_offset
33052 sk_negative_common(1)
33053 movzbl (%rax), %eax
33054+ pax_force_retaddr
33055 ret
33056
33057 bpf_slow_path_byte_msh_neg:
33058@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33059 and $15,%al
33060 shl $2,%al
33061 xchg %eax,%ebx
33062+ pax_force_retaddr
33063 ret
33064
33065 bpf_error:
33066@@ -197,4 +210,5 @@ bpf_error:
33067 xor %eax,%eax
33068 mov -8(%rbp),%rbx
33069 leaveq
33070+ pax_force_retaddr
33071 ret
33072diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33073index 4ed75dd..8dfe0d5 100644
33074--- a/arch/x86/net/bpf_jit_comp.c
33075+++ b/arch/x86/net/bpf_jit_comp.c
33076@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33077 return ptr + len;
33078 }
33079
33080+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33081+#define MAX_INSTR_CODE_SIZE 96
33082+#else
33083+#define MAX_INSTR_CODE_SIZE 64
33084+#endif
33085+
33086 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33087
33088 #define EMIT1(b1) EMIT(b1, 1)
33089 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33090 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33091 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33092+
33093+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33094+/* original constant will appear in ecx */
33095+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33096+do { \
33097+ /* mov ecx, randkey */ \
33098+ EMIT1(0xb9); \
33099+ EMIT(_key, 4); \
33100+ /* xor ecx, randkey ^ off */ \
33101+ EMIT2(0x81, 0xf1); \
33102+ EMIT((_key) ^ (_off), 4); \
33103+} while (0)
33104+
33105+#define EMIT1_off32(b1, _off) \
33106+do { \
33107+ switch (b1) { \
33108+ case 0x05: /* add eax, imm32 */ \
33109+ case 0x2d: /* sub eax, imm32 */ \
33110+ case 0x25: /* and eax, imm32 */ \
33111+ case 0x0d: /* or eax, imm32 */ \
33112+ case 0xb8: /* mov eax, imm32 */ \
33113+ case 0x35: /* xor eax, imm32 */ \
33114+ case 0x3d: /* cmp eax, imm32 */ \
33115+ case 0xa9: /* test eax, imm32 */ \
33116+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33117+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33118+ break; \
33119+ case 0xbb: /* mov ebx, imm32 */ \
33120+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33121+ /* mov ebx, ecx */ \
33122+ EMIT2(0x89, 0xcb); \
33123+ break; \
33124+ case 0xbe: /* mov esi, imm32 */ \
33125+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33126+ /* mov esi, ecx */ \
33127+ EMIT2(0x89, 0xce); \
33128+ break; \
33129+ case 0xe8: /* call rel imm32, always to known funcs */ \
33130+ EMIT1(b1); \
33131+ EMIT(_off, 4); \
33132+ break; \
33133+ case 0xe9: /* jmp rel imm32 */ \
33134+ EMIT1(b1); \
33135+ EMIT(_off, 4); \
33136+ /* prevent fall-through, we're not called if off = 0 */ \
33137+ EMIT(0xcccccccc, 4); \
33138+ EMIT(0xcccccccc, 4); \
33139+ break; \
33140+ default: \
33141+ BUILD_BUG(); \
33142+ } \
33143+} while (0)
33144+
33145+#define EMIT2_off32(b1, b2, _off) \
33146+do { \
33147+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33148+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33149+ EMIT(randkey, 4); \
33150+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33151+ EMIT((_off) - randkey, 4); \
33152+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33153+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33154+ /* imul eax, ecx */ \
33155+ EMIT3(0x0f, 0xaf, 0xc1); \
33156+ } else { \
33157+ BUILD_BUG(); \
33158+ } \
33159+} while (0)
33160+#else
33161 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33162+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33163+#endif
33164
33165 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33166 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33167@@ -91,6 +168,24 @@ do { \
33168 #define X86_JBE 0x76
33169 #define X86_JA 0x77
33170
33171+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33172+#define APPEND_FLOW_VERIFY() \
33173+do { \
33174+ /* mov ecx, randkey */ \
33175+ EMIT1(0xb9); \
33176+ EMIT(randkey, 4); \
33177+ /* cmp ecx, randkey */ \
33178+ EMIT2(0x81, 0xf9); \
33179+ EMIT(randkey, 4); \
33180+ /* jz after 8 int 3s */ \
33181+ EMIT2(0x74, 0x08); \
33182+ EMIT(0xcccccccc, 4); \
33183+ EMIT(0xcccccccc, 4); \
33184+} while (0)
33185+#else
33186+#define APPEND_FLOW_VERIFY() do { } while (0)
33187+#endif
33188+
33189 #define EMIT_COND_JMP(op, offset) \
33190 do { \
33191 if (is_near(offset)) \
33192@@ -98,6 +193,7 @@ do { \
33193 else { \
33194 EMIT2(0x0f, op + 0x10); \
33195 EMIT(offset, 4); /* jxx .+off32 */ \
33196+ APPEND_FLOW_VERIFY(); \
33197 } \
33198 } while (0)
33199
33200@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33201 return -1;
33202 }
33203
33204-struct bpf_binary_header {
33205- unsigned int pages;
33206- /* Note : for security reasons, bpf code will follow a randomly
33207- * sized amount of int3 instructions
33208- */
33209- u8 image[];
33210-};
33211-
33212-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33213+/* Note : for security reasons, bpf code will follow a randomly
33214+ * sized amount of int3 instructions
33215+ */
33216+static u8 *bpf_alloc_binary(unsigned int proglen,
33217 u8 **image_ptr)
33218 {
33219 unsigned int sz, hole;
33220- struct bpf_binary_header *header;
33221+ u8 *header;
33222
33223 /* Most of BPF filters are really small,
33224 * but if some of them fill a page, allow at least
33225 * 128 extra bytes to insert a random section of int3
33226 */
33227- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33228- header = module_alloc(sz);
33229+ sz = round_up(proglen + 128, PAGE_SIZE);
33230+ header = module_alloc_exec(sz);
33231 if (!header)
33232 return NULL;
33233
33234+ pax_open_kernel();
33235 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33236+ pax_close_kernel();
33237
33238- header->pages = sz / PAGE_SIZE;
33239- hole = sz - (proglen + sizeof(*header));
33240+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33241
33242 /* insert a random number of int3 instructions before BPF code */
33243- *image_ptr = &header->image[prandom_u32() % hole];
33244+ *image_ptr = &header[prandom_u32() % hole];
33245 return header;
33246 }
33247
33248 void bpf_jit_compile(struct sk_filter *fp)
33249 {
33250- u8 temp[64];
33251+ u8 temp[MAX_INSTR_CODE_SIZE];
33252 u8 *prog;
33253 unsigned int proglen, oldproglen = 0;
33254 int ilen, i;
33255 int t_offset, f_offset;
33256 u8 t_op, f_op, seen = 0, pass;
33257 u8 *image = NULL;
33258- struct bpf_binary_header *header = NULL;
33259+ u8 *header = NULL;
33260 u8 *func;
33261 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33262 unsigned int cleanup_addr; /* epilogue code offset */
33263 unsigned int *addrs;
33264 const struct sock_filter *filter = fp->insns;
33265 int flen = fp->len;
33266+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33267+ unsigned int randkey;
33268+#endif
33269
33270 if (!bpf_jit_enable)
33271 return;
33272@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
33273 if (addrs == NULL)
33274 return;
33275
33276+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33277+ randkey = get_random_int();
33278+#endif
33279+
33280 /* Before first pass, make a rough estimation of addrs[]
33281- * each bpf instruction is translated to less than 64 bytes
33282+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33283 */
33284 for (proglen = 0, i = 0; i < flen; i++) {
33285- proglen += 64;
33286+ proglen += MAX_INSTR_CODE_SIZE;
33287 addrs[i] = proglen;
33288 }
33289 cleanup_addr = proglen; /* epilogue address */
33290@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33291 case BPF_S_ALU_MUL_K: /* A *= K */
33292 if (is_imm8(K))
33293 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33294- else {
33295- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33296- EMIT(K, 4);
33297- }
33298+ else
33299+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33300 break;
33301 case BPF_S_ALU_DIV_X: /* A /= X; */
33302 seen |= SEEN_XREG;
33303@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33304 break;
33305 }
33306 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33307+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33308+ DILUTE_CONST_SEQUENCE(K, randkey);
33309+#else
33310 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33311+#endif
33312 EMIT2(0xf7, 0xf1); /* div %ecx */
33313 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33314 break;
33315@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33316 if (K == 1)
33317 break;
33318 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33319+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33320+ DILUTE_CONST_SEQUENCE(K, randkey);
33321+#else
33322 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33323+#endif
33324 EMIT2(0xf7, 0xf1); /* div %ecx */
33325 break;
33326 case BPF_S_ALU_AND_X:
33327@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33328 if (is_imm8(K)) {
33329 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33330 } else {
33331- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33332- EMIT(K, 4);
33333+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33334 }
33335 } else {
33336 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33337@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33338 if (unlikely(proglen + ilen > oldproglen)) {
33339 pr_err("bpb_jit_compile fatal error\n");
33340 kfree(addrs);
33341- module_free(NULL, header);
33342+ module_free_exec(NULL, image);
33343 return;
33344 }
33345+ pax_open_kernel();
33346 memcpy(image + proglen, temp, ilen);
33347+ pax_close_kernel();
33348 }
33349 proglen += ilen;
33350 addrs[i] = proglen;
33351@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33352
33353 if (image) {
33354 bpf_flush_icache(header, image + proglen);
33355- set_memory_ro((unsigned long)header, header->pages);
33356 fp->bpf_func = (void *)image;
33357 }
33358 out:
33359@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33360 {
33361 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33362 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33363- struct bpf_binary_header *header = (void *)addr;
33364
33365- set_memory_rw(addr, header->pages);
33366- module_free(NULL, header);
33367+ set_memory_rw(addr, 1);
33368+ module_free_exec(NULL, (void *)addr);
33369 kfree(fp);
33370 }
33371
33372diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33373index 5d04be5..2beeaa2 100644
33374--- a/arch/x86/oprofile/backtrace.c
33375+++ b/arch/x86/oprofile/backtrace.c
33376@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33377 struct stack_frame_ia32 *fp;
33378 unsigned long bytes;
33379
33380- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33381+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33382 if (bytes != 0)
33383 return NULL;
33384
33385- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33386+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33387
33388 oprofile_add_trace(bufhead[0].return_address);
33389
33390@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33391 struct stack_frame bufhead[2];
33392 unsigned long bytes;
33393
33394- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33395+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33396 if (bytes != 0)
33397 return NULL;
33398
33399@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33400 {
33401 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33402
33403- if (!user_mode_vm(regs)) {
33404+ if (!user_mode(regs)) {
33405 unsigned long stack = kernel_stack_pointer(regs);
33406 if (depth)
33407 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33408diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33409index 6890d84..1dad1f1 100644
33410--- a/arch/x86/oprofile/nmi_int.c
33411+++ b/arch/x86/oprofile/nmi_int.c
33412@@ -23,6 +23,7 @@
33413 #include <asm/nmi.h>
33414 #include <asm/msr.h>
33415 #include <asm/apic.h>
33416+#include <asm/pgtable.h>
33417
33418 #include "op_counter.h"
33419 #include "op_x86_model.h"
33420@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33421 if (ret)
33422 return ret;
33423
33424- if (!model->num_virt_counters)
33425- model->num_virt_counters = model->num_counters;
33426+ if (!model->num_virt_counters) {
33427+ pax_open_kernel();
33428+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
33429+ pax_close_kernel();
33430+ }
33431
33432 mux_init(ops);
33433
33434diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33435index 50d86c0..7985318 100644
33436--- a/arch/x86/oprofile/op_model_amd.c
33437+++ b/arch/x86/oprofile/op_model_amd.c
33438@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33439 num_counters = AMD64_NUM_COUNTERS;
33440 }
33441
33442- op_amd_spec.num_counters = num_counters;
33443- op_amd_spec.num_controls = num_counters;
33444- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33445+ pax_open_kernel();
33446+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33447+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33448+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33449+ pax_close_kernel();
33450
33451 return 0;
33452 }
33453diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33454index d90528e..0127e2b 100644
33455--- a/arch/x86/oprofile/op_model_ppro.c
33456+++ b/arch/x86/oprofile/op_model_ppro.c
33457@@ -19,6 +19,7 @@
33458 #include <asm/msr.h>
33459 #include <asm/apic.h>
33460 #include <asm/nmi.h>
33461+#include <asm/pgtable.h>
33462
33463 #include "op_x86_model.h"
33464 #include "op_counter.h"
33465@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33466
33467 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33468
33469- op_arch_perfmon_spec.num_counters = num_counters;
33470- op_arch_perfmon_spec.num_controls = num_counters;
33471+ pax_open_kernel();
33472+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33473+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33474+ pax_close_kernel();
33475 }
33476
33477 static int arch_perfmon_init(struct oprofile_operations *ignore)
33478diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33479index 71e8a67..6a313bb 100644
33480--- a/arch/x86/oprofile/op_x86_model.h
33481+++ b/arch/x86/oprofile/op_x86_model.h
33482@@ -52,7 +52,7 @@ struct op_x86_model_spec {
33483 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33484 struct op_msrs const * const msrs);
33485 #endif
33486-};
33487+} __do_const;
33488
33489 struct op_counter_config;
33490
33491diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
33492index 51384ca..a25f51e 100644
33493--- a/arch/x86/pci/intel_mid_pci.c
33494+++ b/arch/x86/pci/intel_mid_pci.c
33495@@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
33496 pr_info("Intel MID platform detected, using MID PCI ops\n");
33497 pci_mmcfg_late_init();
33498 pcibios_enable_irq = intel_mid_pci_irq_enable;
33499- pci_root_ops = intel_mid_pci_ops;
33500+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
33501 pci_soc_mode = 1;
33502 /* Continue with standard init */
33503 return 1;
33504diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33505index 372e9b8..e775a6c 100644
33506--- a/arch/x86/pci/irq.c
33507+++ b/arch/x86/pci/irq.c
33508@@ -50,7 +50,7 @@ struct irq_router {
33509 struct irq_router_handler {
33510 u16 vendor;
33511 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33512-};
33513+} __do_const;
33514
33515 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33516 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33517@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33518 return 0;
33519 }
33520
33521-static __initdata struct irq_router_handler pirq_routers[] = {
33522+static __initconst const struct irq_router_handler pirq_routers[] = {
33523 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33524 { PCI_VENDOR_ID_AL, ali_router_probe },
33525 { PCI_VENDOR_ID_ITE, ite_router_probe },
33526@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33527 static void __init pirq_find_router(struct irq_router *r)
33528 {
33529 struct irq_routing_table *rt = pirq_table;
33530- struct irq_router_handler *h;
33531+ const struct irq_router_handler *h;
33532
33533 #ifdef CONFIG_PCI_BIOS
33534 if (!rt->signature) {
33535@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33536 return 0;
33537 }
33538
33539-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33540+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33541 {
33542 .callback = fix_broken_hp_bios_irq9,
33543 .ident = "HP Pavilion N5400 Series Laptop",
33544diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33545index c77b24a..c979855 100644
33546--- a/arch/x86/pci/pcbios.c
33547+++ b/arch/x86/pci/pcbios.c
33548@@ -79,7 +79,7 @@ union bios32 {
33549 static struct {
33550 unsigned long address;
33551 unsigned short segment;
33552-} bios32_indirect = { 0, __KERNEL_CS };
33553+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33554
33555 /*
33556 * Returns the entry point for the given service, NULL on error
33557@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33558 unsigned long length; /* %ecx */
33559 unsigned long entry; /* %edx */
33560 unsigned long flags;
33561+ struct desc_struct d, *gdt;
33562
33563 local_irq_save(flags);
33564- __asm__("lcall *(%%edi); cld"
33565+
33566+ gdt = get_cpu_gdt_table(smp_processor_id());
33567+
33568+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33569+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33570+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33571+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33572+
33573+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33574 : "=a" (return_code),
33575 "=b" (address),
33576 "=c" (length),
33577 "=d" (entry)
33578 : "0" (service),
33579 "1" (0),
33580- "D" (&bios32_indirect));
33581+ "D" (&bios32_indirect),
33582+ "r"(__PCIBIOS_DS)
33583+ : "memory");
33584+
33585+ pax_open_kernel();
33586+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33587+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33588+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33589+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33590+ pax_close_kernel();
33591+
33592 local_irq_restore(flags);
33593
33594 switch (return_code) {
33595- case 0:
33596- return address + entry;
33597- case 0x80: /* Not present */
33598- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33599- return 0;
33600- default: /* Shouldn't happen */
33601- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33602- service, return_code);
33603+ case 0: {
33604+ int cpu;
33605+ unsigned char flags;
33606+
33607+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33608+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33609+ printk(KERN_WARNING "bios32_service: not valid\n");
33610 return 0;
33611+ }
33612+ address = address + PAGE_OFFSET;
33613+ length += 16UL; /* some BIOSs underreport this... */
33614+ flags = 4;
33615+ if (length >= 64*1024*1024) {
33616+ length >>= PAGE_SHIFT;
33617+ flags |= 8;
33618+ }
33619+
33620+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33621+ gdt = get_cpu_gdt_table(cpu);
33622+ pack_descriptor(&d, address, length, 0x9b, flags);
33623+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33624+ pack_descriptor(&d, address, length, 0x93, flags);
33625+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33626+ }
33627+ return entry;
33628+ }
33629+ case 0x80: /* Not present */
33630+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33631+ return 0;
33632+ default: /* Shouldn't happen */
33633+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33634+ service, return_code);
33635+ return 0;
33636 }
33637 }
33638
33639 static struct {
33640 unsigned long address;
33641 unsigned short segment;
33642-} pci_indirect = { 0, __KERNEL_CS };
33643+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33644
33645-static int pci_bios_present;
33646+static int pci_bios_present __read_only;
33647
33648 static int check_pcibios(void)
33649 {
33650@@ -131,11 +174,13 @@ static int check_pcibios(void)
33651 unsigned long flags, pcibios_entry;
33652
33653 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33654- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33655+ pci_indirect.address = pcibios_entry;
33656
33657 local_irq_save(flags);
33658- __asm__(
33659- "lcall *(%%edi); cld\n\t"
33660+ __asm__("movw %w6, %%ds\n\t"
33661+ "lcall *%%ss:(%%edi); cld\n\t"
33662+ "push %%ss\n\t"
33663+ "pop %%ds\n\t"
33664 "jc 1f\n\t"
33665 "xor %%ah, %%ah\n"
33666 "1:"
33667@@ -144,7 +189,8 @@ static int check_pcibios(void)
33668 "=b" (ebx),
33669 "=c" (ecx)
33670 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33671- "D" (&pci_indirect)
33672+ "D" (&pci_indirect),
33673+ "r" (__PCIBIOS_DS)
33674 : "memory");
33675 local_irq_restore(flags);
33676
33677@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33678
33679 switch (len) {
33680 case 1:
33681- __asm__("lcall *(%%esi); cld\n\t"
33682+ __asm__("movw %w6, %%ds\n\t"
33683+ "lcall *%%ss:(%%esi); cld\n\t"
33684+ "push %%ss\n\t"
33685+ "pop %%ds\n\t"
33686 "jc 1f\n\t"
33687 "xor %%ah, %%ah\n"
33688 "1:"
33689@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33690 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33691 "b" (bx),
33692 "D" ((long)reg),
33693- "S" (&pci_indirect));
33694+ "S" (&pci_indirect),
33695+ "r" (__PCIBIOS_DS));
33696 /*
33697 * Zero-extend the result beyond 8 bits, do not trust the
33698 * BIOS having done it:
33699@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33700 *value &= 0xff;
33701 break;
33702 case 2:
33703- __asm__("lcall *(%%esi); cld\n\t"
33704+ __asm__("movw %w6, %%ds\n\t"
33705+ "lcall *%%ss:(%%esi); cld\n\t"
33706+ "push %%ss\n\t"
33707+ "pop %%ds\n\t"
33708 "jc 1f\n\t"
33709 "xor %%ah, %%ah\n"
33710 "1:"
33711@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33712 : "1" (PCIBIOS_READ_CONFIG_WORD),
33713 "b" (bx),
33714 "D" ((long)reg),
33715- "S" (&pci_indirect));
33716+ "S" (&pci_indirect),
33717+ "r" (__PCIBIOS_DS));
33718 /*
33719 * Zero-extend the result beyond 16 bits, do not trust the
33720 * BIOS having done it:
33721@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33722 *value &= 0xffff;
33723 break;
33724 case 4:
33725- __asm__("lcall *(%%esi); cld\n\t"
33726+ __asm__("movw %w6, %%ds\n\t"
33727+ "lcall *%%ss:(%%esi); cld\n\t"
33728+ "push %%ss\n\t"
33729+ "pop %%ds\n\t"
33730 "jc 1f\n\t"
33731 "xor %%ah, %%ah\n"
33732 "1:"
33733@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33734 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33735 "b" (bx),
33736 "D" ((long)reg),
33737- "S" (&pci_indirect));
33738+ "S" (&pci_indirect),
33739+ "r" (__PCIBIOS_DS));
33740 break;
33741 }
33742
33743@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33744
33745 switch (len) {
33746 case 1:
33747- __asm__("lcall *(%%esi); cld\n\t"
33748+ __asm__("movw %w6, %%ds\n\t"
33749+ "lcall *%%ss:(%%esi); cld\n\t"
33750+ "push %%ss\n\t"
33751+ "pop %%ds\n\t"
33752 "jc 1f\n\t"
33753 "xor %%ah, %%ah\n"
33754 "1:"
33755@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33756 "c" (value),
33757 "b" (bx),
33758 "D" ((long)reg),
33759- "S" (&pci_indirect));
33760+ "S" (&pci_indirect),
33761+ "r" (__PCIBIOS_DS));
33762 break;
33763 case 2:
33764- __asm__("lcall *(%%esi); cld\n\t"
33765+ __asm__("movw %w6, %%ds\n\t"
33766+ "lcall *%%ss:(%%esi); cld\n\t"
33767+ "push %%ss\n\t"
33768+ "pop %%ds\n\t"
33769 "jc 1f\n\t"
33770 "xor %%ah, %%ah\n"
33771 "1:"
33772@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33773 "c" (value),
33774 "b" (bx),
33775 "D" ((long)reg),
33776- "S" (&pci_indirect));
33777+ "S" (&pci_indirect),
33778+ "r" (__PCIBIOS_DS));
33779 break;
33780 case 4:
33781- __asm__("lcall *(%%esi); cld\n\t"
33782+ __asm__("movw %w6, %%ds\n\t"
33783+ "lcall *%%ss:(%%esi); cld\n\t"
33784+ "push %%ss\n\t"
33785+ "pop %%ds\n\t"
33786 "jc 1f\n\t"
33787 "xor %%ah, %%ah\n"
33788 "1:"
33789@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33790 "c" (value),
33791 "b" (bx),
33792 "D" ((long)reg),
33793- "S" (&pci_indirect));
33794+ "S" (&pci_indirect),
33795+ "r" (__PCIBIOS_DS));
33796 break;
33797 }
33798
33799@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33800
33801 DBG("PCI: Fetching IRQ routing table... ");
33802 __asm__("push %%es\n\t"
33803+ "movw %w8, %%ds\n\t"
33804 "push %%ds\n\t"
33805 "pop %%es\n\t"
33806- "lcall *(%%esi); cld\n\t"
33807+ "lcall *%%ss:(%%esi); cld\n\t"
33808 "pop %%es\n\t"
33809+ "push %%ss\n\t"
33810+ "pop %%ds\n"
33811 "jc 1f\n\t"
33812 "xor %%ah, %%ah\n"
33813 "1:"
33814@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33815 "1" (0),
33816 "D" ((long) &opt),
33817 "S" (&pci_indirect),
33818- "m" (opt)
33819+ "m" (opt),
33820+ "r" (__PCIBIOS_DS)
33821 : "memory");
33822 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33823 if (ret & 0xff00)
33824@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33825 {
33826 int ret;
33827
33828- __asm__("lcall *(%%esi); cld\n\t"
33829+ __asm__("movw %w5, %%ds\n\t"
33830+ "lcall *%%ss:(%%esi); cld\n\t"
33831+ "push %%ss\n\t"
33832+ "pop %%ds\n"
33833 "jc 1f\n\t"
33834 "xor %%ah, %%ah\n"
33835 "1:"
33836@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33837 : "0" (PCIBIOS_SET_PCI_HW_INT),
33838 "b" ((dev->bus->number << 8) | dev->devfn),
33839 "c" ((irq << 8) | (pin + 10)),
33840- "S" (&pci_indirect));
33841+ "S" (&pci_indirect),
33842+ "r" (__PCIBIOS_DS));
33843 return !(ret & 0xff00);
33844 }
33845 EXPORT_SYMBOL(pcibios_set_irq_routing);
33846diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33847index 40e4469..d915bf9 100644
33848--- a/arch/x86/platform/efi/efi_32.c
33849+++ b/arch/x86/platform/efi/efi_32.c
33850@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33851 {
33852 struct desc_ptr gdt_descr;
33853
33854+#ifdef CONFIG_PAX_KERNEXEC
33855+ struct desc_struct d;
33856+#endif
33857+
33858 local_irq_save(efi_rt_eflags);
33859
33860 load_cr3(initial_page_table);
33861 __flush_tlb_all();
33862
33863+#ifdef CONFIG_PAX_KERNEXEC
33864+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33865+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33866+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33867+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33868+#endif
33869+
33870 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33871 gdt_descr.size = GDT_SIZE - 1;
33872 load_gdt(&gdt_descr);
33873@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33874 {
33875 struct desc_ptr gdt_descr;
33876
33877+#ifdef CONFIG_PAX_KERNEXEC
33878+ struct desc_struct d;
33879+
33880+ memset(&d, 0, sizeof d);
33881+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33882+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33883+#endif
33884+
33885 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33886 gdt_descr.size = GDT_SIZE - 1;
33887 load_gdt(&gdt_descr);
33888
33889+#ifdef CONFIG_PAX_PER_CPU_PGD
33890+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33891+#else
33892 load_cr3(swapper_pg_dir);
33893+#endif
33894+
33895 __flush_tlb_all();
33896
33897 local_irq_restore(efi_rt_eflags);
33898diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33899index 39a0e7f1..872396e 100644
33900--- a/arch/x86/platform/efi/efi_64.c
33901+++ b/arch/x86/platform/efi/efi_64.c
33902@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33903 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33904 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33905 }
33906+
33907+#ifdef CONFIG_PAX_PER_CPU_PGD
33908+ load_cr3(swapper_pg_dir);
33909+#endif
33910+
33911 __flush_tlb_all();
33912 }
33913
33914@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33915 for (pgd = 0; pgd < n_pgds; pgd++)
33916 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33917 kfree(save_pgd);
33918+
33919+#ifdef CONFIG_PAX_PER_CPU_PGD
33920+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33921+#endif
33922+
33923 __flush_tlb_all();
33924 local_irq_restore(efi_flags);
33925 early_code_mapping_set_exec(0);
33926diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33927index fbe66e6..eae5e38 100644
33928--- a/arch/x86/platform/efi/efi_stub_32.S
33929+++ b/arch/x86/platform/efi/efi_stub_32.S
33930@@ -6,7 +6,9 @@
33931 */
33932
33933 #include <linux/linkage.h>
33934+#include <linux/init.h>
33935 #include <asm/page_types.h>
33936+#include <asm/segment.h>
33937
33938 /*
33939 * efi_call_phys(void *, ...) is a function with variable parameters.
33940@@ -20,7 +22,7 @@
33941 * service functions will comply with gcc calling convention, too.
33942 */
33943
33944-.text
33945+__INIT
33946 ENTRY(efi_call_phys)
33947 /*
33948 * 0. The function can only be called in Linux kernel. So CS has been
33949@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33950 * The mapping of lower virtual memory has been created in prelog and
33951 * epilog.
33952 */
33953- movl $1f, %edx
33954- subl $__PAGE_OFFSET, %edx
33955- jmp *%edx
33956+#ifdef CONFIG_PAX_KERNEXEC
33957+ movl $(__KERNEXEC_EFI_DS), %edx
33958+ mov %edx, %ds
33959+ mov %edx, %es
33960+ mov %edx, %ss
33961+ addl $2f,(1f)
33962+ ljmp *(1f)
33963+
33964+__INITDATA
33965+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33966+.previous
33967+
33968+2:
33969+ subl $2b,(1b)
33970+#else
33971+ jmp 1f-__PAGE_OFFSET
33972 1:
33973+#endif
33974
33975 /*
33976 * 2. Now on the top of stack is the return
33977@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33978 * parameter 2, ..., param n. To make things easy, we save the return
33979 * address of efi_call_phys in a global variable.
33980 */
33981- popl %edx
33982- movl %edx, saved_return_addr
33983- /* get the function pointer into ECX*/
33984- popl %ecx
33985- movl %ecx, efi_rt_function_ptr
33986- movl $2f, %edx
33987- subl $__PAGE_OFFSET, %edx
33988- pushl %edx
33989+ popl (saved_return_addr)
33990+ popl (efi_rt_function_ptr)
33991
33992 /*
33993 * 3. Clear PG bit in %CR0.
33994@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33995 /*
33996 * 5. Call the physical function.
33997 */
33998- jmp *%ecx
33999+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34000
34001-2:
34002 /*
34003 * 6. After EFI runtime service returns, control will return to
34004 * following instruction. We'd better readjust stack pointer first.
34005@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34006 movl %cr0, %edx
34007 orl $0x80000000, %edx
34008 movl %edx, %cr0
34009- jmp 1f
34010-1:
34011+
34012 /*
34013 * 8. Now restore the virtual mode from flat mode by
34014 * adding EIP with PAGE_OFFSET.
34015 */
34016- movl $1f, %edx
34017- jmp *%edx
34018+#ifdef CONFIG_PAX_KERNEXEC
34019+ movl $(__KERNEL_DS), %edx
34020+ mov %edx, %ds
34021+ mov %edx, %es
34022+ mov %edx, %ss
34023+ ljmp $(__KERNEL_CS),$1f
34024+#else
34025+ jmp 1f+__PAGE_OFFSET
34026+#endif
34027 1:
34028
34029 /*
34030 * 9. Balance the stack. And because EAX contain the return value,
34031 * we'd better not clobber it.
34032 */
34033- leal efi_rt_function_ptr, %edx
34034- movl (%edx), %ecx
34035- pushl %ecx
34036+ pushl (efi_rt_function_ptr)
34037
34038 /*
34039- * 10. Push the saved return address onto the stack and return.
34040+ * 10. Return to the saved return address.
34041 */
34042- leal saved_return_addr, %edx
34043- movl (%edx), %ecx
34044- pushl %ecx
34045- ret
34046+ jmpl *(saved_return_addr)
34047 ENDPROC(efi_call_phys)
34048 .previous
34049
34050-.data
34051+__INITDATA
34052 saved_return_addr:
34053 .long 0
34054 efi_rt_function_ptr:
34055diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34056index 4c07cca..2c8427d 100644
34057--- a/arch/x86/platform/efi/efi_stub_64.S
34058+++ b/arch/x86/platform/efi/efi_stub_64.S
34059@@ -7,6 +7,7 @@
34060 */
34061
34062 #include <linux/linkage.h>
34063+#include <asm/alternative-asm.h>
34064
34065 #define SAVE_XMM \
34066 mov %rsp, %rax; \
34067@@ -40,6 +41,7 @@ ENTRY(efi_call0)
34068 call *%rdi
34069 addq $32, %rsp
34070 RESTORE_XMM
34071+ pax_force_retaddr 0, 1
34072 ret
34073 ENDPROC(efi_call0)
34074
34075@@ -50,6 +52,7 @@ ENTRY(efi_call1)
34076 call *%rdi
34077 addq $32, %rsp
34078 RESTORE_XMM
34079+ pax_force_retaddr 0, 1
34080 ret
34081 ENDPROC(efi_call1)
34082
34083@@ -60,6 +63,7 @@ ENTRY(efi_call2)
34084 call *%rdi
34085 addq $32, %rsp
34086 RESTORE_XMM
34087+ pax_force_retaddr 0, 1
34088 ret
34089 ENDPROC(efi_call2)
34090
34091@@ -71,6 +75,7 @@ ENTRY(efi_call3)
34092 call *%rdi
34093 addq $32, %rsp
34094 RESTORE_XMM
34095+ pax_force_retaddr 0, 1
34096 ret
34097 ENDPROC(efi_call3)
34098
34099@@ -83,6 +88,7 @@ ENTRY(efi_call4)
34100 call *%rdi
34101 addq $32, %rsp
34102 RESTORE_XMM
34103+ pax_force_retaddr 0, 1
34104 ret
34105 ENDPROC(efi_call4)
34106
34107@@ -96,6 +102,7 @@ ENTRY(efi_call5)
34108 call *%rdi
34109 addq $48, %rsp
34110 RESTORE_XMM
34111+ pax_force_retaddr 0, 1
34112 ret
34113 ENDPROC(efi_call5)
34114
34115@@ -112,5 +119,6 @@ ENTRY(efi_call6)
34116 call *%rdi
34117 addq $48, %rsp
34118 RESTORE_XMM
34119+ pax_force_retaddr 0, 1
34120 ret
34121 ENDPROC(efi_call6)
34122diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34123index f90e290..435f0dd 100644
34124--- a/arch/x86/platform/intel-mid/intel-mid.c
34125+++ b/arch/x86/platform/intel-mid/intel-mid.c
34126@@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34127 {
34128 }
34129
34130-static void intel_mid_reboot(void)
34131+static void __noreturn intel_mid_reboot(void)
34132 {
34133 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34134+ BUG();
34135 }
34136
34137 static unsigned long __init intel_mid_calibrate_tsc(void)
34138diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34139index d6ee929..3637cb5 100644
34140--- a/arch/x86/platform/olpc/olpc_dt.c
34141+++ b/arch/x86/platform/olpc/olpc_dt.c
34142@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34143 return res;
34144 }
34145
34146-static struct of_pdt_ops prom_olpc_ops __initdata = {
34147+static struct of_pdt_ops prom_olpc_ops __initconst = {
34148 .nextprop = olpc_dt_nextprop,
34149 .getproplen = olpc_dt_getproplen,
34150 .getproperty = olpc_dt_getproperty,
34151diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34152index 424f4c9..f2a2988 100644
34153--- a/arch/x86/power/cpu.c
34154+++ b/arch/x86/power/cpu.c
34155@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34156 static void fix_processor_context(void)
34157 {
34158 int cpu = smp_processor_id();
34159- struct tss_struct *t = &per_cpu(init_tss, cpu);
34160-#ifdef CONFIG_X86_64
34161- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34162- tss_desc tss;
34163-#endif
34164+ struct tss_struct *t = init_tss + cpu;
34165+
34166 set_tss_desc(cpu, t); /*
34167 * This just modifies memory; should not be
34168 * necessary. But... This is necessary, because
34169@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34170 */
34171
34172 #ifdef CONFIG_X86_64
34173- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34174- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34175- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34176-
34177 syscall_init(); /* This sets MSR_*STAR and related */
34178 #endif
34179 load_TR_desc(); /* This does ltr */
34180diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34181index a44f457..9140171 100644
34182--- a/arch/x86/realmode/init.c
34183+++ b/arch/x86/realmode/init.c
34184@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34185 __va(real_mode_header->trampoline_header);
34186
34187 #ifdef CONFIG_X86_32
34188- trampoline_header->start = __pa_symbol(startup_32_smp);
34189+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34190+
34191+#ifdef CONFIG_PAX_KERNEXEC
34192+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34193+#endif
34194+
34195+ trampoline_header->boot_cs = __BOOT_CS;
34196 trampoline_header->gdt_limit = __BOOT_DS + 7;
34197 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34198 #else
34199@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34200 *trampoline_cr4_features = read_cr4();
34201
34202 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34203- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34204+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34205 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34206 #endif
34207 }
34208diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34209index 9cac825..4890b25 100644
34210--- a/arch/x86/realmode/rm/Makefile
34211+++ b/arch/x86/realmode/rm/Makefile
34212@@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34213 $(call cc-option, -fno-unit-at-a-time)) \
34214 $(call cc-option, -fno-stack-protector) \
34215 $(call cc-option, -mpreferred-stack-boundary=2)
34216+ifdef CONSTIFY_PLUGIN
34217+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34218+endif
34219 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34220 GCOV_PROFILE := n
34221diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34222index a28221d..93c40f1 100644
34223--- a/arch/x86/realmode/rm/header.S
34224+++ b/arch/x86/realmode/rm/header.S
34225@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34226 #endif
34227 /* APM/BIOS reboot */
34228 .long pa_machine_real_restart_asm
34229-#ifdef CONFIG_X86_64
34230+#ifdef CONFIG_X86_32
34231+ .long __KERNEL_CS
34232+#else
34233 .long __KERNEL32_CS
34234 #endif
34235 END(real_mode_header)
34236diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34237index c1b2791..f9e31c7 100644
34238--- a/arch/x86/realmode/rm/trampoline_32.S
34239+++ b/arch/x86/realmode/rm/trampoline_32.S
34240@@ -25,6 +25,12 @@
34241 #include <asm/page_types.h>
34242 #include "realmode.h"
34243
34244+#ifdef CONFIG_PAX_KERNEXEC
34245+#define ta(X) (X)
34246+#else
34247+#define ta(X) (pa_ ## X)
34248+#endif
34249+
34250 .text
34251 .code16
34252
34253@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34254
34255 cli # We should be safe anyway
34256
34257- movl tr_start, %eax # where we need to go
34258-
34259 movl $0xA5A5A5A5, trampoline_status
34260 # write marker for master knows we're running
34261
34262@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34263 movw $1, %dx # protected mode (PE) bit
34264 lmsw %dx # into protected mode
34265
34266- ljmpl $__BOOT_CS, $pa_startup_32
34267+ ljmpl *(trampoline_header)
34268
34269 .section ".text32","ax"
34270 .code32
34271@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34272 .balign 8
34273 GLOBAL(trampoline_header)
34274 tr_start: .space 4
34275- tr_gdt_pad: .space 2
34276+ tr_boot_cs: .space 2
34277 tr_gdt: .space 6
34278 END(trampoline_header)
34279
34280diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34281index bb360dc..d0fd8f8 100644
34282--- a/arch/x86/realmode/rm/trampoline_64.S
34283+++ b/arch/x86/realmode/rm/trampoline_64.S
34284@@ -94,6 +94,7 @@ ENTRY(startup_32)
34285 movl %edx, %gs
34286
34287 movl pa_tr_cr4, %eax
34288+ andl $~X86_CR4_PCIDE, %eax
34289 movl %eax, %cr4 # Enable PAE mode
34290
34291 # Setup trampoline 4 level pagetables
34292@@ -107,7 +108,7 @@ ENTRY(startup_32)
34293 wrmsr
34294
34295 # Enable paging and in turn activate Long Mode
34296- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34297+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34298 movl %eax, %cr0
34299
34300 /*
34301diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34302index e812034..c747134 100644
34303--- a/arch/x86/tools/Makefile
34304+++ b/arch/x86/tools/Makefile
34305@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34306
34307 $(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
34308
34309-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34310+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34311 hostprogs-y += relocs
34312 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34313 relocs: $(obj)/relocs
34314diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34315index f7bab68..b6d9886 100644
34316--- a/arch/x86/tools/relocs.c
34317+++ b/arch/x86/tools/relocs.c
34318@@ -1,5 +1,7 @@
34319 /* This is included from relocs_32/64.c */
34320
34321+#include "../../../include/generated/autoconf.h"
34322+
34323 #define ElfW(type) _ElfW(ELF_BITS, type)
34324 #define _ElfW(bits, type) __ElfW(bits, type)
34325 #define __ElfW(bits, type) Elf##bits##_##type
34326@@ -11,6 +13,7 @@
34327 #define Elf_Sym ElfW(Sym)
34328
34329 static Elf_Ehdr ehdr;
34330+static Elf_Phdr *phdr;
34331
34332 struct relocs {
34333 uint32_t *offset;
34334@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34335 }
34336 }
34337
34338+static void read_phdrs(FILE *fp)
34339+{
34340+ unsigned int i;
34341+
34342+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34343+ if (!phdr) {
34344+ die("Unable to allocate %d program headers\n",
34345+ ehdr.e_phnum);
34346+ }
34347+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34348+ die("Seek to %d failed: %s\n",
34349+ ehdr.e_phoff, strerror(errno));
34350+ }
34351+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34352+ die("Cannot read ELF program headers: %s\n",
34353+ strerror(errno));
34354+ }
34355+ for(i = 0; i < ehdr.e_phnum; i++) {
34356+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34357+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34358+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34359+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34360+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34361+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34362+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34363+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34364+ }
34365+
34366+}
34367+
34368 static void read_shdrs(FILE *fp)
34369 {
34370- int i;
34371+ unsigned int i;
34372 Elf_Shdr shdr;
34373
34374 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34375@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34376
34377 static void read_strtabs(FILE *fp)
34378 {
34379- int i;
34380+ unsigned int i;
34381 for (i = 0; i < ehdr.e_shnum; i++) {
34382 struct section *sec = &secs[i];
34383 if (sec->shdr.sh_type != SHT_STRTAB) {
34384@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34385
34386 static void read_symtabs(FILE *fp)
34387 {
34388- int i,j;
34389+ unsigned int i,j;
34390 for (i = 0; i < ehdr.e_shnum; i++) {
34391 struct section *sec = &secs[i];
34392 if (sec->shdr.sh_type != SHT_SYMTAB) {
34393@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34394 }
34395
34396
34397-static void read_relocs(FILE *fp)
34398+static void read_relocs(FILE *fp, int use_real_mode)
34399 {
34400- int i,j;
34401+ unsigned int i,j;
34402+ uint32_t base;
34403+
34404 for (i = 0; i < ehdr.e_shnum; i++) {
34405 struct section *sec = &secs[i];
34406 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34407@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34408 die("Cannot read symbol table: %s\n",
34409 strerror(errno));
34410 }
34411+ base = 0;
34412+
34413+#ifdef CONFIG_X86_32
34414+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34415+ if (phdr[j].p_type != PT_LOAD )
34416+ continue;
34417+ 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)
34418+ continue;
34419+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34420+ break;
34421+ }
34422+#endif
34423+
34424 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34425 Elf_Rel *rel = &sec->reltab[j];
34426- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34427+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34428 rel->r_info = elf_xword_to_cpu(rel->r_info);
34429 #if (SHT_REL_TYPE == SHT_RELA)
34430 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34431@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34432
34433 static void print_absolute_symbols(void)
34434 {
34435- int i;
34436+ unsigned int i;
34437 const char *format;
34438
34439 if (ELF_BITS == 64)
34440@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34441 for (i = 0; i < ehdr.e_shnum; i++) {
34442 struct section *sec = &secs[i];
34443 char *sym_strtab;
34444- int j;
34445+ unsigned int j;
34446
34447 if (sec->shdr.sh_type != SHT_SYMTAB) {
34448 continue;
34449@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34450
34451 static void print_absolute_relocs(void)
34452 {
34453- int i, printed = 0;
34454+ unsigned int i, printed = 0;
34455 const char *format;
34456
34457 if (ELF_BITS == 64)
34458@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34459 struct section *sec_applies, *sec_symtab;
34460 char *sym_strtab;
34461 Elf_Sym *sh_symtab;
34462- int j;
34463+ unsigned int j;
34464 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34465 continue;
34466 }
34467@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34468 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34469 Elf_Sym *sym, const char *symname))
34470 {
34471- int i;
34472+ unsigned int i;
34473 /* Walk through the relocations */
34474 for (i = 0; i < ehdr.e_shnum; i++) {
34475 char *sym_strtab;
34476 Elf_Sym *sh_symtab;
34477 struct section *sec_applies, *sec_symtab;
34478- int j;
34479+ unsigned int j;
34480 struct section *sec = &secs[i];
34481
34482 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34483@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34484 {
34485 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34486 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34487+ char *sym_strtab = sec->link->link->strtab;
34488+
34489+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34490+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34491+ return 0;
34492+
34493+#ifdef CONFIG_PAX_KERNEXEC
34494+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34495+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34496+ return 0;
34497+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34498+ return 0;
34499+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34500+ return 0;
34501+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34502+ return 0;
34503+#endif
34504
34505 switch (r_type) {
34506 case R_386_NONE:
34507@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34508
34509 static void emit_relocs(int as_text, int use_real_mode)
34510 {
34511- int i;
34512+ unsigned int i;
34513 int (*write_reloc)(uint32_t, FILE *) = write32;
34514 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34515 const char *symname);
34516@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34517 {
34518 regex_init(use_real_mode);
34519 read_ehdr(fp);
34520+ read_phdrs(fp);
34521 read_shdrs(fp);
34522 read_strtabs(fp);
34523 read_symtabs(fp);
34524- read_relocs(fp);
34525+ read_relocs(fp, use_real_mode);
34526 if (ELF_BITS == 64)
34527 percpu_init();
34528 if (show_absolute_syms) {
34529diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34530index 80ffa5b..a33bd15 100644
34531--- a/arch/x86/um/tls_32.c
34532+++ b/arch/x86/um/tls_32.c
34533@@ -260,7 +260,7 @@ out:
34534 if (unlikely(task == current &&
34535 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34536 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34537- "without flushed TLS.", current->pid);
34538+ "without flushed TLS.", task_pid_nr(current));
34539 }
34540
34541 return 0;
34542diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34543index fd14be1..e3c79c0 100644
34544--- a/arch/x86/vdso/Makefile
34545+++ b/arch/x86/vdso/Makefile
34546@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34547 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34548 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34549
34550-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34551+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34552 GCOV_PROFILE := n
34553
34554 #
34555diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34556index d6bfb87..876ee18 100644
34557--- a/arch/x86/vdso/vdso32-setup.c
34558+++ b/arch/x86/vdso/vdso32-setup.c
34559@@ -25,6 +25,7 @@
34560 #include <asm/tlbflush.h>
34561 #include <asm/vdso.h>
34562 #include <asm/proto.h>
34563+#include <asm/mman.h>
34564
34565 enum {
34566 VDSO_DISABLED = 0,
34567@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34568 void enable_sep_cpu(void)
34569 {
34570 int cpu = get_cpu();
34571- struct tss_struct *tss = &per_cpu(init_tss, cpu);
34572+ struct tss_struct *tss = init_tss + cpu;
34573
34574 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34575 put_cpu();
34576@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34577 gate_vma.vm_start = FIXADDR_USER_START;
34578 gate_vma.vm_end = FIXADDR_USER_END;
34579 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34580- gate_vma.vm_page_prot = __P101;
34581+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34582
34583 return 0;
34584 }
34585@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34586 if (compat)
34587 addr = VDSO_HIGH_BASE;
34588 else {
34589- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34590+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34591 if (IS_ERR_VALUE(addr)) {
34592 ret = addr;
34593 goto up_fail;
34594 }
34595 }
34596
34597- current->mm->context.vdso = (void *)addr;
34598+ current->mm->context.vdso = addr;
34599
34600 if (compat_uses_vma || !compat) {
34601 /*
34602@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34603 }
34604
34605 current_thread_info()->sysenter_return =
34606- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34607+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34608
34609 up_fail:
34610 if (ret)
34611- current->mm->context.vdso = NULL;
34612+ current->mm->context.vdso = 0;
34613
34614 up_write(&mm->mmap_sem);
34615
34616@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34617
34618 const char *arch_vma_name(struct vm_area_struct *vma)
34619 {
34620- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34621+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34622 return "[vdso]";
34623+
34624+#ifdef CONFIG_PAX_SEGMEXEC
34625+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34626+ return "[vdso]";
34627+#endif
34628+
34629 return NULL;
34630 }
34631
34632@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34633 * Check to see if the corresponding task was created in compat vdso
34634 * mode.
34635 */
34636- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34637+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34638 return &gate_vma;
34639 return NULL;
34640 }
34641diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34642index 431e875..cbb23f3 100644
34643--- a/arch/x86/vdso/vma.c
34644+++ b/arch/x86/vdso/vma.c
34645@@ -16,8 +16,6 @@
34646 #include <asm/vdso.h>
34647 #include <asm/page.h>
34648
34649-unsigned int __read_mostly vdso_enabled = 1;
34650-
34651 extern char vdso_start[], vdso_end[];
34652 extern unsigned short vdso_sync_cpuid;
34653
34654@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34655 * unaligned here as a result of stack start randomization.
34656 */
34657 addr = PAGE_ALIGN(addr);
34658- addr = align_vdso_addr(addr);
34659
34660 return addr;
34661 }
34662@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34663 unsigned size)
34664 {
34665 struct mm_struct *mm = current->mm;
34666- unsigned long addr;
34667+ unsigned long addr = 0;
34668 int ret;
34669
34670- if (!vdso_enabled)
34671- return 0;
34672-
34673 down_write(&mm->mmap_sem);
34674+
34675+#ifdef CONFIG_PAX_RANDMMAP
34676+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34677+#endif
34678+
34679 addr = vdso_addr(mm->start_stack, size);
34680+ addr = align_vdso_addr(addr);
34681 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34682 if (IS_ERR_VALUE(addr)) {
34683 ret = addr;
34684 goto up_fail;
34685 }
34686
34687- current->mm->context.vdso = (void *)addr;
34688+ mm->context.vdso = addr;
34689
34690 ret = install_special_mapping(mm, addr, size,
34691 VM_READ|VM_EXEC|
34692 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34693 pages);
34694- if (ret) {
34695- current->mm->context.vdso = NULL;
34696- goto up_fail;
34697- }
34698+ if (ret)
34699+ mm->context.vdso = 0;
34700
34701 up_fail:
34702 up_write(&mm->mmap_sem);
34703@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34704 vdsox32_size);
34705 }
34706 #endif
34707-
34708-static __init int vdso_setup(char *s)
34709-{
34710- vdso_enabled = simple_strtoul(s, NULL, 0);
34711- return 0;
34712-}
34713-__setup("vdso=", vdso_setup);
34714diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34715index fa6ade7..73da73a5 100644
34716--- a/arch/x86/xen/enlighten.c
34717+++ b/arch/x86/xen/enlighten.c
34718@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34719
34720 struct shared_info xen_dummy_shared_info;
34721
34722-void *xen_initial_gdt;
34723-
34724 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34725 __read_mostly int xen_have_vector_callback;
34726 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34727@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34728 {
34729 unsigned long va = dtr->address;
34730 unsigned int size = dtr->size + 1;
34731- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34732- unsigned long frames[pages];
34733+ unsigned long frames[65536 / PAGE_SIZE];
34734 int f;
34735
34736 /*
34737@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34738 {
34739 unsigned long va = dtr->address;
34740 unsigned int size = dtr->size + 1;
34741- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34742- unsigned long frames[pages];
34743+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34744 int f;
34745
34746 /*
34747@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34748 * 8-byte entries, or 16 4k pages..
34749 */
34750
34751- BUG_ON(size > 65536);
34752+ BUG_ON(size > GDT_SIZE);
34753 BUG_ON(va & ~PAGE_MASK);
34754
34755 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34756@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34757 return 0;
34758 }
34759
34760-static void set_xen_basic_apic_ops(void)
34761+static void __init set_xen_basic_apic_ops(void)
34762 {
34763 apic->read = xen_apic_read;
34764 apic->write = xen_apic_write;
34765@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34766 #endif
34767 };
34768
34769-static void xen_reboot(int reason)
34770+static __noreturn void xen_reboot(int reason)
34771 {
34772 struct sched_shutdown r = { .reason = reason };
34773
34774- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34775- BUG();
34776+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34777+ BUG();
34778 }
34779
34780-static void xen_restart(char *msg)
34781+static __noreturn void xen_restart(char *msg)
34782 {
34783 xen_reboot(SHUTDOWN_reboot);
34784 }
34785
34786-static void xen_emergency_restart(void)
34787+static __noreturn void xen_emergency_restart(void)
34788 {
34789 xen_reboot(SHUTDOWN_reboot);
34790 }
34791
34792-static void xen_machine_halt(void)
34793+static __noreturn void xen_machine_halt(void)
34794 {
34795 xen_reboot(SHUTDOWN_poweroff);
34796 }
34797
34798-static void xen_machine_power_off(void)
34799+static __noreturn void xen_machine_power_off(void)
34800 {
34801 if (pm_power_off)
34802 pm_power_off();
34803@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34804 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34805
34806 /* Work out if we support NX */
34807- x86_configure_nx();
34808+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34809+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34810+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34811+ unsigned l, h;
34812+
34813+ __supported_pte_mask |= _PAGE_NX;
34814+ rdmsr(MSR_EFER, l, h);
34815+ l |= EFER_NX;
34816+ wrmsr(MSR_EFER, l, h);
34817+ }
34818+#endif
34819
34820 xen_setup_features();
34821
34822@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34823
34824 machine_ops = xen_machine_ops;
34825
34826- /*
34827- * The only reliable way to retain the initial address of the
34828- * percpu gdt_page is to remember it here, so we can go and
34829- * mark it RW later, when the initial percpu area is freed.
34830- */
34831- xen_initial_gdt = &per_cpu(gdt_page, 0);
34832-
34833 xen_smp_init();
34834
34835 #ifdef CONFIG_ACPI_NUMA
34836diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34837index ce563be..7327d91 100644
34838--- a/arch/x86/xen/mmu.c
34839+++ b/arch/x86/xen/mmu.c
34840@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34841 return val;
34842 }
34843
34844-static pteval_t pte_pfn_to_mfn(pteval_t val)
34845+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34846 {
34847 if (val & _PAGE_PRESENT) {
34848 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34849@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34850 /* L3_k[510] -> level2_kernel_pgt
34851 * L3_i[511] -> level2_fixmap_pgt */
34852 convert_pfn_mfn(level3_kernel_pgt);
34853+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34854+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34855+ convert_pfn_mfn(level3_vmemmap_pgt);
34856
34857 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34858 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34859@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34860 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34861 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34862 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34863+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34864+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34865+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34866 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34867 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34868+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34869 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34870 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34871
34872@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34873 pv_mmu_ops.set_pud = xen_set_pud;
34874 #if PAGETABLE_LEVELS == 4
34875 pv_mmu_ops.set_pgd = xen_set_pgd;
34876+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34877 #endif
34878
34879 /* This will work as long as patching hasn't happened yet
34880@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34881 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34882 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34883 .set_pgd = xen_set_pgd_hyper,
34884+ .set_pgd_batched = xen_set_pgd_hyper,
34885
34886 .alloc_pud = xen_alloc_pmd_init,
34887 .release_pud = xen_release_pmd_init,
34888diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34889index c36b325..b0f1518 100644
34890--- a/arch/x86/xen/smp.c
34891+++ b/arch/x86/xen/smp.c
34892@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34893 native_smp_prepare_boot_cpu();
34894
34895 if (xen_pv_domain()) {
34896- /* We've switched to the "real" per-cpu gdt, so make sure the
34897- old memory can be recycled */
34898- make_lowmem_page_readwrite(xen_initial_gdt);
34899-
34900 #ifdef CONFIG_X86_32
34901 /*
34902 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34903 * expects __USER_DS
34904 */
34905- loadsegment(ds, __USER_DS);
34906- loadsegment(es, __USER_DS);
34907+ loadsegment(ds, __KERNEL_DS);
34908+ loadsegment(es, __KERNEL_DS);
34909 #endif
34910
34911 xen_filter_cpu_maps();
34912@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34913 ctxt->user_regs.ss = __KERNEL_DS;
34914 #ifdef CONFIG_X86_32
34915 ctxt->user_regs.fs = __KERNEL_PERCPU;
34916- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34917+ savesegment(gs, ctxt->user_regs.gs);
34918 #else
34919 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34920 #endif
34921@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34922
34923 {
34924 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34925- ctxt->user_regs.ds = __USER_DS;
34926- ctxt->user_regs.es = __USER_DS;
34927+ ctxt->user_regs.ds = __KERNEL_DS;
34928+ ctxt->user_regs.es = __KERNEL_DS;
34929
34930 xen_copy_trap_info(ctxt->trap_ctxt);
34931
34932@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34933 int rc;
34934
34935 per_cpu(current_task, cpu) = idle;
34936+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34937 #ifdef CONFIG_X86_32
34938 irq_ctx_init(cpu);
34939 #else
34940 clear_tsk_thread_flag(idle, TIF_FORK);
34941- per_cpu(kernel_stack, cpu) =
34942- (unsigned long)task_stack_page(idle) -
34943- KERNEL_STACK_OFFSET + THREAD_SIZE;
34944+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34945 #endif
34946 xen_setup_runstate_info(cpu);
34947 xen_setup_timer(cpu);
34948@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34949
34950 void __init xen_smp_init(void)
34951 {
34952- smp_ops = xen_smp_ops;
34953+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34954 xen_fill_possible_map();
34955 }
34956
34957diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34958index 33ca6e4..0ded929 100644
34959--- a/arch/x86/xen/xen-asm_32.S
34960+++ b/arch/x86/xen/xen-asm_32.S
34961@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34962 ESP_OFFSET=4 # bytes pushed onto stack
34963
34964 /*
34965- * Store vcpu_info pointer for easy access. Do it this way to
34966- * avoid having to reload %fs
34967+ * Store vcpu_info pointer for easy access.
34968 */
34969 #ifdef CONFIG_SMP
34970- GET_THREAD_INFO(%eax)
34971- movl %ss:TI_cpu(%eax), %eax
34972- movl %ss:__per_cpu_offset(,%eax,4), %eax
34973- mov %ss:xen_vcpu(%eax), %eax
34974+ push %fs
34975+ mov $(__KERNEL_PERCPU), %eax
34976+ mov %eax, %fs
34977+ mov PER_CPU_VAR(xen_vcpu), %eax
34978+ pop %fs
34979 #else
34980 movl %ss:xen_vcpu, %eax
34981 #endif
34982diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34983index 7faed58..ba4427c 100644
34984--- a/arch/x86/xen/xen-head.S
34985+++ b/arch/x86/xen/xen-head.S
34986@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34987 #ifdef CONFIG_X86_32
34988 mov %esi,xen_start_info
34989 mov $init_thread_union+THREAD_SIZE,%esp
34990+#ifdef CONFIG_SMP
34991+ movl $cpu_gdt_table,%edi
34992+ movl $__per_cpu_load,%eax
34993+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34994+ rorl $16,%eax
34995+ movb %al,__KERNEL_PERCPU + 4(%edi)
34996+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34997+ movl $__per_cpu_end - 1,%eax
34998+ subl $__per_cpu_start,%eax
34999+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35000+#endif
35001 #else
35002 mov %rsi,xen_start_info
35003 mov $init_thread_union+THREAD_SIZE,%rsp
35004diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35005index 95f8c61..611d6e8 100644
35006--- a/arch/x86/xen/xen-ops.h
35007+++ b/arch/x86/xen/xen-ops.h
35008@@ -10,8 +10,6 @@
35009 extern const char xen_hypervisor_callback[];
35010 extern const char xen_failsafe_callback[];
35011
35012-extern void *xen_initial_gdt;
35013-
35014 struct trap_info;
35015 void xen_copy_trap_info(struct trap_info *traps);
35016
35017diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35018index 525bd3d..ef888b1 100644
35019--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35020+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35021@@ -119,9 +119,9 @@
35022 ----------------------------------------------------------------------*/
35023
35024 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35025-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35026 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35027 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35028+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35029
35030 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35031 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35032diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35033index 2f33760..835e50a 100644
35034--- a/arch/xtensa/variants/fsf/include/variant/core.h
35035+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35036@@ -11,6 +11,7 @@
35037 #ifndef _XTENSA_CORE_H
35038 #define _XTENSA_CORE_H
35039
35040+#include <linux/const.h>
35041
35042 /****************************************************************************
35043 Parameters Useful for Any Code, USER or PRIVILEGED
35044@@ -112,9 +113,9 @@
35045 ----------------------------------------------------------------------*/
35046
35047 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35048-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35049 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35050 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35051+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35052
35053 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35054 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35055diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35056index af00795..2bb8105 100644
35057--- a/arch/xtensa/variants/s6000/include/variant/core.h
35058+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35059@@ -11,6 +11,7 @@
35060 #ifndef _XTENSA_CORE_CONFIGURATION_H
35061 #define _XTENSA_CORE_CONFIGURATION_H
35062
35063+#include <linux/const.h>
35064
35065 /****************************************************************************
35066 Parameters Useful for Any Code, USER or PRIVILEGED
35067@@ -118,9 +119,9 @@
35068 ----------------------------------------------------------------------*/
35069
35070 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35071-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35072 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35073 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35074+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35075
35076 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35077 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35078diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35079index 4e491d9..c8e18e4 100644
35080--- a/block/blk-cgroup.c
35081+++ b/block/blk-cgroup.c
35082@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35083 static struct cgroup_subsys_state *
35084 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35085 {
35086- static atomic64_t id_seq = ATOMIC64_INIT(0);
35087+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35088 struct blkcg *blkcg;
35089
35090 if (!parent_css) {
35091@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35092
35093 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35094 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35095- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35096+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35097 done:
35098 spin_lock_init(&blkcg->lock);
35099 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35100diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35101index 1855bf5..af12b06 100644
35102--- a/block/blk-iopoll.c
35103+++ b/block/blk-iopoll.c
35104@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35105 }
35106 EXPORT_SYMBOL(blk_iopoll_complete);
35107
35108-static void blk_iopoll_softirq(struct softirq_action *h)
35109+static __latent_entropy void blk_iopoll_softirq(void)
35110 {
35111 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35112 int rearm = 0, budget = blk_iopoll_budget;
35113diff --git a/block/blk-map.c b/block/blk-map.c
35114index 623e1cd..ca1e109 100644
35115--- a/block/blk-map.c
35116+++ b/block/blk-map.c
35117@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35118 if (!len || !kbuf)
35119 return -EINVAL;
35120
35121- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35122+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35123 if (do_copy)
35124 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35125 else
35126diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35127index 57790c1..5e988dd 100644
35128--- a/block/blk-softirq.c
35129+++ b/block/blk-softirq.c
35130@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35131 * Softirq action handler - move entries to local list and loop over them
35132 * while passing them to the queue registered handler.
35133 */
35134-static void blk_done_softirq(struct softirq_action *h)
35135+static __latent_entropy void blk_done_softirq(void)
35136 {
35137 struct list_head *cpu_list, local_list;
35138
35139diff --git a/block/bsg.c b/block/bsg.c
35140index 420a5a9..23834aa 100644
35141--- a/block/bsg.c
35142+++ b/block/bsg.c
35143@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35144 struct sg_io_v4 *hdr, struct bsg_device *bd,
35145 fmode_t has_write_perm)
35146 {
35147+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35148+ unsigned char *cmdptr;
35149+
35150 if (hdr->request_len > BLK_MAX_CDB) {
35151 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35152 if (!rq->cmd)
35153 return -ENOMEM;
35154- }
35155+ cmdptr = rq->cmd;
35156+ } else
35157+ cmdptr = tmpcmd;
35158
35159- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35160+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35161 hdr->request_len))
35162 return -EFAULT;
35163
35164+ if (cmdptr != rq->cmd)
35165+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35166+
35167 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35168 if (blk_verify_command(rq->cmd, has_write_perm))
35169 return -EPERM;
35170diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35171index fbd5a67..f24fd95 100644
35172--- a/block/compat_ioctl.c
35173+++ b/block/compat_ioctl.c
35174@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35175 cgc = compat_alloc_user_space(sizeof(*cgc));
35176 cgc32 = compat_ptr(arg);
35177
35178- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35179+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35180 get_user(data, &cgc32->buffer) ||
35181 put_user(compat_ptr(data), &cgc->buffer) ||
35182 copy_in_user(&cgc->buflen, &cgc32->buflen,
35183@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35184 err |= __get_user(f->spec1, &uf->spec1);
35185 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35186 err |= __get_user(name, &uf->name);
35187- f->name = compat_ptr(name);
35188+ f->name = (void __force_kernel *)compat_ptr(name);
35189 if (err) {
35190 err = -EFAULT;
35191 goto out;
35192diff --git a/block/genhd.c b/block/genhd.c
35193index 791f419..89f21c4 100644
35194--- a/block/genhd.c
35195+++ b/block/genhd.c
35196@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35197
35198 /*
35199 * Register device numbers dev..(dev+range-1)
35200- * range must be nonzero
35201+ * Noop if @range is zero.
35202 * The hash chain is sorted on range, so that subranges can override.
35203 */
35204 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35205 struct kobject *(*probe)(dev_t, int *, void *),
35206 int (*lock)(dev_t, void *), void *data)
35207 {
35208- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35209+ if (range)
35210+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35211 }
35212
35213 EXPORT_SYMBOL(blk_register_region);
35214
35215+/* undo blk_register_region(), noop if @range is zero */
35216 void blk_unregister_region(dev_t devt, unsigned long range)
35217 {
35218- kobj_unmap(bdev_map, devt, range);
35219+ if (range)
35220+ kobj_unmap(bdev_map, devt, range);
35221 }
35222
35223 EXPORT_SYMBOL(blk_unregister_region);
35224diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35225index dc51f46..d5446a8 100644
35226--- a/block/partitions/efi.c
35227+++ b/block/partitions/efi.c
35228@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35229 if (!gpt)
35230 return NULL;
35231
35232+ if (!le32_to_cpu(gpt->num_partition_entries))
35233+ return NULL;
35234+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35235+ if (!pte)
35236+ return NULL;
35237+
35238 count = le32_to_cpu(gpt->num_partition_entries) *
35239 le32_to_cpu(gpt->sizeof_partition_entry);
35240- if (!count)
35241- return NULL;
35242- pte = kmalloc(count, GFP_KERNEL);
35243- if (!pte)
35244- return NULL;
35245-
35246 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35247 (u8 *) pte, count) < count) {
35248 kfree(pte);
35249diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35250index 625e3e4..b5339f9 100644
35251--- a/block/scsi_ioctl.c
35252+++ b/block/scsi_ioctl.c
35253@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35254 return put_user(0, p);
35255 }
35256
35257-static int sg_get_timeout(struct request_queue *q)
35258+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35259 {
35260 return jiffies_to_clock_t(q->sg_timeout);
35261 }
35262@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35263 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35264 struct sg_io_hdr *hdr, fmode_t mode)
35265 {
35266- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35267+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35268+ unsigned char *cmdptr;
35269+
35270+ if (rq->cmd != rq->__cmd)
35271+ cmdptr = rq->cmd;
35272+ else
35273+ cmdptr = tmpcmd;
35274+
35275+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35276 return -EFAULT;
35277+
35278+ if (cmdptr != rq->cmd)
35279+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35280+
35281 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35282 return -EPERM;
35283
35284@@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35285 int err;
35286 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35287 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35288+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35289+ unsigned char *cmdptr;
35290
35291 if (!sic)
35292 return -EINVAL;
35293@@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35294 */
35295 err = -EFAULT;
35296 rq->cmd_len = cmdlen;
35297- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35298+
35299+ if (rq->cmd != rq->__cmd)
35300+ cmdptr = rq->cmd;
35301+ else
35302+ cmdptr = tmpcmd;
35303+
35304+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35305 goto error;
35306
35307+ if (rq->cmd != cmdptr)
35308+ memcpy(rq->cmd, cmdptr, cmdlen);
35309+
35310 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35311 goto error;
35312
35313diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35314index 7bdd61b..afec999 100644
35315--- a/crypto/cryptd.c
35316+++ b/crypto/cryptd.c
35317@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35318
35319 struct cryptd_blkcipher_request_ctx {
35320 crypto_completion_t complete;
35321-};
35322+} __no_const;
35323
35324 struct cryptd_hash_ctx {
35325 struct crypto_shash *child;
35326@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35327
35328 struct cryptd_aead_request_ctx {
35329 crypto_completion_t complete;
35330-};
35331+} __no_const;
35332
35333 static void cryptd_queue_worker(struct work_struct *work);
35334
35335diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35336index f8c920c..ab2cb5a 100644
35337--- a/crypto/pcrypt.c
35338+++ b/crypto/pcrypt.c
35339@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35340 int ret;
35341
35342 pinst->kobj.kset = pcrypt_kset;
35343- ret = kobject_add(&pinst->kobj, NULL, name);
35344+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35345 if (!ret)
35346 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35347
35348diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35349index 15dddc1..b61cf0c 100644
35350--- a/drivers/acpi/acpica/hwxfsleep.c
35351+++ b/drivers/acpi/acpica/hwxfsleep.c
35352@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35353 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35354
35355 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35356- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35357- acpi_hw_extended_sleep},
35358- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35359- acpi_hw_extended_wake_prep},
35360- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35361+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35362+ .extended_function = acpi_hw_extended_sleep},
35363+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35364+ .extended_function = acpi_hw_extended_wake_prep},
35365+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35366+ .extended_function = acpi_hw_extended_wake}
35367 };
35368
35369 /*
35370diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35371index 21ba34a..cb05966 100644
35372--- a/drivers/acpi/apei/apei-internal.h
35373+++ b/drivers/acpi/apei/apei-internal.h
35374@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35375 struct apei_exec_ins_type {
35376 u32 flags;
35377 apei_exec_ins_func_t run;
35378-};
35379+} __do_const;
35380
35381 struct apei_exec_context {
35382 u32 ip;
35383diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35384index a30bc31..b91c4d5 100644
35385--- a/drivers/acpi/apei/ghes.c
35386+++ b/drivers/acpi/apei/ghes.c
35387@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35388 const struct acpi_hest_generic *generic,
35389 const struct acpi_generic_status *estatus)
35390 {
35391- static atomic_t seqno;
35392+ static atomic_unchecked_t seqno;
35393 unsigned int curr_seqno;
35394 char pfx_seq[64];
35395
35396@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35397 else
35398 pfx = KERN_ERR;
35399 }
35400- curr_seqno = atomic_inc_return(&seqno);
35401+ curr_seqno = atomic_inc_return_unchecked(&seqno);
35402 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35403 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35404 pfx_seq, generic->header.source_id);
35405diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35406index a83e3c6..c3d617f 100644
35407--- a/drivers/acpi/bgrt.c
35408+++ b/drivers/acpi/bgrt.c
35409@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35410 if (!bgrt_image)
35411 return -ENODEV;
35412
35413- bin_attr_image.private = bgrt_image;
35414- bin_attr_image.size = bgrt_image_size;
35415+ pax_open_kernel();
35416+ *(void **)&bin_attr_image.private = bgrt_image;
35417+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
35418+ pax_close_kernel();
35419
35420 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35421 if (!bgrt_kobj)
35422diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35423index 078c4f7..410e272 100644
35424--- a/drivers/acpi/blacklist.c
35425+++ b/drivers/acpi/blacklist.c
35426@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35427 u32 is_critical_error;
35428 };
35429
35430-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35431+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35432
35433 /*
35434 * POLICY: If *anything* doesn't work, put it on the blacklist.
35435@@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35436 return 0;
35437 }
35438
35439-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35440+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35441 {
35442 .callback = dmi_disable_osi_vista,
35443 .ident = "Fujitsu Siemens",
35444diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
35445index 12b62f2..dc2aac8 100644
35446--- a/drivers/acpi/custom_method.c
35447+++ b/drivers/acpi/custom_method.c
35448@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
35449 struct acpi_table_header table;
35450 acpi_status status;
35451
35452+#ifdef CONFIG_GRKERNSEC_KMEM
35453+ return -EPERM;
35454+#endif
35455+
35456 if (!(*ppos)) {
35457 /* parse the table header to get the table length */
35458 if (count <= sizeof(struct acpi_table_header))
35459diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35460index 644516d..643937e 100644
35461--- a/drivers/acpi/processor_idle.c
35462+++ b/drivers/acpi/processor_idle.c
35463@@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35464 {
35465 int i, count = CPUIDLE_DRIVER_STATE_START;
35466 struct acpi_processor_cx *cx;
35467- struct cpuidle_state *state;
35468+ cpuidle_state_no_const *state;
35469 struct cpuidle_driver *drv = &acpi_idle_driver;
35470
35471 if (!pr->flags.power_setup_done)
35472diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35473index 6dbc3ca..b8b59a0 100644
35474--- a/drivers/acpi/sysfs.c
35475+++ b/drivers/acpi/sysfs.c
35476@@ -425,11 +425,11 @@ static u32 num_counters;
35477 static struct attribute **all_attrs;
35478 static u32 acpi_gpe_count;
35479
35480-static struct attribute_group interrupt_stats_attr_group = {
35481+static attribute_group_no_const interrupt_stats_attr_group = {
35482 .name = "interrupts",
35483 };
35484
35485-static struct kobj_attribute *counter_attrs;
35486+static kobj_attribute_no_const *counter_attrs;
35487
35488 static void delete_gpe_attr_array(void)
35489 {
35490diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35491index c482f8c..c832240 100644
35492--- a/drivers/ata/libahci.c
35493+++ b/drivers/ata/libahci.c
35494@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
35495 }
35496 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35497
35498-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35499+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35500 struct ata_taskfile *tf, int is_cmd, u16 flags,
35501 unsigned long timeout_msec)
35502 {
35503diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35504index 1393a58..3bf8cbe 100644
35505--- a/drivers/ata/libata-core.c
35506+++ b/drivers/ata/libata-core.c
35507@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35508 static void ata_dev_xfermask(struct ata_device *dev);
35509 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35510
35511-atomic_t ata_print_id = ATOMIC_INIT(0);
35512+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35513
35514 struct ata_force_param {
35515 const char *name;
35516@@ -4823,7 +4823,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35517 struct ata_port *ap;
35518 unsigned int tag;
35519
35520- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35521+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35522 ap = qc->ap;
35523
35524 qc->flags = 0;
35525@@ -4839,7 +4839,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35526 struct ata_port *ap;
35527 struct ata_link *link;
35528
35529- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35530+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35531 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35532 ap = qc->ap;
35533 link = qc->dev->link;
35534@@ -5958,6 +5958,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35535 return;
35536
35537 spin_lock(&lock);
35538+ pax_open_kernel();
35539
35540 for (cur = ops->inherits; cur; cur = cur->inherits) {
35541 void **inherit = (void **)cur;
35542@@ -5971,8 +5972,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35543 if (IS_ERR(*pp))
35544 *pp = NULL;
35545
35546- ops->inherits = NULL;
35547+ *(struct ata_port_operations **)&ops->inherits = NULL;
35548
35549+ pax_close_kernel();
35550 spin_unlock(&lock);
35551 }
35552
35553@@ -6165,7 +6167,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35554
35555 /* give ports names and add SCSI hosts */
35556 for (i = 0; i < host->n_ports; i++) {
35557- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35558+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35559 host->ports[i]->local_port_no = i + 1;
35560 }
35561
35562diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35563index 377eb88..8591b44 100644
35564--- a/drivers/ata/libata-scsi.c
35565+++ b/drivers/ata/libata-scsi.c
35566@@ -4135,7 +4135,7 @@ int ata_sas_port_init(struct ata_port *ap)
35567
35568 if (rc)
35569 return rc;
35570- ap->print_id = atomic_inc_return(&ata_print_id);
35571+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35572 return 0;
35573 }
35574 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35575diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35576index 45b5ab3..98446b8 100644
35577--- a/drivers/ata/libata.h
35578+++ b/drivers/ata/libata.h
35579@@ -53,7 +53,7 @@ enum {
35580 ATA_DNXFER_QUIET = (1 << 31),
35581 };
35582
35583-extern atomic_t ata_print_id;
35584+extern atomic_unchecked_t ata_print_id;
35585 extern int atapi_passthru16;
35586 extern int libata_fua;
35587 extern int libata_noacpi;
35588diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35589index 73492dd..ca2bff5 100644
35590--- a/drivers/ata/pata_arasan_cf.c
35591+++ b/drivers/ata/pata_arasan_cf.c
35592@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35593 /* Handle platform specific quirks */
35594 if (quirk) {
35595 if (quirk & CF_BROKEN_PIO) {
35596- ap->ops->set_piomode = NULL;
35597+ pax_open_kernel();
35598+ *(void **)&ap->ops->set_piomode = NULL;
35599+ pax_close_kernel();
35600 ap->pio_mask = 0;
35601 }
35602 if (quirk & CF_BROKEN_MWDMA)
35603diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35604index f9b983a..887b9d8 100644
35605--- a/drivers/atm/adummy.c
35606+++ b/drivers/atm/adummy.c
35607@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35608 vcc->pop(vcc, skb);
35609 else
35610 dev_kfree_skb_any(skb);
35611- atomic_inc(&vcc->stats->tx);
35612+ atomic_inc_unchecked(&vcc->stats->tx);
35613
35614 return 0;
35615 }
35616diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35617index 62a7607..cc4be104 100644
35618--- a/drivers/atm/ambassador.c
35619+++ b/drivers/atm/ambassador.c
35620@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35621 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35622
35623 // VC layer stats
35624- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35625+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35626
35627 // free the descriptor
35628 kfree (tx_descr);
35629@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35630 dump_skb ("<<<", vc, skb);
35631
35632 // VC layer stats
35633- atomic_inc(&atm_vcc->stats->rx);
35634+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35635 __net_timestamp(skb);
35636 // end of our responsibility
35637 atm_vcc->push (atm_vcc, skb);
35638@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35639 } else {
35640 PRINTK (KERN_INFO, "dropped over-size frame");
35641 // should we count this?
35642- atomic_inc(&atm_vcc->stats->rx_drop);
35643+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35644 }
35645
35646 } else {
35647@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35648 }
35649
35650 if (check_area (skb->data, skb->len)) {
35651- atomic_inc(&atm_vcc->stats->tx_err);
35652+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35653 return -ENOMEM; // ?
35654 }
35655
35656diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35657index 0e3f8f9..765a7a5 100644
35658--- a/drivers/atm/atmtcp.c
35659+++ b/drivers/atm/atmtcp.c
35660@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35661 if (vcc->pop) vcc->pop(vcc,skb);
35662 else dev_kfree_skb(skb);
35663 if (dev_data) return 0;
35664- atomic_inc(&vcc->stats->tx_err);
35665+ atomic_inc_unchecked(&vcc->stats->tx_err);
35666 return -ENOLINK;
35667 }
35668 size = skb->len+sizeof(struct atmtcp_hdr);
35669@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35670 if (!new_skb) {
35671 if (vcc->pop) vcc->pop(vcc,skb);
35672 else dev_kfree_skb(skb);
35673- atomic_inc(&vcc->stats->tx_err);
35674+ atomic_inc_unchecked(&vcc->stats->tx_err);
35675 return -ENOBUFS;
35676 }
35677 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35678@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35679 if (vcc->pop) vcc->pop(vcc,skb);
35680 else dev_kfree_skb(skb);
35681 out_vcc->push(out_vcc,new_skb);
35682- atomic_inc(&vcc->stats->tx);
35683- atomic_inc(&out_vcc->stats->rx);
35684+ atomic_inc_unchecked(&vcc->stats->tx);
35685+ atomic_inc_unchecked(&out_vcc->stats->rx);
35686 return 0;
35687 }
35688
35689@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35690 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35691 read_unlock(&vcc_sklist_lock);
35692 if (!out_vcc) {
35693- atomic_inc(&vcc->stats->tx_err);
35694+ atomic_inc_unchecked(&vcc->stats->tx_err);
35695 goto done;
35696 }
35697 skb_pull(skb,sizeof(struct atmtcp_hdr));
35698@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35699 __net_timestamp(new_skb);
35700 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35701 out_vcc->push(out_vcc,new_skb);
35702- atomic_inc(&vcc->stats->tx);
35703- atomic_inc(&out_vcc->stats->rx);
35704+ atomic_inc_unchecked(&vcc->stats->tx);
35705+ atomic_inc_unchecked(&out_vcc->stats->rx);
35706 done:
35707 if (vcc->pop) vcc->pop(vcc,skb);
35708 else dev_kfree_skb(skb);
35709diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35710index b1955ba..b179940 100644
35711--- a/drivers/atm/eni.c
35712+++ b/drivers/atm/eni.c
35713@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35714 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35715 vcc->dev->number);
35716 length = 0;
35717- atomic_inc(&vcc->stats->rx_err);
35718+ atomic_inc_unchecked(&vcc->stats->rx_err);
35719 }
35720 else {
35721 length = ATM_CELL_SIZE-1; /* no HEC */
35722@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35723 size);
35724 }
35725 eff = length = 0;
35726- atomic_inc(&vcc->stats->rx_err);
35727+ atomic_inc_unchecked(&vcc->stats->rx_err);
35728 }
35729 else {
35730 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35731@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35732 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35733 vcc->dev->number,vcc->vci,length,size << 2,descr);
35734 length = eff = 0;
35735- atomic_inc(&vcc->stats->rx_err);
35736+ atomic_inc_unchecked(&vcc->stats->rx_err);
35737 }
35738 }
35739 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35740@@ -767,7 +767,7 @@ rx_dequeued++;
35741 vcc->push(vcc,skb);
35742 pushed++;
35743 }
35744- atomic_inc(&vcc->stats->rx);
35745+ atomic_inc_unchecked(&vcc->stats->rx);
35746 }
35747 wake_up(&eni_dev->rx_wait);
35748 }
35749@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35750 PCI_DMA_TODEVICE);
35751 if (vcc->pop) vcc->pop(vcc,skb);
35752 else dev_kfree_skb_irq(skb);
35753- atomic_inc(&vcc->stats->tx);
35754+ atomic_inc_unchecked(&vcc->stats->tx);
35755 wake_up(&eni_dev->tx_wait);
35756 dma_complete++;
35757 }
35758diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35759index b41c948..a002b17 100644
35760--- a/drivers/atm/firestream.c
35761+++ b/drivers/atm/firestream.c
35762@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35763 }
35764 }
35765
35766- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35767+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35768
35769 fs_dprintk (FS_DEBUG_TXMEM, "i");
35770 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35771@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35772 #endif
35773 skb_put (skb, qe->p1 & 0xffff);
35774 ATM_SKB(skb)->vcc = atm_vcc;
35775- atomic_inc(&atm_vcc->stats->rx);
35776+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35777 __net_timestamp(skb);
35778 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35779 atm_vcc->push (atm_vcc, skb);
35780@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35781 kfree (pe);
35782 }
35783 if (atm_vcc)
35784- atomic_inc(&atm_vcc->stats->rx_drop);
35785+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35786 break;
35787 case 0x1f: /* Reassembly abort: no buffers. */
35788 /* Silently increment error counter. */
35789 if (atm_vcc)
35790- atomic_inc(&atm_vcc->stats->rx_drop);
35791+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35792 break;
35793 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35794 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35795diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35796index 204814e..cede831 100644
35797--- a/drivers/atm/fore200e.c
35798+++ b/drivers/atm/fore200e.c
35799@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35800 #endif
35801 /* check error condition */
35802 if (*entry->status & STATUS_ERROR)
35803- atomic_inc(&vcc->stats->tx_err);
35804+ atomic_inc_unchecked(&vcc->stats->tx_err);
35805 else
35806- atomic_inc(&vcc->stats->tx);
35807+ atomic_inc_unchecked(&vcc->stats->tx);
35808 }
35809 }
35810
35811@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35812 if (skb == NULL) {
35813 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35814
35815- atomic_inc(&vcc->stats->rx_drop);
35816+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35817 return -ENOMEM;
35818 }
35819
35820@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35821
35822 dev_kfree_skb_any(skb);
35823
35824- atomic_inc(&vcc->stats->rx_drop);
35825+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35826 return -ENOMEM;
35827 }
35828
35829 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35830
35831 vcc->push(vcc, skb);
35832- atomic_inc(&vcc->stats->rx);
35833+ atomic_inc_unchecked(&vcc->stats->rx);
35834
35835 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35836
35837@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35838 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35839 fore200e->atm_dev->number,
35840 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35841- atomic_inc(&vcc->stats->rx_err);
35842+ atomic_inc_unchecked(&vcc->stats->rx_err);
35843 }
35844 }
35845
35846@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35847 goto retry_here;
35848 }
35849
35850- atomic_inc(&vcc->stats->tx_err);
35851+ atomic_inc_unchecked(&vcc->stats->tx_err);
35852
35853 fore200e->tx_sat++;
35854 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35855diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35856index 8557adc..3fb5d55 100644
35857--- a/drivers/atm/he.c
35858+++ b/drivers/atm/he.c
35859@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35860
35861 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35862 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35863- atomic_inc(&vcc->stats->rx_drop);
35864+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35865 goto return_host_buffers;
35866 }
35867
35868@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35869 RBRQ_LEN_ERR(he_dev->rbrq_head)
35870 ? "LEN_ERR" : "",
35871 vcc->vpi, vcc->vci);
35872- atomic_inc(&vcc->stats->rx_err);
35873+ atomic_inc_unchecked(&vcc->stats->rx_err);
35874 goto return_host_buffers;
35875 }
35876
35877@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35878 vcc->push(vcc, skb);
35879 spin_lock(&he_dev->global_lock);
35880
35881- atomic_inc(&vcc->stats->rx);
35882+ atomic_inc_unchecked(&vcc->stats->rx);
35883
35884 return_host_buffers:
35885 ++pdus_assembled;
35886@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35887 tpd->vcc->pop(tpd->vcc, tpd->skb);
35888 else
35889 dev_kfree_skb_any(tpd->skb);
35890- atomic_inc(&tpd->vcc->stats->tx_err);
35891+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35892 }
35893 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35894 return;
35895@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35896 vcc->pop(vcc, skb);
35897 else
35898 dev_kfree_skb_any(skb);
35899- atomic_inc(&vcc->stats->tx_err);
35900+ atomic_inc_unchecked(&vcc->stats->tx_err);
35901 return -EINVAL;
35902 }
35903
35904@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35905 vcc->pop(vcc, skb);
35906 else
35907 dev_kfree_skb_any(skb);
35908- atomic_inc(&vcc->stats->tx_err);
35909+ atomic_inc_unchecked(&vcc->stats->tx_err);
35910 return -EINVAL;
35911 }
35912 #endif
35913@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35914 vcc->pop(vcc, skb);
35915 else
35916 dev_kfree_skb_any(skb);
35917- atomic_inc(&vcc->stats->tx_err);
35918+ atomic_inc_unchecked(&vcc->stats->tx_err);
35919 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35920 return -ENOMEM;
35921 }
35922@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35923 vcc->pop(vcc, skb);
35924 else
35925 dev_kfree_skb_any(skb);
35926- atomic_inc(&vcc->stats->tx_err);
35927+ atomic_inc_unchecked(&vcc->stats->tx_err);
35928 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35929 return -ENOMEM;
35930 }
35931@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35932 __enqueue_tpd(he_dev, tpd, cid);
35933 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35934
35935- atomic_inc(&vcc->stats->tx);
35936+ atomic_inc_unchecked(&vcc->stats->tx);
35937
35938 return 0;
35939 }
35940diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35941index 1dc0519..1aadaf7 100644
35942--- a/drivers/atm/horizon.c
35943+++ b/drivers/atm/horizon.c
35944@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35945 {
35946 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35947 // VC layer stats
35948- atomic_inc(&vcc->stats->rx);
35949+ atomic_inc_unchecked(&vcc->stats->rx);
35950 __net_timestamp(skb);
35951 // end of our responsibility
35952 vcc->push (vcc, skb);
35953@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35954 dev->tx_iovec = NULL;
35955
35956 // VC layer stats
35957- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35958+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35959
35960 // free the skb
35961 hrz_kfree_skb (skb);
35962diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35963index 1bdf104..9dc44b1 100644
35964--- a/drivers/atm/idt77252.c
35965+++ b/drivers/atm/idt77252.c
35966@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35967 else
35968 dev_kfree_skb(skb);
35969
35970- atomic_inc(&vcc->stats->tx);
35971+ atomic_inc_unchecked(&vcc->stats->tx);
35972 }
35973
35974 atomic_dec(&scq->used);
35975@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35976 if ((sb = dev_alloc_skb(64)) == NULL) {
35977 printk("%s: Can't allocate buffers for aal0.\n",
35978 card->name);
35979- atomic_add(i, &vcc->stats->rx_drop);
35980+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35981 break;
35982 }
35983 if (!atm_charge(vcc, sb->truesize)) {
35984 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35985 card->name);
35986- atomic_add(i - 1, &vcc->stats->rx_drop);
35987+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35988 dev_kfree_skb(sb);
35989 break;
35990 }
35991@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35992 ATM_SKB(sb)->vcc = vcc;
35993 __net_timestamp(sb);
35994 vcc->push(vcc, sb);
35995- atomic_inc(&vcc->stats->rx);
35996+ atomic_inc_unchecked(&vcc->stats->rx);
35997
35998 cell += ATM_CELL_PAYLOAD;
35999 }
36000@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36001 "(CDC: %08x)\n",
36002 card->name, len, rpp->len, readl(SAR_REG_CDC));
36003 recycle_rx_pool_skb(card, rpp);
36004- atomic_inc(&vcc->stats->rx_err);
36005+ atomic_inc_unchecked(&vcc->stats->rx_err);
36006 return;
36007 }
36008 if (stat & SAR_RSQE_CRC) {
36009 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36010 recycle_rx_pool_skb(card, rpp);
36011- atomic_inc(&vcc->stats->rx_err);
36012+ atomic_inc_unchecked(&vcc->stats->rx_err);
36013 return;
36014 }
36015 if (skb_queue_len(&rpp->queue) > 1) {
36016@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36017 RXPRINTK("%s: Can't alloc RX skb.\n",
36018 card->name);
36019 recycle_rx_pool_skb(card, rpp);
36020- atomic_inc(&vcc->stats->rx_err);
36021+ atomic_inc_unchecked(&vcc->stats->rx_err);
36022 return;
36023 }
36024 if (!atm_charge(vcc, skb->truesize)) {
36025@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36026 __net_timestamp(skb);
36027
36028 vcc->push(vcc, skb);
36029- atomic_inc(&vcc->stats->rx);
36030+ atomic_inc_unchecked(&vcc->stats->rx);
36031
36032 return;
36033 }
36034@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36035 __net_timestamp(skb);
36036
36037 vcc->push(vcc, skb);
36038- atomic_inc(&vcc->stats->rx);
36039+ atomic_inc_unchecked(&vcc->stats->rx);
36040
36041 if (skb->truesize > SAR_FB_SIZE_3)
36042 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36043@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36044 if (vcc->qos.aal != ATM_AAL0) {
36045 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36046 card->name, vpi, vci);
36047- atomic_inc(&vcc->stats->rx_drop);
36048+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36049 goto drop;
36050 }
36051
36052 if ((sb = dev_alloc_skb(64)) == NULL) {
36053 printk("%s: Can't allocate buffers for AAL0.\n",
36054 card->name);
36055- atomic_inc(&vcc->stats->rx_err);
36056+ atomic_inc_unchecked(&vcc->stats->rx_err);
36057 goto drop;
36058 }
36059
36060@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36061 ATM_SKB(sb)->vcc = vcc;
36062 __net_timestamp(sb);
36063 vcc->push(vcc, sb);
36064- atomic_inc(&vcc->stats->rx);
36065+ atomic_inc_unchecked(&vcc->stats->rx);
36066
36067 drop:
36068 skb_pull(queue, 64);
36069@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36070
36071 if (vc == NULL) {
36072 printk("%s: NULL connection in send().\n", card->name);
36073- atomic_inc(&vcc->stats->tx_err);
36074+ atomic_inc_unchecked(&vcc->stats->tx_err);
36075 dev_kfree_skb(skb);
36076 return -EINVAL;
36077 }
36078 if (!test_bit(VCF_TX, &vc->flags)) {
36079 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36080- atomic_inc(&vcc->stats->tx_err);
36081+ atomic_inc_unchecked(&vcc->stats->tx_err);
36082 dev_kfree_skb(skb);
36083 return -EINVAL;
36084 }
36085@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36086 break;
36087 default:
36088 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36089- atomic_inc(&vcc->stats->tx_err);
36090+ atomic_inc_unchecked(&vcc->stats->tx_err);
36091 dev_kfree_skb(skb);
36092 return -EINVAL;
36093 }
36094
36095 if (skb_shinfo(skb)->nr_frags != 0) {
36096 printk("%s: No scatter-gather yet.\n", card->name);
36097- atomic_inc(&vcc->stats->tx_err);
36098+ atomic_inc_unchecked(&vcc->stats->tx_err);
36099 dev_kfree_skb(skb);
36100 return -EINVAL;
36101 }
36102@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36103
36104 err = queue_skb(card, vc, skb, oam);
36105 if (err) {
36106- atomic_inc(&vcc->stats->tx_err);
36107+ atomic_inc_unchecked(&vcc->stats->tx_err);
36108 dev_kfree_skb(skb);
36109 return err;
36110 }
36111@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36112 skb = dev_alloc_skb(64);
36113 if (!skb) {
36114 printk("%s: Out of memory in send_oam().\n", card->name);
36115- atomic_inc(&vcc->stats->tx_err);
36116+ atomic_inc_unchecked(&vcc->stats->tx_err);
36117 return -ENOMEM;
36118 }
36119 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36120diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36121index 4217f29..88f547a 100644
36122--- a/drivers/atm/iphase.c
36123+++ b/drivers/atm/iphase.c
36124@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36125 status = (u_short) (buf_desc_ptr->desc_mode);
36126 if (status & (RX_CER | RX_PTE | RX_OFL))
36127 {
36128- atomic_inc(&vcc->stats->rx_err);
36129+ atomic_inc_unchecked(&vcc->stats->rx_err);
36130 IF_ERR(printk("IA: bad packet, dropping it");)
36131 if (status & RX_CER) {
36132 IF_ERR(printk(" cause: packet CRC error\n");)
36133@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36134 len = dma_addr - buf_addr;
36135 if (len > iadev->rx_buf_sz) {
36136 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36137- atomic_inc(&vcc->stats->rx_err);
36138+ atomic_inc_unchecked(&vcc->stats->rx_err);
36139 goto out_free_desc;
36140 }
36141
36142@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36143 ia_vcc = INPH_IA_VCC(vcc);
36144 if (ia_vcc == NULL)
36145 {
36146- atomic_inc(&vcc->stats->rx_err);
36147+ atomic_inc_unchecked(&vcc->stats->rx_err);
36148 atm_return(vcc, skb->truesize);
36149 dev_kfree_skb_any(skb);
36150 goto INCR_DLE;
36151@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36152 if ((length > iadev->rx_buf_sz) || (length >
36153 (skb->len - sizeof(struct cpcs_trailer))))
36154 {
36155- atomic_inc(&vcc->stats->rx_err);
36156+ atomic_inc_unchecked(&vcc->stats->rx_err);
36157 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36158 length, skb->len);)
36159 atm_return(vcc, skb->truesize);
36160@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36161
36162 IF_RX(printk("rx_dle_intr: skb push");)
36163 vcc->push(vcc,skb);
36164- atomic_inc(&vcc->stats->rx);
36165+ atomic_inc_unchecked(&vcc->stats->rx);
36166 iadev->rx_pkt_cnt++;
36167 }
36168 INCR_DLE:
36169@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36170 {
36171 struct k_sonet_stats *stats;
36172 stats = &PRIV(_ia_dev[board])->sonet_stats;
36173- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36174- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36175- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36176- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36177- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36178- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36179- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36180- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36181- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36182+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36183+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36184+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36185+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36186+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36187+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36188+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36189+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36190+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36191 }
36192 ia_cmds.status = 0;
36193 break;
36194@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36195 if ((desc == 0) || (desc > iadev->num_tx_desc))
36196 {
36197 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36198- atomic_inc(&vcc->stats->tx);
36199+ atomic_inc_unchecked(&vcc->stats->tx);
36200 if (vcc->pop)
36201 vcc->pop(vcc, skb);
36202 else
36203@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36204 ATM_DESC(skb) = vcc->vci;
36205 skb_queue_tail(&iadev->tx_dma_q, skb);
36206
36207- atomic_inc(&vcc->stats->tx);
36208+ atomic_inc_unchecked(&vcc->stats->tx);
36209 iadev->tx_pkt_cnt++;
36210 /* Increment transaction counter */
36211 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36212
36213 #if 0
36214 /* add flow control logic */
36215- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36216+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36217 if (iavcc->vc_desc_cnt > 10) {
36218 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36219 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36220diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36221index fa7d701..1e404c7 100644
36222--- a/drivers/atm/lanai.c
36223+++ b/drivers/atm/lanai.c
36224@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36225 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36226 lanai_endtx(lanai, lvcc);
36227 lanai_free_skb(lvcc->tx.atmvcc, skb);
36228- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36229+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36230 }
36231
36232 /* Try to fill the buffer - don't call unless there is backlog */
36233@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36234 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36235 __net_timestamp(skb);
36236 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36237- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36238+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36239 out:
36240 lvcc->rx.buf.ptr = end;
36241 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36242@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36243 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36244 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36245 lanai->stats.service_rxnotaal5++;
36246- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36247+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36248 return 0;
36249 }
36250 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36251@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36252 int bytes;
36253 read_unlock(&vcc_sklist_lock);
36254 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36255- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36256+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36257 lvcc->stats.x.aal5.service_trash++;
36258 bytes = (SERVICE_GET_END(s) * 16) -
36259 (((unsigned long) lvcc->rx.buf.ptr) -
36260@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36261 }
36262 if (s & SERVICE_STREAM) {
36263 read_unlock(&vcc_sklist_lock);
36264- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36265+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36266 lvcc->stats.x.aal5.service_stream++;
36267 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36268 "PDU on VCI %d!\n", lanai->number, vci);
36269@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36270 return 0;
36271 }
36272 DPRINTK("got rx crc error on vci %d\n", vci);
36273- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36274+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36275 lvcc->stats.x.aal5.service_rxcrc++;
36276 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36277 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36278diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36279index 5aca5f4..ce3a6b0 100644
36280--- a/drivers/atm/nicstar.c
36281+++ b/drivers/atm/nicstar.c
36282@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36283 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36284 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36285 card->index);
36286- atomic_inc(&vcc->stats->tx_err);
36287+ atomic_inc_unchecked(&vcc->stats->tx_err);
36288 dev_kfree_skb_any(skb);
36289 return -EINVAL;
36290 }
36291@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36292 if (!vc->tx) {
36293 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36294 card->index);
36295- atomic_inc(&vcc->stats->tx_err);
36296+ atomic_inc_unchecked(&vcc->stats->tx_err);
36297 dev_kfree_skb_any(skb);
36298 return -EINVAL;
36299 }
36300@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36301 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36302 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36303 card->index);
36304- atomic_inc(&vcc->stats->tx_err);
36305+ atomic_inc_unchecked(&vcc->stats->tx_err);
36306 dev_kfree_skb_any(skb);
36307 return -EINVAL;
36308 }
36309
36310 if (skb_shinfo(skb)->nr_frags != 0) {
36311 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36312- atomic_inc(&vcc->stats->tx_err);
36313+ atomic_inc_unchecked(&vcc->stats->tx_err);
36314 dev_kfree_skb_any(skb);
36315 return -EINVAL;
36316 }
36317@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36318 }
36319
36320 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36321- atomic_inc(&vcc->stats->tx_err);
36322+ atomic_inc_unchecked(&vcc->stats->tx_err);
36323 dev_kfree_skb_any(skb);
36324 return -EIO;
36325 }
36326- atomic_inc(&vcc->stats->tx);
36327+ atomic_inc_unchecked(&vcc->stats->tx);
36328
36329 return 0;
36330 }
36331@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36332 printk
36333 ("nicstar%d: Can't allocate buffers for aal0.\n",
36334 card->index);
36335- atomic_add(i, &vcc->stats->rx_drop);
36336+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36337 break;
36338 }
36339 if (!atm_charge(vcc, sb->truesize)) {
36340 RXPRINTK
36341 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36342 card->index);
36343- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36344+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36345 dev_kfree_skb_any(sb);
36346 break;
36347 }
36348@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36349 ATM_SKB(sb)->vcc = vcc;
36350 __net_timestamp(sb);
36351 vcc->push(vcc, sb);
36352- atomic_inc(&vcc->stats->rx);
36353+ atomic_inc_unchecked(&vcc->stats->rx);
36354 cell += ATM_CELL_PAYLOAD;
36355 }
36356
36357@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36358 if (iovb == NULL) {
36359 printk("nicstar%d: Out of iovec buffers.\n",
36360 card->index);
36361- atomic_inc(&vcc->stats->rx_drop);
36362+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36363 recycle_rx_buf(card, skb);
36364 return;
36365 }
36366@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36367 small or large buffer itself. */
36368 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36369 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36370- atomic_inc(&vcc->stats->rx_err);
36371+ atomic_inc_unchecked(&vcc->stats->rx_err);
36372 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36373 NS_MAX_IOVECS);
36374 NS_PRV_IOVCNT(iovb) = 0;
36375@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36376 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36377 card->index);
36378 which_list(card, skb);
36379- atomic_inc(&vcc->stats->rx_err);
36380+ atomic_inc_unchecked(&vcc->stats->rx_err);
36381 recycle_rx_buf(card, skb);
36382 vc->rx_iov = NULL;
36383 recycle_iov_buf(card, iovb);
36384@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36385 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36386 card->index);
36387 which_list(card, skb);
36388- atomic_inc(&vcc->stats->rx_err);
36389+ atomic_inc_unchecked(&vcc->stats->rx_err);
36390 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36391 NS_PRV_IOVCNT(iovb));
36392 vc->rx_iov = NULL;
36393@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36394 printk(" - PDU size mismatch.\n");
36395 else
36396 printk(".\n");
36397- atomic_inc(&vcc->stats->rx_err);
36398+ atomic_inc_unchecked(&vcc->stats->rx_err);
36399 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36400 NS_PRV_IOVCNT(iovb));
36401 vc->rx_iov = NULL;
36402@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36403 /* skb points to a small buffer */
36404 if (!atm_charge(vcc, skb->truesize)) {
36405 push_rxbufs(card, skb);
36406- atomic_inc(&vcc->stats->rx_drop);
36407+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36408 } else {
36409 skb_put(skb, len);
36410 dequeue_sm_buf(card, skb);
36411@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36412 ATM_SKB(skb)->vcc = vcc;
36413 __net_timestamp(skb);
36414 vcc->push(vcc, skb);
36415- atomic_inc(&vcc->stats->rx);
36416+ atomic_inc_unchecked(&vcc->stats->rx);
36417 }
36418 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36419 struct sk_buff *sb;
36420@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36421 if (len <= NS_SMBUFSIZE) {
36422 if (!atm_charge(vcc, sb->truesize)) {
36423 push_rxbufs(card, sb);
36424- atomic_inc(&vcc->stats->rx_drop);
36425+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36426 } else {
36427 skb_put(sb, len);
36428 dequeue_sm_buf(card, sb);
36429@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36430 ATM_SKB(sb)->vcc = vcc;
36431 __net_timestamp(sb);
36432 vcc->push(vcc, sb);
36433- atomic_inc(&vcc->stats->rx);
36434+ atomic_inc_unchecked(&vcc->stats->rx);
36435 }
36436
36437 push_rxbufs(card, skb);
36438@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36439
36440 if (!atm_charge(vcc, skb->truesize)) {
36441 push_rxbufs(card, skb);
36442- atomic_inc(&vcc->stats->rx_drop);
36443+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36444 } else {
36445 dequeue_lg_buf(card, skb);
36446 #ifdef NS_USE_DESTRUCTORS
36447@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36448 ATM_SKB(skb)->vcc = vcc;
36449 __net_timestamp(skb);
36450 vcc->push(vcc, skb);
36451- atomic_inc(&vcc->stats->rx);
36452+ atomic_inc_unchecked(&vcc->stats->rx);
36453 }
36454
36455 push_rxbufs(card, sb);
36456@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36457 printk
36458 ("nicstar%d: Out of huge buffers.\n",
36459 card->index);
36460- atomic_inc(&vcc->stats->rx_drop);
36461+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36462 recycle_iovec_rx_bufs(card,
36463 (struct iovec *)
36464 iovb->data,
36465@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36466 card->hbpool.count++;
36467 } else
36468 dev_kfree_skb_any(hb);
36469- atomic_inc(&vcc->stats->rx_drop);
36470+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36471 } else {
36472 /* Copy the small buffer to the huge buffer */
36473 sb = (struct sk_buff *)iov->iov_base;
36474@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36475 #endif /* NS_USE_DESTRUCTORS */
36476 __net_timestamp(hb);
36477 vcc->push(vcc, hb);
36478- atomic_inc(&vcc->stats->rx);
36479+ atomic_inc_unchecked(&vcc->stats->rx);
36480 }
36481 }
36482
36483diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36484index 32784d1..4a8434a 100644
36485--- a/drivers/atm/solos-pci.c
36486+++ b/drivers/atm/solos-pci.c
36487@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36488 }
36489 atm_charge(vcc, skb->truesize);
36490 vcc->push(vcc, skb);
36491- atomic_inc(&vcc->stats->rx);
36492+ atomic_inc_unchecked(&vcc->stats->rx);
36493 break;
36494
36495 case PKT_STATUS:
36496@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36497 vcc = SKB_CB(oldskb)->vcc;
36498
36499 if (vcc) {
36500- atomic_inc(&vcc->stats->tx);
36501+ atomic_inc_unchecked(&vcc->stats->tx);
36502 solos_pop(vcc, oldskb);
36503 } else {
36504 dev_kfree_skb_irq(oldskb);
36505diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36506index 0215934..ce9f5b1 100644
36507--- a/drivers/atm/suni.c
36508+++ b/drivers/atm/suni.c
36509@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36510
36511
36512 #define ADD_LIMITED(s,v) \
36513- atomic_add((v),&stats->s); \
36514- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36515+ atomic_add_unchecked((v),&stats->s); \
36516+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36517
36518
36519 static void suni_hz(unsigned long from_timer)
36520diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36521index 5120a96..e2572bd 100644
36522--- a/drivers/atm/uPD98402.c
36523+++ b/drivers/atm/uPD98402.c
36524@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36525 struct sonet_stats tmp;
36526 int error = 0;
36527
36528- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36529+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36530 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36531 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36532 if (zero && !error) {
36533@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36534
36535
36536 #define ADD_LIMITED(s,v) \
36537- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36538- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36539- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36540+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36541+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36542+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36543
36544
36545 static void stat_event(struct atm_dev *dev)
36546@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36547 if (reason & uPD98402_INT_PFM) stat_event(dev);
36548 if (reason & uPD98402_INT_PCO) {
36549 (void) GET(PCOCR); /* clear interrupt cause */
36550- atomic_add(GET(HECCT),
36551+ atomic_add_unchecked(GET(HECCT),
36552 &PRIV(dev)->sonet_stats.uncorr_hcs);
36553 }
36554 if ((reason & uPD98402_INT_RFO) &&
36555@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36556 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36557 uPD98402_INT_LOS),PIMR); /* enable them */
36558 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36559- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36560- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36561- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36562+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36563+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36564+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36565 return 0;
36566 }
36567
36568diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36569index 969c3c2..9b72956 100644
36570--- a/drivers/atm/zatm.c
36571+++ b/drivers/atm/zatm.c
36572@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36573 }
36574 if (!size) {
36575 dev_kfree_skb_irq(skb);
36576- if (vcc) atomic_inc(&vcc->stats->rx_err);
36577+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36578 continue;
36579 }
36580 if (!atm_charge(vcc,skb->truesize)) {
36581@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36582 skb->len = size;
36583 ATM_SKB(skb)->vcc = vcc;
36584 vcc->push(vcc,skb);
36585- atomic_inc(&vcc->stats->rx);
36586+ atomic_inc_unchecked(&vcc->stats->rx);
36587 }
36588 zout(pos & 0xffff,MTA(mbx));
36589 #if 0 /* probably a stupid idea */
36590@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36591 skb_queue_head(&zatm_vcc->backlog,skb);
36592 break;
36593 }
36594- atomic_inc(&vcc->stats->tx);
36595+ atomic_inc_unchecked(&vcc->stats->tx);
36596 wake_up(&zatm_vcc->tx_wait);
36597 }
36598
36599diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36600index 73f6c29..b0c0e13 100644
36601--- a/drivers/base/bus.c
36602+++ b/drivers/base/bus.c
36603@@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36604 return -EINVAL;
36605
36606 mutex_lock(&subsys->p->mutex);
36607- list_add_tail(&sif->node, &subsys->p->interfaces);
36608+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36609 if (sif->add_dev) {
36610 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36611 while ((dev = subsys_dev_iter_next(&iter)))
36612@@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36613 subsys = sif->subsys;
36614
36615 mutex_lock(&subsys->p->mutex);
36616- list_del_init(&sif->node);
36617+ pax_list_del_init((struct list_head *)&sif->node);
36618 if (sif->remove_dev) {
36619 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36620 while ((dev = subsys_dev_iter_next(&iter)))
36621diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36622index 0f38201..6c2b444 100644
36623--- a/drivers/base/devtmpfs.c
36624+++ b/drivers/base/devtmpfs.c
36625@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36626 if (!thread)
36627 return 0;
36628
36629- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36630+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36631 if (err)
36632 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36633 else
36634@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36635 *err = sys_unshare(CLONE_NEWNS);
36636 if (*err)
36637 goto out;
36638- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36639+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36640 if (*err)
36641 goto out;
36642- sys_chdir("/.."); /* will traverse into overmounted root */
36643- sys_chroot(".");
36644+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36645+ sys_chroot((char __force_user *)".");
36646 complete(&setup_done);
36647 while (1) {
36648 spin_lock(&req_lock);
36649diff --git a/drivers/base/node.c b/drivers/base/node.c
36650index bc9f43b..29703b8 100644
36651--- a/drivers/base/node.c
36652+++ b/drivers/base/node.c
36653@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36654 struct node_attr {
36655 struct device_attribute attr;
36656 enum node_states state;
36657-};
36658+} __do_const;
36659
36660 static ssize_t show_node_state(struct device *dev,
36661 struct device_attribute *attr, char *buf)
36662diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36663index bfb8955..42c9b9a 100644
36664--- a/drivers/base/power/domain.c
36665+++ b/drivers/base/power/domain.c
36666@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36667 {
36668 struct cpuidle_driver *cpuidle_drv;
36669 struct gpd_cpu_data *cpu_data;
36670- struct cpuidle_state *idle_state;
36671+ cpuidle_state_no_const *idle_state;
36672 int ret = 0;
36673
36674 if (IS_ERR_OR_NULL(genpd) || state < 0)
36675@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36676 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36677 {
36678 struct gpd_cpu_data *cpu_data;
36679- struct cpuidle_state *idle_state;
36680+ cpuidle_state_no_const *idle_state;
36681 int ret = 0;
36682
36683 if (IS_ERR_OR_NULL(genpd))
36684diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36685index 03e089a..0e9560c 100644
36686--- a/drivers/base/power/sysfs.c
36687+++ b/drivers/base/power/sysfs.c
36688@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36689 return -EIO;
36690 }
36691 }
36692- return sprintf(buf, p);
36693+ return sprintf(buf, "%s", p);
36694 }
36695
36696 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36697diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36698index 2d56f41..8830f19 100644
36699--- a/drivers/base/power/wakeup.c
36700+++ b/drivers/base/power/wakeup.c
36701@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36702 * They need to be modified together atomically, so it's better to use one
36703 * atomic variable to hold them both.
36704 */
36705-static atomic_t combined_event_count = ATOMIC_INIT(0);
36706+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36707
36708 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36709 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36710
36711 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36712 {
36713- unsigned int comb = atomic_read(&combined_event_count);
36714+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
36715
36716 *cnt = (comb >> IN_PROGRESS_BITS);
36717 *inpr = comb & MAX_IN_PROGRESS;
36718@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36719 ws->start_prevent_time = ws->last_time;
36720
36721 /* Increment the counter of events in progress. */
36722- cec = atomic_inc_return(&combined_event_count);
36723+ cec = atomic_inc_return_unchecked(&combined_event_count);
36724
36725 trace_wakeup_source_activate(ws->name, cec);
36726 }
36727@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36728 * Increment the counter of registered wakeup events and decrement the
36729 * couter of wakeup events in progress simultaneously.
36730 */
36731- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36732+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36733 trace_wakeup_source_deactivate(ws->name, cec);
36734
36735 split_counters(&cnt, &inpr);
36736diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36737index e8d11b6..7b1b36f 100644
36738--- a/drivers/base/syscore.c
36739+++ b/drivers/base/syscore.c
36740@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36741 void register_syscore_ops(struct syscore_ops *ops)
36742 {
36743 mutex_lock(&syscore_ops_lock);
36744- list_add_tail(&ops->node, &syscore_ops_list);
36745+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36746 mutex_unlock(&syscore_ops_lock);
36747 }
36748 EXPORT_SYMBOL_GPL(register_syscore_ops);
36749@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36750 void unregister_syscore_ops(struct syscore_ops *ops)
36751 {
36752 mutex_lock(&syscore_ops_lock);
36753- list_del(&ops->node);
36754+ pax_list_del((struct list_head *)&ops->node);
36755 mutex_unlock(&syscore_ops_lock);
36756 }
36757 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36758diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36759index b35fc4f..c902870 100644
36760--- a/drivers/block/cciss.c
36761+++ b/drivers/block/cciss.c
36762@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36763 while (!list_empty(&h->reqQ)) {
36764 c = list_entry(h->reqQ.next, CommandList_struct, list);
36765 /* can't do anything if fifo is full */
36766- if ((h->access.fifo_full(h))) {
36767+ if ((h->access->fifo_full(h))) {
36768 dev_warn(&h->pdev->dev, "fifo full\n");
36769 break;
36770 }
36771@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36772 h->Qdepth--;
36773
36774 /* Tell the controller execute command */
36775- h->access.submit_command(h, c);
36776+ h->access->submit_command(h, c);
36777
36778 /* Put job onto the completed Q */
36779 addQ(&h->cmpQ, c);
36780@@ -3447,17 +3447,17 @@ startio:
36781
36782 static inline unsigned long get_next_completion(ctlr_info_t *h)
36783 {
36784- return h->access.command_completed(h);
36785+ return h->access->command_completed(h);
36786 }
36787
36788 static inline int interrupt_pending(ctlr_info_t *h)
36789 {
36790- return h->access.intr_pending(h);
36791+ return h->access->intr_pending(h);
36792 }
36793
36794 static inline long interrupt_not_for_us(ctlr_info_t *h)
36795 {
36796- return ((h->access.intr_pending(h) == 0) ||
36797+ return ((h->access->intr_pending(h) == 0) ||
36798 (h->interrupts_enabled == 0));
36799 }
36800
36801@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36802 u32 a;
36803
36804 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36805- return h->access.command_completed(h);
36806+ return h->access->command_completed(h);
36807
36808 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36809 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36810@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36811 trans_support & CFGTBL_Trans_use_short_tags);
36812
36813 /* Change the access methods to the performant access methods */
36814- h->access = SA5_performant_access;
36815+ h->access = &SA5_performant_access;
36816 h->transMethod = CFGTBL_Trans_Performant;
36817
36818 return;
36819@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36820 if (prod_index < 0)
36821 return -ENODEV;
36822 h->product_name = products[prod_index].product_name;
36823- h->access = *(products[prod_index].access);
36824+ h->access = products[prod_index].access;
36825
36826 if (cciss_board_disabled(h)) {
36827 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36828@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36829 }
36830
36831 /* make sure the board interrupts are off */
36832- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36833+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36834 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36835 if (rc)
36836 goto clean2;
36837@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36838 * fake ones to scoop up any residual completions.
36839 */
36840 spin_lock_irqsave(&h->lock, flags);
36841- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36842+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36843 spin_unlock_irqrestore(&h->lock, flags);
36844 free_irq(h->intr[h->intr_mode], h);
36845 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36846@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36847 dev_info(&h->pdev->dev, "Board READY.\n");
36848 dev_info(&h->pdev->dev,
36849 "Waiting for stale completions to drain.\n");
36850- h->access.set_intr_mask(h, CCISS_INTR_ON);
36851+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36852 msleep(10000);
36853- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36854+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36855
36856 rc = controller_reset_failed(h->cfgtable);
36857 if (rc)
36858@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36859 cciss_scsi_setup(h);
36860
36861 /* Turn the interrupts on so we can service requests */
36862- h->access.set_intr_mask(h, CCISS_INTR_ON);
36863+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36864
36865 /* Get the firmware version */
36866 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36867@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36868 kfree(flush_buf);
36869 if (return_code != IO_OK)
36870 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36871- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36872+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36873 free_irq(h->intr[h->intr_mode], h);
36874 }
36875
36876diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36877index 7fda30e..2f27946 100644
36878--- a/drivers/block/cciss.h
36879+++ b/drivers/block/cciss.h
36880@@ -101,7 +101,7 @@ struct ctlr_info
36881 /* information about each logical volume */
36882 drive_info_struct *drv[CISS_MAX_LUN];
36883
36884- struct access_method access;
36885+ struct access_method *access;
36886
36887 /* queue and queue Info */
36888 struct list_head reqQ;
36889@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
36890 }
36891
36892 static struct access_method SA5_access = {
36893- SA5_submit_command,
36894- SA5_intr_mask,
36895- SA5_fifo_full,
36896- SA5_intr_pending,
36897- SA5_completed,
36898+ .submit_command = SA5_submit_command,
36899+ .set_intr_mask = SA5_intr_mask,
36900+ .fifo_full = SA5_fifo_full,
36901+ .intr_pending = SA5_intr_pending,
36902+ .command_completed = SA5_completed,
36903 };
36904
36905 static struct access_method SA5B_access = {
36906- SA5_submit_command,
36907- SA5B_intr_mask,
36908- SA5_fifo_full,
36909- SA5B_intr_pending,
36910- SA5_completed,
36911+ .submit_command = SA5_submit_command,
36912+ .set_intr_mask = SA5B_intr_mask,
36913+ .fifo_full = SA5_fifo_full,
36914+ .intr_pending = SA5B_intr_pending,
36915+ .command_completed = SA5_completed,
36916 };
36917
36918 static struct access_method SA5_performant_access = {
36919- SA5_submit_command,
36920- SA5_performant_intr_mask,
36921- SA5_fifo_full,
36922- SA5_performant_intr_pending,
36923- SA5_performant_completed,
36924+ .submit_command = SA5_submit_command,
36925+ .set_intr_mask = SA5_performant_intr_mask,
36926+ .fifo_full = SA5_fifo_full,
36927+ .intr_pending = SA5_performant_intr_pending,
36928+ .command_completed = SA5_performant_completed,
36929 };
36930
36931 struct board_type {
36932diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36933index 2b94403..fd6ad1f 100644
36934--- a/drivers/block/cpqarray.c
36935+++ b/drivers/block/cpqarray.c
36936@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36937 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36938 goto Enomem4;
36939 }
36940- hba[i]->access.set_intr_mask(hba[i], 0);
36941+ hba[i]->access->set_intr_mask(hba[i], 0);
36942 if (request_irq(hba[i]->intr, do_ida_intr,
36943 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36944 {
36945@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36946 add_timer(&hba[i]->timer);
36947
36948 /* Enable IRQ now that spinlock and rate limit timer are set up */
36949- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36950+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36951
36952 for(j=0; j<NWD; j++) {
36953 struct gendisk *disk = ida_gendisk[i][j];
36954@@ -694,7 +694,7 @@ DBGINFO(
36955 for(i=0; i<NR_PRODUCTS; i++) {
36956 if (board_id == products[i].board_id) {
36957 c->product_name = products[i].product_name;
36958- c->access = *(products[i].access);
36959+ c->access = products[i].access;
36960 break;
36961 }
36962 }
36963@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36964 hba[ctlr]->intr = intr;
36965 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36966 hba[ctlr]->product_name = products[j].product_name;
36967- hba[ctlr]->access = *(products[j].access);
36968+ hba[ctlr]->access = products[j].access;
36969 hba[ctlr]->ctlr = ctlr;
36970 hba[ctlr]->board_id = board_id;
36971 hba[ctlr]->pci_dev = NULL; /* not PCI */
36972@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36973
36974 while((c = h->reqQ) != NULL) {
36975 /* Can't do anything if we're busy */
36976- if (h->access.fifo_full(h) == 0)
36977+ if (h->access->fifo_full(h) == 0)
36978 return;
36979
36980 /* Get the first entry from the request Q */
36981@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36982 h->Qdepth--;
36983
36984 /* Tell the controller to do our bidding */
36985- h->access.submit_command(h, c);
36986+ h->access->submit_command(h, c);
36987
36988 /* Get onto the completion Q */
36989 addQ(&h->cmpQ, c);
36990@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36991 unsigned long flags;
36992 __u32 a,a1;
36993
36994- istat = h->access.intr_pending(h);
36995+ istat = h->access->intr_pending(h);
36996 /* Is this interrupt for us? */
36997 if (istat == 0)
36998 return IRQ_NONE;
36999@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37000 */
37001 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37002 if (istat & FIFO_NOT_EMPTY) {
37003- while((a = h->access.command_completed(h))) {
37004+ while((a = h->access->command_completed(h))) {
37005 a1 = a; a &= ~3;
37006 if ((c = h->cmpQ) == NULL)
37007 {
37008@@ -1448,11 +1448,11 @@ static int sendcmd(
37009 /*
37010 * Disable interrupt
37011 */
37012- info_p->access.set_intr_mask(info_p, 0);
37013+ info_p->access->set_intr_mask(info_p, 0);
37014 /* Make sure there is room in the command FIFO */
37015 /* Actually it should be completely empty at this time. */
37016 for (i = 200000; i > 0; i--) {
37017- temp = info_p->access.fifo_full(info_p);
37018+ temp = info_p->access->fifo_full(info_p);
37019 if (temp != 0) {
37020 break;
37021 }
37022@@ -1465,7 +1465,7 @@ DBG(
37023 /*
37024 * Send the cmd
37025 */
37026- info_p->access.submit_command(info_p, c);
37027+ info_p->access->submit_command(info_p, c);
37028 complete = pollcomplete(ctlr);
37029
37030 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37031@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37032 * we check the new geometry. Then turn interrupts back on when
37033 * we're done.
37034 */
37035- host->access.set_intr_mask(host, 0);
37036+ host->access->set_intr_mask(host, 0);
37037 getgeometry(ctlr);
37038- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37039+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37040
37041 for(i=0; i<NWD; i++) {
37042 struct gendisk *disk = ida_gendisk[ctlr][i];
37043@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37044 /* Wait (up to 2 seconds) for a command to complete */
37045
37046 for (i = 200000; i > 0; i--) {
37047- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37048+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37049 if (done == 0) {
37050 udelay(10); /* a short fixed delay */
37051 } else
37052diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37053index be73e9d..7fbf140 100644
37054--- a/drivers/block/cpqarray.h
37055+++ b/drivers/block/cpqarray.h
37056@@ -99,7 +99,7 @@ struct ctlr_info {
37057 drv_info_t drv[NWD];
37058 struct proc_dir_entry *proc;
37059
37060- struct access_method access;
37061+ struct access_method *access;
37062
37063 cmdlist_t *reqQ;
37064 cmdlist_t *cmpQ;
37065diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37066index 0e06f0c..c47b81d 100644
37067--- a/drivers/block/drbd/drbd_int.h
37068+++ b/drivers/block/drbd/drbd_int.h
37069@@ -582,7 +582,7 @@ struct drbd_epoch {
37070 struct drbd_tconn *tconn;
37071 struct list_head list;
37072 unsigned int barrier_nr;
37073- atomic_t epoch_size; /* increased on every request added. */
37074+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37075 atomic_t active; /* increased on every req. added, and dec on every finished. */
37076 unsigned long flags;
37077 };
37078@@ -1022,7 +1022,7 @@ struct drbd_conf {
37079 unsigned int al_tr_number;
37080 int al_tr_cycle;
37081 wait_queue_head_t seq_wait;
37082- atomic_t packet_seq;
37083+ atomic_unchecked_t packet_seq;
37084 unsigned int peer_seq;
37085 spinlock_t peer_seq_lock;
37086 unsigned int minor;
37087@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37088 char __user *uoptval;
37089 int err;
37090
37091- uoptval = (char __user __force *)optval;
37092+ uoptval = (char __force_user *)optval;
37093
37094 set_fs(KERNEL_DS);
37095 if (level == SOL_SOCKET)
37096diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37097index 89c497c..9c736ae 100644
37098--- a/drivers/block/drbd/drbd_interval.c
37099+++ b/drivers/block/drbd/drbd_interval.c
37100@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37101 }
37102
37103 static const struct rb_augment_callbacks augment_callbacks = {
37104- augment_propagate,
37105- augment_copy,
37106- augment_rotate,
37107+ .propagate = augment_propagate,
37108+ .copy = augment_copy,
37109+ .rotate = augment_rotate,
37110 };
37111
37112 /**
37113diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37114index 9e3818b..7b64c92 100644
37115--- a/drivers/block/drbd/drbd_main.c
37116+++ b/drivers/block/drbd/drbd_main.c
37117@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37118 p->sector = sector;
37119 p->block_id = block_id;
37120 p->blksize = blksize;
37121- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37122+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37123 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37124 }
37125
37126@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37127 return -EIO;
37128 p->sector = cpu_to_be64(req->i.sector);
37129 p->block_id = (unsigned long)req;
37130- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37131+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37132 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37133 if (mdev->state.conn >= C_SYNC_SOURCE &&
37134 mdev->state.conn <= C_PAUSED_SYNC_T)
37135@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37136 {
37137 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37138
37139- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37140- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37141+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37142+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37143 kfree(tconn->current_epoch);
37144
37145 idr_destroy(&tconn->volumes);
37146diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37147index c706d50..5e1b472 100644
37148--- a/drivers/block/drbd/drbd_nl.c
37149+++ b/drivers/block/drbd/drbd_nl.c
37150@@ -3440,7 +3440,7 @@ out:
37151
37152 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37153 {
37154- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37155+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37156 struct sk_buff *msg;
37157 struct drbd_genlmsghdr *d_out;
37158 unsigned seq;
37159@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37160 return;
37161 }
37162
37163- seq = atomic_inc_return(&drbd_genl_seq);
37164+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37165 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37166 if (!msg)
37167 goto failed;
37168diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37169index 6fa6673..b7f97e9 100644
37170--- a/drivers/block/drbd/drbd_receiver.c
37171+++ b/drivers/block/drbd/drbd_receiver.c
37172@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37173 {
37174 int err;
37175
37176- atomic_set(&mdev->packet_seq, 0);
37177+ atomic_set_unchecked(&mdev->packet_seq, 0);
37178 mdev->peer_seq = 0;
37179
37180 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37181@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37182 do {
37183 next_epoch = NULL;
37184
37185- epoch_size = atomic_read(&epoch->epoch_size);
37186+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37187
37188 switch (ev & ~EV_CLEANUP) {
37189 case EV_PUT:
37190@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37191 rv = FE_DESTROYED;
37192 } else {
37193 epoch->flags = 0;
37194- atomic_set(&epoch->epoch_size, 0);
37195+ atomic_set_unchecked(&epoch->epoch_size, 0);
37196 /* atomic_set(&epoch->active, 0); is already zero */
37197 if (rv == FE_STILL_LIVE)
37198 rv = FE_RECYCLED;
37199@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37200 conn_wait_active_ee_empty(tconn);
37201 drbd_flush(tconn);
37202
37203- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37204+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37205 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37206 if (epoch)
37207 break;
37208@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37209 }
37210
37211 epoch->flags = 0;
37212- atomic_set(&epoch->epoch_size, 0);
37213+ atomic_set_unchecked(&epoch->epoch_size, 0);
37214 atomic_set(&epoch->active, 0);
37215
37216 spin_lock(&tconn->epoch_lock);
37217- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37218+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37219 list_add(&epoch->list, &tconn->current_epoch->list);
37220 tconn->current_epoch = epoch;
37221 tconn->epochs++;
37222@@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37223
37224 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37225 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37226- atomic_inc(&tconn->current_epoch->epoch_size);
37227+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37228 err2 = drbd_drain_block(mdev, pi->size);
37229 if (!err)
37230 err = err2;
37231@@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37232
37233 spin_lock(&tconn->epoch_lock);
37234 peer_req->epoch = tconn->current_epoch;
37235- atomic_inc(&peer_req->epoch->epoch_size);
37236+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37237 atomic_inc(&peer_req->epoch->active);
37238 spin_unlock(&tconn->epoch_lock);
37239
37240@@ -4344,7 +4344,7 @@ struct data_cmd {
37241 int expect_payload;
37242 size_t pkt_size;
37243 int (*fn)(struct drbd_tconn *, struct packet_info *);
37244-};
37245+} __do_const;
37246
37247 static struct data_cmd drbd_cmd_handler[] = {
37248 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37249@@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37250 if (!list_empty(&tconn->current_epoch->list))
37251 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37252 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37253- atomic_set(&tconn->current_epoch->epoch_size, 0);
37254+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37255 tconn->send.seen_any_write_yet = false;
37256
37257 conn_info(tconn, "Connection closed\n");
37258@@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37259 struct asender_cmd {
37260 size_t pkt_size;
37261 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37262-};
37263+} __do_const;
37264
37265 static struct asender_cmd asender_tbl[] = {
37266 [P_PING] = { 0, got_Ping },
37267diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37268index c8dac73..1800093 100644
37269--- a/drivers/block/loop.c
37270+++ b/drivers/block/loop.c
37271@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37272
37273 file_start_write(file);
37274 set_fs(get_ds());
37275- bw = file->f_op->write(file, buf, len, &pos);
37276+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37277 set_fs(old_fs);
37278 file_end_write(file);
37279 if (likely(bw == len))
37280diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37281index 83a598e..2de5ce3 100644
37282--- a/drivers/block/null_blk.c
37283+++ b/drivers/block/null_blk.c
37284@@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37285 return 0;
37286 }
37287
37288-static struct blk_mq_ops null_mq_ops = {
37289- .queue_rq = null_queue_rq,
37290- .map_queue = blk_mq_map_queue,
37291+static struct blk_mq_ops null_mq_single_ops = {
37292+ .queue_rq = null_queue_rq,
37293+ .map_queue = blk_mq_map_queue,
37294 .init_hctx = null_init_hctx,
37295+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
37296+ .free_hctx = blk_mq_free_single_hw_queue,
37297+};
37298+
37299+static struct blk_mq_ops null_mq_per_node_ops = {
37300+ .queue_rq = null_queue_rq,
37301+ .map_queue = blk_mq_map_queue,
37302+ .init_hctx = null_init_hctx,
37303+ .alloc_hctx = null_alloc_hctx,
37304+ .free_hctx = null_free_hctx,
37305 };
37306
37307 static struct blk_mq_reg null_mq_reg = {
37308- .ops = &null_mq_ops,
37309+ .ops = &null_mq_single_ops,
37310 .queue_depth = 64,
37311 .cmd_size = sizeof(struct nullb_cmd),
37312 .flags = BLK_MQ_F_SHOULD_MERGE,
37313@@ -545,13 +555,8 @@ static int null_add_dev(void)
37314 null_mq_reg.queue_depth = hw_queue_depth;
37315 null_mq_reg.nr_hw_queues = submit_queues;
37316
37317- if (use_per_node_hctx) {
37318- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37319- null_mq_reg.ops->free_hctx = null_free_hctx;
37320- } else {
37321- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37322- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37323- }
37324+ if (use_per_node_hctx)
37325+ null_mq_reg.ops = &null_mq_per_node_ops;
37326
37327 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37328 } else if (queue_mode == NULL_Q_BIO) {
37329diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37330index ff8668c..f62167a 100644
37331--- a/drivers/block/pktcdvd.c
37332+++ b/drivers/block/pktcdvd.c
37333@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37334
37335 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37336 {
37337- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37338+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37339 }
37340
37341 /*
37342@@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37343 return -EROFS;
37344 }
37345 pd->settings.fp = ti.fp;
37346- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37347+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37348
37349 if (ti.nwa_v) {
37350 pd->nwa = be32_to_cpu(ti.next_writable);
37351diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37352index e5565fb..71be10b4 100644
37353--- a/drivers/block/smart1,2.h
37354+++ b/drivers/block/smart1,2.h
37355@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37356 }
37357
37358 static struct access_method smart4_access = {
37359- smart4_submit_command,
37360- smart4_intr_mask,
37361- smart4_fifo_full,
37362- smart4_intr_pending,
37363- smart4_completed,
37364+ .submit_command = smart4_submit_command,
37365+ .set_intr_mask = smart4_intr_mask,
37366+ .fifo_full = smart4_fifo_full,
37367+ .intr_pending = smart4_intr_pending,
37368+ .command_completed = smart4_completed,
37369 };
37370
37371 /*
37372@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37373 }
37374
37375 static struct access_method smart2_access = {
37376- smart2_submit_command,
37377- smart2_intr_mask,
37378- smart2_fifo_full,
37379- smart2_intr_pending,
37380- smart2_completed,
37381+ .submit_command = smart2_submit_command,
37382+ .set_intr_mask = smart2_intr_mask,
37383+ .fifo_full = smart2_fifo_full,
37384+ .intr_pending = smart2_intr_pending,
37385+ .command_completed = smart2_completed,
37386 };
37387
37388 /*
37389@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37390 }
37391
37392 static struct access_method smart2e_access = {
37393- smart2e_submit_command,
37394- smart2e_intr_mask,
37395- smart2e_fifo_full,
37396- smart2e_intr_pending,
37397- smart2e_completed,
37398+ .submit_command = smart2e_submit_command,
37399+ .set_intr_mask = smart2e_intr_mask,
37400+ .fifo_full = smart2e_fifo_full,
37401+ .intr_pending = smart2e_intr_pending,
37402+ .command_completed = smart2e_completed,
37403 };
37404
37405 /*
37406@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37407 }
37408
37409 static struct access_method smart1_access = {
37410- smart1_submit_command,
37411- smart1_intr_mask,
37412- smart1_fifo_full,
37413- smart1_intr_pending,
37414- smart1_completed,
37415+ .submit_command = smart1_submit_command,
37416+ .set_intr_mask = smart1_intr_mask,
37417+ .fifo_full = smart1_fifo_full,
37418+ .intr_pending = smart1_intr_pending,
37419+ .command_completed = smart1_completed,
37420 };
37421diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37422index f038dba..bb74c08 100644
37423--- a/drivers/bluetooth/btwilink.c
37424+++ b/drivers/bluetooth/btwilink.c
37425@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
37426
37427 static int bt_ti_probe(struct platform_device *pdev)
37428 {
37429- static struct ti_st *hst;
37430+ struct ti_st *hst;
37431 struct hci_dev *hdev;
37432 int err;
37433
37434diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
37435index b6739cb..962fd35 100644
37436--- a/drivers/bus/arm-cci.c
37437+++ b/drivers/bus/arm-cci.c
37438@@ -979,7 +979,7 @@ static int cci_probe(void)
37439
37440 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
37441
37442- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
37443+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
37444 if (!ports)
37445 return -ENOMEM;
37446
37447diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37448index 8a3aff7..d7538c2 100644
37449--- a/drivers/cdrom/cdrom.c
37450+++ b/drivers/cdrom/cdrom.c
37451@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37452 ENSURE(reset, CDC_RESET);
37453 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37454 cdi->mc_flags = 0;
37455- cdo->n_minors = 0;
37456 cdi->options = CDO_USE_FFLAGS;
37457
37458 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
37459@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
37460 else
37461 cdi->cdda_method = CDDA_OLD;
37462
37463- if (!cdo->generic_packet)
37464- cdo->generic_packet = cdrom_dummy_generic_packet;
37465+ if (!cdo->generic_packet) {
37466+ pax_open_kernel();
37467+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
37468+ pax_close_kernel();
37469+ }
37470
37471 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
37472 mutex_lock(&cdrom_mutex);
37473@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
37474 if (cdi->exit)
37475 cdi->exit(cdi);
37476
37477- cdi->ops->n_minors--;
37478 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
37479 }
37480
37481@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
37482 */
37483 nr = nframes;
37484 do {
37485- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37486+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37487 if (cgc.buffer)
37488 break;
37489
37490@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
37491 struct cdrom_device_info *cdi;
37492 int ret;
37493
37494- ret = scnprintf(info + *pos, max_size - *pos, header);
37495+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
37496 if (!ret)
37497 return 1;
37498
37499diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
37500index 5980cb9..6d7bd7e 100644
37501--- a/drivers/cdrom/gdrom.c
37502+++ b/drivers/cdrom/gdrom.c
37503@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
37504 .audio_ioctl = gdrom_audio_ioctl,
37505 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
37506 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37507- .n_minors = 1,
37508 };
37509
37510 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37511diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37512index fa3243d..8c98297 100644
37513--- a/drivers/char/Kconfig
37514+++ b/drivers/char/Kconfig
37515@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37516
37517 config DEVKMEM
37518 bool "/dev/kmem virtual device support"
37519- default y
37520+ default n
37521+ depends on !GRKERNSEC_KMEM
37522 help
37523 Say Y here if you want to support the /dev/kmem device. The
37524 /dev/kmem device is rarely used, but can be used for certain
37525@@ -576,6 +577,7 @@ config DEVPORT
37526 bool
37527 depends on !M68K
37528 depends on ISA || PCI
37529+ depends on !GRKERNSEC_KMEM
37530 default y
37531
37532 source "drivers/s390/char/Kconfig"
37533diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37534index a48e05b..6bac831 100644
37535--- a/drivers/char/agp/compat_ioctl.c
37536+++ b/drivers/char/agp/compat_ioctl.c
37537@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37538 return -ENOMEM;
37539 }
37540
37541- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37542+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37543 sizeof(*usegment) * ureserve.seg_count)) {
37544 kfree(usegment);
37545 kfree(ksegment);
37546diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37547index 1b19239..b87b143 100644
37548--- a/drivers/char/agp/frontend.c
37549+++ b/drivers/char/agp/frontend.c
37550@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37551 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37552 return -EFAULT;
37553
37554- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37555+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37556 return -EFAULT;
37557
37558 client = agp_find_client_by_pid(reserve.pid);
37559@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37560 if (segment == NULL)
37561 return -ENOMEM;
37562
37563- if (copy_from_user(segment, (void __user *) reserve.seg_list,
37564+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37565 sizeof(struct agp_segment) * reserve.seg_count)) {
37566 kfree(segment);
37567 return -EFAULT;
37568diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37569index 4f94375..413694e 100644
37570--- a/drivers/char/genrtc.c
37571+++ b/drivers/char/genrtc.c
37572@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37573 switch (cmd) {
37574
37575 case RTC_PLL_GET:
37576+ memset(&pll, 0, sizeof(pll));
37577 if (get_rtc_pll(&pll))
37578 return -EINVAL;
37579 else
37580diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37581index 5d9c31d..c94ccb5 100644
37582--- a/drivers/char/hpet.c
37583+++ b/drivers/char/hpet.c
37584@@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37585 }
37586
37587 static int
37588-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37589+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37590 struct hpet_info *info)
37591 {
37592 struct hpet_timer __iomem *timer;
37593diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37594index 86fe45c..c0ea948 100644
37595--- a/drivers/char/hw_random/intel-rng.c
37596+++ b/drivers/char/hw_random/intel-rng.c
37597@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37598
37599 if (no_fwh_detect)
37600 return -ENODEV;
37601- printk(warning);
37602+ printk("%s", warning);
37603 return -EBUSY;
37604 }
37605
37606diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37607index ec4e10f..f2a763b 100644
37608--- a/drivers/char/ipmi/ipmi_msghandler.c
37609+++ b/drivers/char/ipmi/ipmi_msghandler.c
37610@@ -420,7 +420,7 @@ struct ipmi_smi {
37611 struct proc_dir_entry *proc_dir;
37612 char proc_dir_name[10];
37613
37614- atomic_t stats[IPMI_NUM_STATS];
37615+ atomic_unchecked_t stats[IPMI_NUM_STATS];
37616
37617 /*
37618 * run_to_completion duplicate of smb_info, smi_info
37619@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37620
37621
37622 #define ipmi_inc_stat(intf, stat) \
37623- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37624+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37625 #define ipmi_get_stat(intf, stat) \
37626- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37627+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37628
37629 static int is_lan_addr(struct ipmi_addr *addr)
37630 {
37631@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37632 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37633 init_waitqueue_head(&intf->waitq);
37634 for (i = 0; i < IPMI_NUM_STATS; i++)
37635- atomic_set(&intf->stats[i], 0);
37636+ atomic_set_unchecked(&intf->stats[i], 0);
37637
37638 intf->proc_dir = NULL;
37639
37640diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37641index 15e4a60..b046093 100644
37642--- a/drivers/char/ipmi/ipmi_si_intf.c
37643+++ b/drivers/char/ipmi/ipmi_si_intf.c
37644@@ -280,7 +280,7 @@ struct smi_info {
37645 unsigned char slave_addr;
37646
37647 /* Counters and things for the proc filesystem. */
37648- atomic_t stats[SI_NUM_STATS];
37649+ atomic_unchecked_t stats[SI_NUM_STATS];
37650
37651 struct task_struct *thread;
37652
37653@@ -289,9 +289,9 @@ struct smi_info {
37654 };
37655
37656 #define smi_inc_stat(smi, stat) \
37657- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37658+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37659 #define smi_get_stat(smi, stat) \
37660- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37661+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37662
37663 #define SI_MAX_PARMS 4
37664
37665@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
37666 atomic_set(&new_smi->req_events, 0);
37667 new_smi->run_to_completion = 0;
37668 for (i = 0; i < SI_NUM_STATS; i++)
37669- atomic_set(&new_smi->stats[i], 0);
37670+ atomic_set_unchecked(&new_smi->stats[i], 0);
37671
37672 new_smi->interrupt_disabled = 1;
37673 atomic_set(&new_smi->stop_operation, 0);
37674diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37675index f895a8c..2bc9147 100644
37676--- a/drivers/char/mem.c
37677+++ b/drivers/char/mem.c
37678@@ -18,6 +18,7 @@
37679 #include <linux/raw.h>
37680 #include <linux/tty.h>
37681 #include <linux/capability.h>
37682+#include <linux/security.h>
37683 #include <linux/ptrace.h>
37684 #include <linux/device.h>
37685 #include <linux/highmem.h>
37686@@ -37,6 +38,10 @@
37687
37688 #define DEVPORT_MINOR 4
37689
37690+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37691+extern const struct file_operations grsec_fops;
37692+#endif
37693+
37694 static inline unsigned long size_inside_page(unsigned long start,
37695 unsigned long size)
37696 {
37697@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37698
37699 while (cursor < to) {
37700 if (!devmem_is_allowed(pfn)) {
37701+#ifdef CONFIG_GRKERNSEC_KMEM
37702+ gr_handle_mem_readwrite(from, to);
37703+#else
37704 printk(KERN_INFO
37705 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37706 current->comm, from, to);
37707+#endif
37708 return 0;
37709 }
37710 cursor += PAGE_SIZE;
37711@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37712 }
37713 return 1;
37714 }
37715+#elif defined(CONFIG_GRKERNSEC_KMEM)
37716+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37717+{
37718+ return 0;
37719+}
37720 #else
37721 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37722 {
37723@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37724
37725 while (count > 0) {
37726 unsigned long remaining;
37727+ char *temp;
37728
37729 sz = size_inside_page(p, count);
37730
37731@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37732 if (!ptr)
37733 return -EFAULT;
37734
37735- remaining = copy_to_user(buf, ptr, sz);
37736+#ifdef CONFIG_PAX_USERCOPY
37737+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37738+ if (!temp) {
37739+ unxlate_dev_mem_ptr(p, ptr);
37740+ return -ENOMEM;
37741+ }
37742+ memcpy(temp, ptr, sz);
37743+#else
37744+ temp = ptr;
37745+#endif
37746+
37747+ remaining = copy_to_user(buf, temp, sz);
37748+
37749+#ifdef CONFIG_PAX_USERCOPY
37750+ kfree(temp);
37751+#endif
37752+
37753 unxlate_dev_mem_ptr(p, ptr);
37754 if (remaining)
37755 return -EFAULT;
37756@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37757 size_t count, loff_t *ppos)
37758 {
37759 unsigned long p = *ppos;
37760- ssize_t low_count, read, sz;
37761+ ssize_t low_count, read, sz, err = 0;
37762 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37763- int err = 0;
37764
37765 read = 0;
37766 if (p < (unsigned long) high_memory) {
37767@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37768 }
37769 #endif
37770 while (low_count > 0) {
37771+ char *temp;
37772+
37773 sz = size_inside_page(p, low_count);
37774
37775 /*
37776@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37777 */
37778 kbuf = xlate_dev_kmem_ptr((char *)p);
37779
37780- if (copy_to_user(buf, kbuf, sz))
37781+#ifdef CONFIG_PAX_USERCOPY
37782+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37783+ if (!temp)
37784+ return -ENOMEM;
37785+ memcpy(temp, kbuf, sz);
37786+#else
37787+ temp = kbuf;
37788+#endif
37789+
37790+ err = copy_to_user(buf, temp, sz);
37791+
37792+#ifdef CONFIG_PAX_USERCOPY
37793+ kfree(temp);
37794+#endif
37795+
37796+ if (err)
37797 return -EFAULT;
37798 buf += sz;
37799 p += sz;
37800@@ -822,6 +869,9 @@ static const struct memdev {
37801 #ifdef CONFIG_PRINTK
37802 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
37803 #endif
37804+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37805+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37806+#endif
37807 };
37808
37809 static int memory_open(struct inode *inode, struct file *filp)
37810@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
37811 continue;
37812
37813 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37814- NULL, devlist[minor].name);
37815+ NULL, "%s", devlist[minor].name);
37816 }
37817
37818 return tty_init();
37819diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37820index 9df78e2..01ba9ae 100644
37821--- a/drivers/char/nvram.c
37822+++ b/drivers/char/nvram.c
37823@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37824
37825 spin_unlock_irq(&rtc_lock);
37826
37827- if (copy_to_user(buf, contents, tmp - contents))
37828+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37829 return -EFAULT;
37830
37831 *ppos = i;
37832diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37833index d39cca6..8c1e269 100644
37834--- a/drivers/char/pcmcia/synclink_cs.c
37835+++ b/drivers/char/pcmcia/synclink_cs.c
37836@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37837
37838 if (debug_level >= DEBUG_LEVEL_INFO)
37839 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37840- __FILE__, __LINE__, info->device_name, port->count);
37841+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37842
37843- WARN_ON(!port->count);
37844+ WARN_ON(!atomic_read(&port->count));
37845
37846 if (tty_port_close_start(port, tty, filp) == 0)
37847 goto cleanup;
37848@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37849 cleanup:
37850 if (debug_level >= DEBUG_LEVEL_INFO)
37851 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37852- tty->driver->name, port->count);
37853+ tty->driver->name, atomic_read(&port->count));
37854 }
37855
37856 /* Wait until the transmitter is empty.
37857@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37858
37859 if (debug_level >= DEBUG_LEVEL_INFO)
37860 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37861- __FILE__, __LINE__, tty->driver->name, port->count);
37862+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37863
37864 /* If port is closing, signal caller to try again */
37865 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37866@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37867 goto cleanup;
37868 }
37869 spin_lock(&port->lock);
37870- port->count++;
37871+ atomic_inc(&port->count);
37872 spin_unlock(&port->lock);
37873 spin_unlock_irqrestore(&info->netlock, flags);
37874
37875- if (port->count == 1) {
37876+ if (atomic_read(&port->count) == 1) {
37877 /* 1st open on this device, init hardware */
37878 retval = startup(info, tty);
37879 if (retval < 0)
37880@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37881 unsigned short new_crctype;
37882
37883 /* return error if TTY interface open */
37884- if (info->port.count)
37885+ if (atomic_read(&info->port.count))
37886 return -EBUSY;
37887
37888 switch (encoding)
37889@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37890
37891 /* arbitrate between network and tty opens */
37892 spin_lock_irqsave(&info->netlock, flags);
37893- if (info->port.count != 0 || info->netcount != 0) {
37894+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37895 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37896 spin_unlock_irqrestore(&info->netlock, flags);
37897 return -EBUSY;
37898@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37899 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37900
37901 /* return error if TTY interface open */
37902- if (info->port.count)
37903+ if (atomic_read(&info->port.count))
37904 return -EBUSY;
37905
37906 if (cmd != SIOCWANDEV)
37907diff --git a/drivers/char/random.c b/drivers/char/random.c
37908index 429b75b..03d60db 100644
37909--- a/drivers/char/random.c
37910+++ b/drivers/char/random.c
37911@@ -270,10 +270,17 @@
37912 /*
37913 * Configuration information
37914 */
37915+#ifdef CONFIG_GRKERNSEC_RANDNET
37916+#define INPUT_POOL_SHIFT 14
37917+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
37918+#define OUTPUT_POOL_SHIFT 12
37919+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
37920+#else
37921 #define INPUT_POOL_SHIFT 12
37922 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
37923 #define OUTPUT_POOL_SHIFT 10
37924 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
37925+#endif
37926 #define SEC_XFER_SIZE 512
37927 #define EXTRACT_SIZE 10
37928
37929@@ -361,12 +368,19 @@ static struct poolinfo {
37930 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
37931 int tap1, tap2, tap3, tap4, tap5;
37932 } poolinfo_table[] = {
37933+#ifdef CONFIG_GRKERNSEC_RANDNET
37934+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37935+ { S(512), 411, 308, 208, 104, 1 },
37936+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37937+ { S(128), 104, 76, 51, 25, 1 },
37938+#else
37939 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
37940 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
37941 { S(128), 104, 76, 51, 25, 1 },
37942 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
37943 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
37944 { S(32), 26, 19, 14, 7, 1 },
37945+#endif
37946 #if 0
37947 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
37948 { S(2048), 1638, 1231, 819, 411, 1 },
37949@@ -524,8 +538,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
37950 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
37951 }
37952
37953- ACCESS_ONCE(r->input_rotate) = input_rotate;
37954- ACCESS_ONCE(r->add_ptr) = i;
37955+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
37956+ ACCESS_ONCE_RW(r->add_ptr) = i;
37957 smp_wmb();
37958
37959 if (out)
37960@@ -1151,7 +1165,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
37961
37962 extract_buf(r, tmp);
37963 i = min_t(int, nbytes, EXTRACT_SIZE);
37964- if (copy_to_user(buf, tmp, i)) {
37965+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37966 ret = -EFAULT;
37967 break;
37968 }
37969@@ -1507,7 +1521,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37970 #include <linux/sysctl.h>
37971
37972 static int min_read_thresh = 8, min_write_thresh;
37973-static int max_read_thresh = INPUT_POOL_WORDS * 32;
37974+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
37975 static int max_write_thresh = INPUT_POOL_WORDS * 32;
37976 static char sysctl_bootid[16];
37977
37978@@ -1523,7 +1537,7 @@ static char sysctl_bootid[16];
37979 static int proc_do_uuid(struct ctl_table *table, int write,
37980 void __user *buffer, size_t *lenp, loff_t *ppos)
37981 {
37982- struct ctl_table fake_table;
37983+ ctl_table_no_const fake_table;
37984 unsigned char buf[64], tmp_uuid[16], *uuid;
37985
37986 uuid = table->data;
37987@@ -1553,7 +1567,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
37988 static int proc_do_entropy(ctl_table *table, int write,
37989 void __user *buffer, size_t *lenp, loff_t *ppos)
37990 {
37991- ctl_table fake_table;
37992+ ctl_table_no_const fake_table;
37993 int entropy_count;
37994
37995 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
37996diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37997index 7cc1fe22..b602d6b 100644
37998--- a/drivers/char/sonypi.c
37999+++ b/drivers/char/sonypi.c
38000@@ -54,6 +54,7 @@
38001
38002 #include <asm/uaccess.h>
38003 #include <asm/io.h>
38004+#include <asm/local.h>
38005
38006 #include <linux/sonypi.h>
38007
38008@@ -490,7 +491,7 @@ static struct sonypi_device {
38009 spinlock_t fifo_lock;
38010 wait_queue_head_t fifo_proc_list;
38011 struct fasync_struct *fifo_async;
38012- int open_count;
38013+ local_t open_count;
38014 int model;
38015 struct input_dev *input_jog_dev;
38016 struct input_dev *input_key_dev;
38017@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38018 static int sonypi_misc_release(struct inode *inode, struct file *file)
38019 {
38020 mutex_lock(&sonypi_device.lock);
38021- sonypi_device.open_count--;
38022+ local_dec(&sonypi_device.open_count);
38023 mutex_unlock(&sonypi_device.lock);
38024 return 0;
38025 }
38026@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38027 {
38028 mutex_lock(&sonypi_device.lock);
38029 /* Flush input queue on first open */
38030- if (!sonypi_device.open_count)
38031+ if (!local_read(&sonypi_device.open_count))
38032 kfifo_reset(&sonypi_device.fifo);
38033- sonypi_device.open_count++;
38034+ local_inc(&sonypi_device.open_count);
38035 mutex_unlock(&sonypi_device.lock);
38036
38037 return 0;
38038diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38039index 64420b3..5c40b56 100644
38040--- a/drivers/char/tpm/tpm_acpi.c
38041+++ b/drivers/char/tpm/tpm_acpi.c
38042@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38043 virt = acpi_os_map_memory(start, len);
38044 if (!virt) {
38045 kfree(log->bios_event_log);
38046+ log->bios_event_log = NULL;
38047 printk("%s: ERROR - Unable to map memory\n", __func__);
38048 return -EIO;
38049 }
38050
38051- memcpy_fromio(log->bios_event_log, virt, len);
38052+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38053
38054 acpi_os_unmap_memory(virt, len);
38055 return 0;
38056diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38057index 59f7cb2..bac8b6d 100644
38058--- a/drivers/char/tpm/tpm_eventlog.c
38059+++ b/drivers/char/tpm/tpm_eventlog.c
38060@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38061 event = addr;
38062
38063 if ((event->event_type == 0 && event->event_size == 0) ||
38064- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38065+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38066 return NULL;
38067
38068 return addr;
38069@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38070 return NULL;
38071
38072 if ((event->event_type == 0 && event->event_size == 0) ||
38073- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38074+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38075 return NULL;
38076
38077 (*pos)++;
38078@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38079 int i;
38080
38081 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38082- seq_putc(m, data[i]);
38083+ if (!seq_putc(m, data[i]))
38084+ return -EFAULT;
38085
38086 return 0;
38087 }
38088diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38089index feea87c..18aefff 100644
38090--- a/drivers/char/virtio_console.c
38091+++ b/drivers/char/virtio_console.c
38092@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38093 if (to_user) {
38094 ssize_t ret;
38095
38096- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38097+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38098 if (ret)
38099 return -EFAULT;
38100 } else {
38101@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38102 if (!port_has_data(port) && !port->host_connected)
38103 return 0;
38104
38105- return fill_readbuf(port, ubuf, count, true);
38106+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38107 }
38108
38109 static int wait_port_writable(struct port *port, bool nonblock)
38110diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38111index a33f46f..a720eed 100644
38112--- a/drivers/clk/clk-composite.c
38113+++ b/drivers/clk/clk-composite.c
38114@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38115 struct clk *clk;
38116 struct clk_init_data init;
38117 struct clk_composite *composite;
38118- struct clk_ops *clk_composite_ops;
38119+ clk_ops_no_const *clk_composite_ops;
38120
38121 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38122 if (!composite) {
38123diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38124index 81dd31a..ef5c542 100644
38125--- a/drivers/clk/socfpga/clk.c
38126+++ b/drivers/clk/socfpga/clk.c
38127@@ -22,6 +22,7 @@
38128 #include <linux/clk-provider.h>
38129 #include <linux/io.h>
38130 #include <linux/of.h>
38131+#include <asm/pgtable.h>
38132
38133 /* Clock Manager offsets */
38134 #define CLKMGR_CTRL 0x0
38135@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38136 streq(clk_name, "periph_pll") ||
38137 streq(clk_name, "sdram_pll")) {
38138 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38139- clk_pll_ops.enable = clk_gate_ops.enable;
38140- clk_pll_ops.disable = clk_gate_ops.disable;
38141+ pax_open_kernel();
38142+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38143+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38144+ pax_close_kernel();
38145 }
38146
38147 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38148@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38149 return parent_rate / div;
38150 }
38151
38152-static struct clk_ops gateclk_ops = {
38153+static clk_ops_no_const gateclk_ops __read_only = {
38154 .recalc_rate = socfpga_clk_recalc_rate,
38155 .get_parent = socfpga_clk_get_parent,
38156 .set_parent = socfpga_clk_set_parent,
38157diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38158index caf41eb..223d27a 100644
38159--- a/drivers/cpufreq/acpi-cpufreq.c
38160+++ b/drivers/cpufreq/acpi-cpufreq.c
38161@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38162 return sprintf(buf, "%u\n", boost_enabled);
38163 }
38164
38165-static struct global_attr global_boost = __ATTR(boost, 0644,
38166+static global_attr_no_const global_boost = __ATTR(boost, 0644,
38167 show_global_boost,
38168 store_global_boost);
38169
38170@@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38171 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38172 per_cpu(acfreq_data, cpu) = data;
38173
38174- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38175- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38176+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38177+ pax_open_kernel();
38178+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38179+ pax_close_kernel();
38180+ }
38181
38182 result = acpi_processor_register_performance(data->acpi_data, cpu);
38183 if (result)
38184@@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38185 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38186 break;
38187 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38188- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38189+ pax_open_kernel();
38190+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38191+ pax_close_kernel();
38192 break;
38193 default:
38194 break;
38195diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38196index 8d19f7c..6bc2daa 100644
38197--- a/drivers/cpufreq/cpufreq.c
38198+++ b/drivers/cpufreq/cpufreq.c
38199@@ -1885,7 +1885,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38200 #endif
38201
38202 mutex_lock(&cpufreq_governor_mutex);
38203- list_del(&governor->governor_list);
38204+ pax_list_del(&governor->governor_list);
38205 mutex_unlock(&cpufreq_governor_mutex);
38206 return;
38207 }
38208@@ -2115,7 +2115,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38209 return NOTIFY_OK;
38210 }
38211
38212-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38213+static struct notifier_block cpufreq_cpu_notifier = {
38214 .notifier_call = cpufreq_cpu_callback,
38215 };
38216
38217@@ -2148,8 +2148,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38218
38219 pr_debug("trying to register driver %s\n", driver_data->name);
38220
38221- if (driver_data->setpolicy)
38222- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38223+ if (driver_data->setpolicy) {
38224+ pax_open_kernel();
38225+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38226+ pax_close_kernel();
38227+ }
38228
38229 write_lock_irqsave(&cpufreq_driver_lock, flags);
38230 if (cpufreq_driver) {
38231diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38232index e6be635..f8a90dc 100644
38233--- a/drivers/cpufreq/cpufreq_governor.c
38234+++ b/drivers/cpufreq/cpufreq_governor.c
38235@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38236 struct dbs_data *dbs_data;
38237 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38238 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38239- struct od_ops *od_ops = NULL;
38240+ const struct od_ops *od_ops = NULL;
38241 struct od_dbs_tuners *od_tuners = NULL;
38242 struct cs_dbs_tuners *cs_tuners = NULL;
38243 struct cpu_dbs_common_info *cpu_cdbs;
38244@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38245
38246 if ((cdata->governor == GOV_CONSERVATIVE) &&
38247 (!policy->governor->initialized)) {
38248- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38249+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38250
38251 cpufreq_register_notifier(cs_ops->notifier_block,
38252 CPUFREQ_TRANSITION_NOTIFIER);
38253@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38254
38255 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38256 (policy->governor->initialized == 1)) {
38257- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38258+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38259
38260 cpufreq_unregister_notifier(cs_ops->notifier_block,
38261 CPUFREQ_TRANSITION_NOTIFIER);
38262diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38263index b5f2b86..daa801b 100644
38264--- a/drivers/cpufreq/cpufreq_governor.h
38265+++ b/drivers/cpufreq/cpufreq_governor.h
38266@@ -205,7 +205,7 @@ struct common_dbs_data {
38267 void (*exit)(struct dbs_data *dbs_data);
38268
38269 /* Governor specific ops, see below */
38270- void *gov_ops;
38271+ const void *gov_ops;
38272 };
38273
38274 /* Governor Per policy data */
38275@@ -225,7 +225,7 @@ struct od_ops {
38276 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38277 unsigned int freq_next, unsigned int relation);
38278 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38279-};
38280+} __no_const;
38281
38282 struct cs_ops {
38283 struct notifier_block *notifier_block;
38284diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38285index 18d4091..434be15 100644
38286--- a/drivers/cpufreq/cpufreq_ondemand.c
38287+++ b/drivers/cpufreq/cpufreq_ondemand.c
38288@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38289
38290 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38291
38292-static struct od_ops od_ops = {
38293+static struct od_ops od_ops __read_only = {
38294 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38295 .powersave_bias_target = generic_powersave_bias_target,
38296 .freq_increase = dbs_freq_increase,
38297@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38298 (struct cpufreq_policy *, unsigned int, unsigned int),
38299 unsigned int powersave_bias)
38300 {
38301- od_ops.powersave_bias_target = f;
38302+ pax_open_kernel();
38303+ *(void **)&od_ops.powersave_bias_target = f;
38304+ pax_close_kernel();
38305 od_set_powersave_bias(powersave_bias);
38306 }
38307 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38308
38309 void od_unregister_powersave_bias_handler(void)
38310 {
38311- od_ops.powersave_bias_target = generic_powersave_bias_target;
38312+ pax_open_kernel();
38313+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38314+ pax_close_kernel();
38315 od_set_powersave_bias(0);
38316 }
38317 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38318diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38319index 4cf0d28..5830372 100644
38320--- a/drivers/cpufreq/cpufreq_stats.c
38321+++ b/drivers/cpufreq/cpufreq_stats.c
38322@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38323 }
38324
38325 /* priority=1 so this will get called before cpufreq_remove_dev */
38326-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38327+static struct notifier_block cpufreq_stat_cpu_notifier = {
38328 .notifier_call = cpufreq_stat_cpu_callback,
38329 .priority = 1,
38330 };
38331diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38332index d51f17ed..9f43b15 100644
38333--- a/drivers/cpufreq/intel_pstate.c
38334+++ b/drivers/cpufreq/intel_pstate.c
38335@@ -112,10 +112,10 @@ struct pstate_funcs {
38336 struct cpu_defaults {
38337 struct pstate_adjust_policy pid_policy;
38338 struct pstate_funcs funcs;
38339-};
38340+} __do_const;
38341
38342 static struct pstate_adjust_policy pid_params;
38343-static struct pstate_funcs pstate_funcs;
38344+static struct pstate_funcs *pstate_funcs;
38345
38346 struct perf_limits {
38347 int no_turbo;
38348@@ -462,7 +462,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38349
38350 cpu->pstate.current_pstate = pstate;
38351
38352- pstate_funcs.set(pstate);
38353+ pstate_funcs->set(pstate);
38354 }
38355
38356 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38357@@ -484,9 +484,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38358 {
38359 sprintf(cpu->name, "Intel 2nd generation core");
38360
38361- cpu->pstate.min_pstate = pstate_funcs.get_min();
38362- cpu->pstate.max_pstate = pstate_funcs.get_max();
38363- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
38364+ cpu->pstate.min_pstate = pstate_funcs->get_min();
38365+ cpu->pstate.max_pstate = pstate_funcs->get_max();
38366+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
38367
38368 /*
38369 * goto max pstate so we don't slow up boot if we are built-in if we are
38370@@ -750,9 +750,9 @@ static int intel_pstate_msrs_not_valid(void)
38371 rdmsrl(MSR_IA32_APERF, aperf);
38372 rdmsrl(MSR_IA32_MPERF, mperf);
38373
38374- if (!pstate_funcs.get_max() ||
38375- !pstate_funcs.get_min() ||
38376- !pstate_funcs.get_turbo())
38377+ if (!pstate_funcs->get_max() ||
38378+ !pstate_funcs->get_min() ||
38379+ !pstate_funcs->get_turbo())
38380 return -ENODEV;
38381
38382 rdmsrl(MSR_IA32_APERF, tmp);
38383@@ -766,7 +766,7 @@ static int intel_pstate_msrs_not_valid(void)
38384 return 0;
38385 }
38386
38387-static void copy_pid_params(struct pstate_adjust_policy *policy)
38388+static void copy_pid_params(const struct pstate_adjust_policy *policy)
38389 {
38390 pid_params.sample_rate_ms = policy->sample_rate_ms;
38391 pid_params.p_gain_pct = policy->p_gain_pct;
38392@@ -778,10 +778,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
38393
38394 static void copy_cpu_funcs(struct pstate_funcs *funcs)
38395 {
38396- pstate_funcs.get_max = funcs->get_max;
38397- pstate_funcs.get_min = funcs->get_min;
38398- pstate_funcs.get_turbo = funcs->get_turbo;
38399- pstate_funcs.set = funcs->set;
38400+ pstate_funcs = funcs;
38401 }
38402
38403 #if IS_ENABLED(CONFIG_ACPI)
38404diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
38405index 3d1cba9..0ab21d2 100644
38406--- a/drivers/cpufreq/p4-clockmod.c
38407+++ b/drivers/cpufreq/p4-clockmod.c
38408@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38409 case 0x0F: /* Core Duo */
38410 case 0x16: /* Celeron Core */
38411 case 0x1C: /* Atom */
38412- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38413+ pax_open_kernel();
38414+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38415+ pax_close_kernel();
38416 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
38417 case 0x0D: /* Pentium M (Dothan) */
38418- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38419+ pax_open_kernel();
38420+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38421+ pax_close_kernel();
38422 /* fall through */
38423 case 0x09: /* Pentium M (Banias) */
38424 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
38425@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38426
38427 /* on P-4s, the TSC runs with constant frequency independent whether
38428 * throttling is active or not. */
38429- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38430+ pax_open_kernel();
38431+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38432+ pax_close_kernel();
38433
38434 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
38435 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
38436diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
38437index 724ffbd..ad83692 100644
38438--- a/drivers/cpufreq/sparc-us3-cpufreq.c
38439+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
38440@@ -18,14 +18,12 @@
38441 #include <asm/head.h>
38442 #include <asm/timer.h>
38443
38444-static struct cpufreq_driver *cpufreq_us3_driver;
38445-
38446 struct us3_freq_percpu_info {
38447 struct cpufreq_frequency_table table[4];
38448 };
38449
38450 /* Indexed by cpu number. */
38451-static struct us3_freq_percpu_info *us3_freq_table;
38452+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
38453
38454 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
38455 * in the Safari config register.
38456@@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
38457
38458 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
38459 {
38460- if (cpufreq_us3_driver) {
38461- cpufreq_frequency_table_put_attr(policy->cpu);
38462- us3_freq_target(policy, 0);
38463- }
38464+ cpufreq_frequency_table_put_attr(policy->cpu);
38465+ us3_freq_target(policy, 0);
38466
38467 return 0;
38468 }
38469
38470+static int __init us3_freq_init(void);
38471+static void __exit us3_freq_exit(void);
38472+
38473+static struct cpufreq_driver cpufreq_us3_driver = {
38474+ .init = us3_freq_cpu_init,
38475+ .verify = cpufreq_generic_frequency_table_verify,
38476+ .target_index = us3_freq_target,
38477+ .get = us3_freq_get,
38478+ .exit = us3_freq_cpu_exit,
38479+ .owner = THIS_MODULE,
38480+ .name = "UltraSPARC-III",
38481+
38482+};
38483+
38484 static int __init us3_freq_init(void)
38485 {
38486 unsigned long manuf, impl, ver;
38487@@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
38488 (impl == CHEETAH_IMPL ||
38489 impl == CHEETAH_PLUS_IMPL ||
38490 impl == JAGUAR_IMPL ||
38491- impl == PANTHER_IMPL)) {
38492- struct cpufreq_driver *driver;
38493-
38494- ret = -ENOMEM;
38495- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
38496- if (!driver)
38497- goto err_out;
38498-
38499- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
38500- GFP_KERNEL);
38501- if (!us3_freq_table)
38502- goto err_out;
38503-
38504- driver->init = us3_freq_cpu_init;
38505- driver->verify = cpufreq_generic_frequency_table_verify;
38506- driver->target_index = us3_freq_target;
38507- driver->get = us3_freq_get;
38508- driver->exit = us3_freq_cpu_exit;
38509- strcpy(driver->name, "UltraSPARC-III");
38510-
38511- cpufreq_us3_driver = driver;
38512- ret = cpufreq_register_driver(driver);
38513- if (ret)
38514- goto err_out;
38515-
38516- return 0;
38517-
38518-err_out:
38519- if (driver) {
38520- kfree(driver);
38521- cpufreq_us3_driver = NULL;
38522- }
38523- kfree(us3_freq_table);
38524- us3_freq_table = NULL;
38525- return ret;
38526- }
38527+ impl == PANTHER_IMPL))
38528+ return cpufreq_register_driver(&cpufreq_us3_driver);
38529
38530 return -ENODEV;
38531 }
38532
38533 static void __exit us3_freq_exit(void)
38534 {
38535- if (cpufreq_us3_driver) {
38536- cpufreq_unregister_driver(cpufreq_us3_driver);
38537- kfree(cpufreq_us3_driver);
38538- cpufreq_us3_driver = NULL;
38539- kfree(us3_freq_table);
38540- us3_freq_table = NULL;
38541- }
38542+ cpufreq_unregister_driver(&cpufreq_us3_driver);
38543 }
38544
38545 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
38546diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
38547index 4e1daca..e707b61 100644
38548--- a/drivers/cpufreq/speedstep-centrino.c
38549+++ b/drivers/cpufreq/speedstep-centrino.c
38550@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
38551 !cpu_has(cpu, X86_FEATURE_EST))
38552 return -ENODEV;
38553
38554- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
38555- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38556+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
38557+ pax_open_kernel();
38558+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38559+ pax_close_kernel();
38560+ }
38561
38562 if (policy->cpu != 0)
38563 return -ENODEV;
38564diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
38565index 06dbe7c..c2c8671 100644
38566--- a/drivers/cpuidle/driver.c
38567+++ b/drivers/cpuidle/driver.c
38568@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
38569
38570 static void poll_idle_init(struct cpuidle_driver *drv)
38571 {
38572- struct cpuidle_state *state = &drv->states[0];
38573+ cpuidle_state_no_const *state = &drv->states[0];
38574
38575 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38576 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38577diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38578index ca89412..a7b9c49 100644
38579--- a/drivers/cpuidle/governor.c
38580+++ b/drivers/cpuidle/governor.c
38581@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38582 mutex_lock(&cpuidle_lock);
38583 if (__cpuidle_find_governor(gov->name) == NULL) {
38584 ret = 0;
38585- list_add_tail(&gov->governor_list, &cpuidle_governors);
38586+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38587 if (!cpuidle_curr_governor ||
38588 cpuidle_curr_governor->rating < gov->rating)
38589 cpuidle_switch_governor(gov);
38590diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38591index e918b6d..f87ea80 100644
38592--- a/drivers/cpuidle/sysfs.c
38593+++ b/drivers/cpuidle/sysfs.c
38594@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38595 NULL
38596 };
38597
38598-static struct attribute_group cpuidle_attr_group = {
38599+static attribute_group_no_const cpuidle_attr_group = {
38600 .attrs = cpuidle_default_attrs,
38601 .name = "cpuidle",
38602 };
38603diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38604index 12fea3e..1e28f47 100644
38605--- a/drivers/crypto/hifn_795x.c
38606+++ b/drivers/crypto/hifn_795x.c
38607@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38608 MODULE_PARM_DESC(hifn_pll_ref,
38609 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38610
38611-static atomic_t hifn_dev_number;
38612+static atomic_unchecked_t hifn_dev_number;
38613
38614 #define ACRYPTO_OP_DECRYPT 0
38615 #define ACRYPTO_OP_ENCRYPT 1
38616@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38617 goto err_out_disable_pci_device;
38618
38619 snprintf(name, sizeof(name), "hifn%d",
38620- atomic_inc_return(&hifn_dev_number)-1);
38621+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
38622
38623 err = pci_request_regions(pdev, name);
38624 if (err)
38625diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38626index a0b2f7e..1b6f028 100644
38627--- a/drivers/devfreq/devfreq.c
38628+++ b/drivers/devfreq/devfreq.c
38629@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38630 goto err_out;
38631 }
38632
38633- list_add(&governor->node, &devfreq_governor_list);
38634+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38635
38636 list_for_each_entry(devfreq, &devfreq_list, node) {
38637 int ret = 0;
38638@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38639 }
38640 }
38641
38642- list_del(&governor->node);
38643+ pax_list_del((struct list_head *)&governor->node);
38644 err_out:
38645 mutex_unlock(&devfreq_list_lock);
38646
38647diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
38648index 0d765c0..60b7480 100644
38649--- a/drivers/dma/sh/shdmac.c
38650+++ b/drivers/dma/sh/shdmac.c
38651@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38652 return ret;
38653 }
38654
38655-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38656+static struct notifier_block sh_dmae_nmi_notifier = {
38657 .notifier_call = sh_dmae_nmi_handler,
38658
38659 /* Run before NMI debug handler and KGDB */
38660diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38661index 1026743..80b081c 100644
38662--- a/drivers/edac/edac_device.c
38663+++ b/drivers/edac/edac_device.c
38664@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38665 */
38666 int edac_device_alloc_index(void)
38667 {
38668- static atomic_t device_indexes = ATOMIC_INIT(0);
38669+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38670
38671- return atomic_inc_return(&device_indexes) - 1;
38672+ return atomic_inc_return_unchecked(&device_indexes) - 1;
38673 }
38674 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38675
38676diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38677index 9f7e0e60..348c875 100644
38678--- a/drivers/edac/edac_mc_sysfs.c
38679+++ b/drivers/edac/edac_mc_sysfs.c
38680@@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
38681 struct dev_ch_attribute {
38682 struct device_attribute attr;
38683 int channel;
38684-};
38685+} __do_const;
38686
38687 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38688 struct dev_ch_attribute dev_attr_legacy_##_name = \
38689@@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38690 }
38691
38692 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38693+ pax_open_kernel();
38694 if (mci->get_sdram_scrub_rate) {
38695- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38696- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38697+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38698+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38699 }
38700 if (mci->set_sdram_scrub_rate) {
38701- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38702- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38703+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38704+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38705 }
38706+ pax_close_kernel();
38707 err = device_create_file(&mci->dev,
38708 &dev_attr_sdram_scrub_rate);
38709 if (err) {
38710diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38711index 2cf44b4d..6dd2dc7 100644
38712--- a/drivers/edac/edac_pci.c
38713+++ b/drivers/edac/edac_pci.c
38714@@ -29,7 +29,7 @@
38715
38716 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38717 static LIST_HEAD(edac_pci_list);
38718-static atomic_t pci_indexes = ATOMIC_INIT(0);
38719+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38720
38721 /*
38722 * edac_pci_alloc_ctl_info
38723@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38724 */
38725 int edac_pci_alloc_index(void)
38726 {
38727- return atomic_inc_return(&pci_indexes) - 1;
38728+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
38729 }
38730 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38731
38732diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38733index e8658e4..22746d6 100644
38734--- a/drivers/edac/edac_pci_sysfs.c
38735+++ b/drivers/edac/edac_pci_sysfs.c
38736@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38737 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38738 static int edac_pci_poll_msec = 1000; /* one second workq period */
38739
38740-static atomic_t pci_parity_count = ATOMIC_INIT(0);
38741-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38742+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38743+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38744
38745 static struct kobject *edac_pci_top_main_kobj;
38746 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38747@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38748 void *value;
38749 ssize_t(*show) (void *, char *);
38750 ssize_t(*store) (void *, const char *, size_t);
38751-};
38752+} __do_const;
38753
38754 /* Set of show/store abstract level functions for PCI Parity object */
38755 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38756@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38757 edac_printk(KERN_CRIT, EDAC_PCI,
38758 "Signaled System Error on %s\n",
38759 pci_name(dev));
38760- atomic_inc(&pci_nonparity_count);
38761+ atomic_inc_unchecked(&pci_nonparity_count);
38762 }
38763
38764 if (status & (PCI_STATUS_PARITY)) {
38765@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38766 "Master Data Parity Error on %s\n",
38767 pci_name(dev));
38768
38769- atomic_inc(&pci_parity_count);
38770+ atomic_inc_unchecked(&pci_parity_count);
38771 }
38772
38773 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38774@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38775 "Detected Parity Error on %s\n",
38776 pci_name(dev));
38777
38778- atomic_inc(&pci_parity_count);
38779+ atomic_inc_unchecked(&pci_parity_count);
38780 }
38781 }
38782
38783@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38784 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38785 "Signaled System Error on %s\n",
38786 pci_name(dev));
38787- atomic_inc(&pci_nonparity_count);
38788+ atomic_inc_unchecked(&pci_nonparity_count);
38789 }
38790
38791 if (status & (PCI_STATUS_PARITY)) {
38792@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38793 "Master Data Parity Error on "
38794 "%s\n", pci_name(dev));
38795
38796- atomic_inc(&pci_parity_count);
38797+ atomic_inc_unchecked(&pci_parity_count);
38798 }
38799
38800 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38801@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38802 "Detected Parity Error on %s\n",
38803 pci_name(dev));
38804
38805- atomic_inc(&pci_parity_count);
38806+ atomic_inc_unchecked(&pci_parity_count);
38807 }
38808 }
38809 }
38810@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38811 if (!check_pci_errors)
38812 return;
38813
38814- before_count = atomic_read(&pci_parity_count);
38815+ before_count = atomic_read_unchecked(&pci_parity_count);
38816
38817 /* scan all PCI devices looking for a Parity Error on devices and
38818 * bridges.
38819@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38820 /* Only if operator has selected panic on PCI Error */
38821 if (edac_pci_get_panic_on_pe()) {
38822 /* If the count is different 'after' from 'before' */
38823- if (before_count != atomic_read(&pci_parity_count))
38824+ if (before_count != atomic_read_unchecked(&pci_parity_count))
38825 panic("EDAC: PCI Parity Error");
38826 }
38827 }
38828diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38829index 51b7e3a..aa8a3e8 100644
38830--- a/drivers/edac/mce_amd.h
38831+++ b/drivers/edac/mce_amd.h
38832@@ -77,7 +77,7 @@ struct amd_decoder_ops {
38833 bool (*mc0_mce)(u16, u8);
38834 bool (*mc1_mce)(u16, u8);
38835 bool (*mc2_mce)(u16, u8);
38836-};
38837+} __no_const;
38838
38839 void amd_report_gart_errors(bool);
38840 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38841diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38842index 57ea7f4..af06b76 100644
38843--- a/drivers/firewire/core-card.c
38844+++ b/drivers/firewire/core-card.c
38845@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38846 const struct fw_card_driver *driver,
38847 struct device *device)
38848 {
38849- static atomic_t index = ATOMIC_INIT(-1);
38850+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
38851
38852- card->index = atomic_inc_return(&index);
38853+ card->index = atomic_inc_return_unchecked(&index);
38854 card->driver = driver;
38855 card->device = device;
38856 card->current_tlabel = 0;
38857@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38858
38859 void fw_core_remove_card(struct fw_card *card)
38860 {
38861- struct fw_card_driver dummy_driver = dummy_driver_template;
38862+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
38863
38864 card->driver->update_phy_reg(card, 4,
38865 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38866diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38867index de4aa40..49ab1f2 100644
38868--- a/drivers/firewire/core-device.c
38869+++ b/drivers/firewire/core-device.c
38870@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38871 struct config_rom_attribute {
38872 struct device_attribute attr;
38873 u32 key;
38874-};
38875+} __do_const;
38876
38877 static ssize_t show_immediate(struct device *dev,
38878 struct device_attribute *dattr, char *buf)
38879diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38880index 0e79951..b180217 100644
38881--- a/drivers/firewire/core-transaction.c
38882+++ b/drivers/firewire/core-transaction.c
38883@@ -38,6 +38,7 @@
38884 #include <linux/timer.h>
38885 #include <linux/types.h>
38886 #include <linux/workqueue.h>
38887+#include <linux/sched.h>
38888
38889 #include <asm/byteorder.h>
38890
38891diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38892index 515a42c..5ecf3ba 100644
38893--- a/drivers/firewire/core.h
38894+++ b/drivers/firewire/core.h
38895@@ -111,6 +111,7 @@ struct fw_card_driver {
38896
38897 int (*stop_iso)(struct fw_iso_context *ctx);
38898 };
38899+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38900
38901 void fw_card_initialize(struct fw_card *card,
38902 const struct fw_card_driver *driver, struct device *device);
38903diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38904index 94a58a0..f5eba42 100644
38905--- a/drivers/firmware/dmi-id.c
38906+++ b/drivers/firmware/dmi-id.c
38907@@ -16,7 +16,7 @@
38908 struct dmi_device_attribute{
38909 struct device_attribute dev_attr;
38910 int field;
38911-};
38912+} __do_const;
38913 #define to_dmi_dev_attr(_dev_attr) \
38914 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38915
38916diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38917index c7e81ff..94a7401 100644
38918--- a/drivers/firmware/dmi_scan.c
38919+++ b/drivers/firmware/dmi_scan.c
38920@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38921 if (buf == NULL)
38922 return -1;
38923
38924- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38925+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38926
38927 iounmap(buf);
38928 return 0;
38929diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
38930index 1491dd4..aa910db 100644
38931--- a/drivers/firmware/efi/cper.c
38932+++ b/drivers/firmware/efi/cper.c
38933@@ -41,12 +41,12 @@
38934 */
38935 u64 cper_next_record_id(void)
38936 {
38937- static atomic64_t seq;
38938+ static atomic64_unchecked_t seq;
38939
38940- if (!atomic64_read(&seq))
38941- atomic64_set(&seq, ((u64)get_seconds()) << 32);
38942+ if (!atomic64_read_unchecked(&seq))
38943+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
38944
38945- return atomic64_inc_return(&seq);
38946+ return atomic64_inc_return_unchecked(&seq);
38947 }
38948 EXPORT_SYMBOL_GPL(cper_next_record_id);
38949
38950diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38951index 2e2fbde..7676c8b 100644
38952--- a/drivers/firmware/efi/efi.c
38953+++ b/drivers/firmware/efi/efi.c
38954@@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
38955 };
38956
38957 static struct efivars generic_efivars;
38958-static struct efivar_operations generic_ops;
38959+static efivar_operations_no_const generic_ops __read_only;
38960
38961 static int generic_ops_register(void)
38962 {
38963- generic_ops.get_variable = efi.get_variable;
38964- generic_ops.set_variable = efi.set_variable;
38965- generic_ops.get_next_variable = efi.get_next_variable;
38966- generic_ops.query_variable_store = efi_query_variable_store;
38967+ pax_open_kernel();
38968+ *(void **)&generic_ops.get_variable = efi.get_variable;
38969+ *(void **)&generic_ops.set_variable = efi.set_variable;
38970+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38971+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38972+ pax_close_kernel();
38973
38974 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38975 }
38976diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38977index 3dc2482..7bd2f61 100644
38978--- a/drivers/firmware/efi/efivars.c
38979+++ b/drivers/firmware/efi/efivars.c
38980@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38981 static int
38982 create_efivars_bin_attributes(void)
38983 {
38984- struct bin_attribute *attr;
38985+ bin_attribute_no_const *attr;
38986 int error;
38987
38988 /* new_var */
38989diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38990index 2a90ba6..07f3733 100644
38991--- a/drivers/firmware/google/memconsole.c
38992+++ b/drivers/firmware/google/memconsole.c
38993@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
38994 if (!found_memconsole())
38995 return -ENODEV;
38996
38997- memconsole_bin_attr.size = memconsole_length;
38998+ pax_open_kernel();
38999+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39000+ pax_close_kernel();
39001
39002 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39003
39004diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39005index 814addb..0937d7f 100644
39006--- a/drivers/gpio/gpio-ich.c
39007+++ b/drivers/gpio/gpio-ich.c
39008@@ -71,7 +71,7 @@ struct ichx_desc {
39009 /* Some chipsets have quirks, let these use their own request/get */
39010 int (*request)(struct gpio_chip *chip, unsigned offset);
39011 int (*get)(struct gpio_chip *chip, unsigned offset);
39012-};
39013+} __do_const;
39014
39015 static struct {
39016 spinlock_t lock;
39017diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39018index 9902732..64b62dd 100644
39019--- a/drivers/gpio/gpio-vr41xx.c
39020+++ b/drivers/gpio/gpio-vr41xx.c
39021@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39022 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39023 maskl, pendl, maskh, pendh);
39024
39025- atomic_inc(&irq_err_count);
39026+ atomic_inc_unchecked(&irq_err_count);
39027
39028 return -EINVAL;
39029 }
39030diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39031index d6cf77c..2842146 100644
39032--- a/drivers/gpu/drm/drm_crtc.c
39033+++ b/drivers/gpu/drm/drm_crtc.c
39034@@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39035 goto done;
39036 }
39037
39038- if (copy_to_user(&enum_ptr[copied].name,
39039+ if (copy_to_user(enum_ptr[copied].name,
39040 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39041 ret = -EFAULT;
39042 goto done;
39043diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39044index 01361ab..891e821 100644
39045--- a/drivers/gpu/drm/drm_crtc_helper.c
39046+++ b/drivers/gpu/drm/drm_crtc_helper.c
39047@@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39048 struct drm_crtc *tmp;
39049 int crtc_mask = 1;
39050
39051- WARN(!crtc, "checking null crtc?\n");
39052+ BUG_ON(!crtc);
39053
39054 dev = crtc->dev;
39055
39056diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39057index d9137e4..69b73a0 100644
39058--- a/drivers/gpu/drm/drm_drv.c
39059+++ b/drivers/gpu/drm/drm_drv.c
39060@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39061 /**
39062 * Copy and IOCTL return string to user space
39063 */
39064-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39065+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39066 {
39067 int len;
39068
39069@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39070 struct drm_file *file_priv = filp->private_data;
39071 struct drm_device *dev;
39072 const struct drm_ioctl_desc *ioctl = NULL;
39073- drm_ioctl_t *func;
39074+ drm_ioctl_no_const_t func;
39075 unsigned int nr = DRM_IOCTL_NR(cmd);
39076 int retcode = -EINVAL;
39077 char stack_kdata[128];
39078diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39079index c5b929c..8a3b8be 100644
39080--- a/drivers/gpu/drm/drm_fops.c
39081+++ b/drivers/gpu/drm/drm_fops.c
39082@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39083 if (drm_device_is_unplugged(dev))
39084 return -ENODEV;
39085
39086- if (!dev->open_count++)
39087+ if (local_inc_return(&dev->open_count) == 1)
39088 need_setup = 1;
39089 mutex_lock(&dev->struct_mutex);
39090 old_imapping = inode->i_mapping;
39091@@ -127,7 +127,7 @@ err_undo:
39092 iput(container_of(dev->dev_mapping, struct inode, i_data));
39093 dev->dev_mapping = old_mapping;
39094 mutex_unlock(&dev->struct_mutex);
39095- dev->open_count--;
39096+ local_dec(&dev->open_count);
39097 return retcode;
39098 }
39099 EXPORT_SYMBOL(drm_open);
39100@@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39101
39102 mutex_lock(&drm_global_mutex);
39103
39104- DRM_DEBUG("open_count = %d\n", dev->open_count);
39105+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39106
39107 if (dev->driver->preclose)
39108 dev->driver->preclose(dev, file_priv);
39109@@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39110 * Begin inline drm_release
39111 */
39112
39113- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39114+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39115 task_pid_nr(current),
39116 (long)old_encode_dev(file_priv->minor->device),
39117- dev->open_count);
39118+ local_read(&dev->open_count));
39119
39120 /* Release any auth tokens that might point to this file_priv,
39121 (do that under the drm_global_mutex) */
39122@@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39123 * End inline drm_release
39124 */
39125
39126- if (!--dev->open_count) {
39127+ if (local_dec_and_test(&dev->open_count)) {
39128 if (atomic_read(&dev->ioctl_count)) {
39129 DRM_ERROR("Device busy: %d\n",
39130 atomic_read(&dev->ioctl_count));
39131diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39132index 3d2e91c..d31c4c9 100644
39133--- a/drivers/gpu/drm/drm_global.c
39134+++ b/drivers/gpu/drm/drm_global.c
39135@@ -36,7 +36,7 @@
39136 struct drm_global_item {
39137 struct mutex mutex;
39138 void *object;
39139- int refcount;
39140+ atomic_t refcount;
39141 };
39142
39143 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39144@@ -49,7 +49,7 @@ void drm_global_init(void)
39145 struct drm_global_item *item = &glob[i];
39146 mutex_init(&item->mutex);
39147 item->object = NULL;
39148- item->refcount = 0;
39149+ atomic_set(&item->refcount, 0);
39150 }
39151 }
39152
39153@@ -59,7 +59,7 @@ void drm_global_release(void)
39154 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39155 struct drm_global_item *item = &glob[i];
39156 BUG_ON(item->object != NULL);
39157- BUG_ON(item->refcount != 0);
39158+ BUG_ON(atomic_read(&item->refcount) != 0);
39159 }
39160 }
39161
39162@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39163 struct drm_global_item *item = &glob[ref->global_type];
39164
39165 mutex_lock(&item->mutex);
39166- if (item->refcount == 0) {
39167+ if (atomic_read(&item->refcount) == 0) {
39168 item->object = kzalloc(ref->size, GFP_KERNEL);
39169 if (unlikely(item->object == NULL)) {
39170 ret = -ENOMEM;
39171@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39172 goto out_err;
39173
39174 }
39175- ++item->refcount;
39176+ atomic_inc(&item->refcount);
39177 ref->object = item->object;
39178 mutex_unlock(&item->mutex);
39179 return 0;
39180@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39181 struct drm_global_item *item = &glob[ref->global_type];
39182
39183 mutex_lock(&item->mutex);
39184- BUG_ON(item->refcount == 0);
39185+ BUG_ON(atomic_read(&item->refcount) == 0);
39186 BUG_ON(ref->object != item->object);
39187- if (--item->refcount == 0) {
39188+ if (atomic_dec_and_test(&item->refcount)) {
39189 ref->release(ref);
39190 item->object = NULL;
39191 }
39192diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39193index 7d5a152..d7186da 100644
39194--- a/drivers/gpu/drm/drm_info.c
39195+++ b/drivers/gpu/drm/drm_info.c
39196@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39197 struct drm_local_map *map;
39198 struct drm_map_list *r_list;
39199
39200- /* Hardcoded from _DRM_FRAME_BUFFER,
39201- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39202- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39203- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39204+ static const char * const types[] = {
39205+ [_DRM_FRAME_BUFFER] = "FB",
39206+ [_DRM_REGISTERS] = "REG",
39207+ [_DRM_SHM] = "SHM",
39208+ [_DRM_AGP] = "AGP",
39209+ [_DRM_SCATTER_GATHER] = "SG",
39210+ [_DRM_CONSISTENT] = "PCI",
39211+ [_DRM_GEM] = "GEM" };
39212 const char *type;
39213 int i;
39214
39215@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39216 map = r_list->map;
39217 if (!map)
39218 continue;
39219- if (map->type < 0 || map->type > 5)
39220+ if (map->type >= ARRAY_SIZE(types))
39221 type = "??";
39222 else
39223 type = types[map->type];
39224@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39225 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39226 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39227 vma->vm_flags & VM_IO ? 'i' : '-',
39228+#ifdef CONFIG_GRKERNSEC_HIDESYM
39229+ 0);
39230+#else
39231 vma->vm_pgoff);
39232+#endif
39233
39234 #if defined(__i386__)
39235 pgprot = pgprot_val(vma->vm_page_prot);
39236diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39237index 2f4c434..dd12cd2 100644
39238--- a/drivers/gpu/drm/drm_ioc32.c
39239+++ b/drivers/gpu/drm/drm_ioc32.c
39240@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39241 request = compat_alloc_user_space(nbytes);
39242 if (!access_ok(VERIFY_WRITE, request, nbytes))
39243 return -EFAULT;
39244- list = (struct drm_buf_desc *) (request + 1);
39245+ list = (struct drm_buf_desc __user *) (request + 1);
39246
39247 if (__put_user(count, &request->count)
39248 || __put_user(list, &request->list))
39249@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39250 request = compat_alloc_user_space(nbytes);
39251 if (!access_ok(VERIFY_WRITE, request, nbytes))
39252 return -EFAULT;
39253- list = (struct drm_buf_pub *) (request + 1);
39254+ list = (struct drm_buf_pub __user *) (request + 1);
39255
39256 if (__put_user(count, &request->count)
39257 || __put_user(list, &request->list))
39258@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39259 return 0;
39260 }
39261
39262-drm_ioctl_compat_t *drm_compat_ioctls[] = {
39263+drm_ioctl_compat_t drm_compat_ioctls[] = {
39264 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39265 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39266 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39267@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39268 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39269 {
39270 unsigned int nr = DRM_IOCTL_NR(cmd);
39271- drm_ioctl_compat_t *fn;
39272 int ret;
39273
39274 /* Assume that ioctls without an explicit compat routine will just
39275@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39276 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39277 return drm_ioctl(filp, cmd, arg);
39278
39279- fn = drm_compat_ioctls[nr];
39280-
39281- if (fn != NULL)
39282- ret = (*fn) (filp, cmd, arg);
39283+ if (drm_compat_ioctls[nr] != NULL)
39284+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39285 else
39286 ret = drm_ioctl(filp, cmd, arg);
39287
39288diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39289index 66dd3a0..3bed6c4 100644
39290--- a/drivers/gpu/drm/drm_stub.c
39291+++ b/drivers/gpu/drm/drm_stub.c
39292@@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39293
39294 drm_device_set_unplugged(dev);
39295
39296- if (dev->open_count == 0) {
39297+ if (local_read(&dev->open_count) == 0) {
39298 drm_put_dev(dev);
39299 }
39300 mutex_unlock(&drm_global_mutex);
39301diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39302index c22c309..ae758c3 100644
39303--- a/drivers/gpu/drm/drm_sysfs.c
39304+++ b/drivers/gpu/drm/drm_sysfs.c
39305@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39306 */
39307 int drm_sysfs_device_add(struct drm_minor *minor)
39308 {
39309- char *minor_str;
39310+ const char *minor_str;
39311 int r;
39312
39313 if (minor->type == DRM_MINOR_CONTROL)
39314diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39315index d4d16ed..8fb0b51 100644
39316--- a/drivers/gpu/drm/i810/i810_drv.h
39317+++ b/drivers/gpu/drm/i810/i810_drv.h
39318@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39319 int page_flipping;
39320
39321 wait_queue_head_t irq_queue;
39322- atomic_t irq_received;
39323- atomic_t irq_emitted;
39324+ atomic_unchecked_t irq_received;
39325+ atomic_unchecked_t irq_emitted;
39326
39327 int front_offset;
39328 } drm_i810_private_t;
39329diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
39330index 6ed45a9..eb6dc41 100644
39331--- a/drivers/gpu/drm/i915/i915_debugfs.c
39332+++ b/drivers/gpu/drm/i915/i915_debugfs.c
39333@@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
39334 I915_READ(GTIMR));
39335 }
39336 seq_printf(m, "Interrupts received: %d\n",
39337- atomic_read(&dev_priv->irq_received));
39338+ atomic_read_unchecked(&dev_priv->irq_received));
39339 for_each_ring(ring, dev_priv, i) {
39340 if (INTEL_INFO(dev)->gen >= 6) {
39341 seq_printf(m,
39342diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
39343index 5c64842..f14bdf8 100644
39344--- a/drivers/gpu/drm/i915/i915_dma.c
39345+++ b/drivers/gpu/drm/i915/i915_dma.c
39346@@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
39347 bool can_switch;
39348
39349 spin_lock(&dev->count_lock);
39350- can_switch = (dev->open_count == 0);
39351+ can_switch = (local_read(&dev->open_count) == 0);
39352 spin_unlock(&dev->count_lock);
39353 return can_switch;
39354 }
39355diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
39356index 90fcccb..b8aabc9 100644
39357--- a/drivers/gpu/drm/i915/i915_drv.h
39358+++ b/drivers/gpu/drm/i915/i915_drv.h
39359@@ -1325,7 +1325,7 @@ typedef struct drm_i915_private {
39360 drm_dma_handle_t *status_page_dmah;
39361 struct resource mch_res;
39362
39363- atomic_t irq_received;
39364+ atomic_unchecked_t irq_received;
39365
39366 /* protects the irq masks */
39367 spinlock_t irq_lock;
39368diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39369index a3ba9a8..ee52ddd 100644
39370--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39371+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39372@@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
39373
39374 static int
39375 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
39376- int count)
39377+ unsigned int count)
39378 {
39379- int i;
39380+ unsigned int i;
39381 unsigned relocs_total = 0;
39382 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
39383
39384diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
39385index 3c59584..500f2e9 100644
39386--- a/drivers/gpu/drm/i915/i915_ioc32.c
39387+++ b/drivers/gpu/drm/i915/i915_ioc32.c
39388@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
39389 (unsigned long)request);
39390 }
39391
39392-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39393+static drm_ioctl_compat_t i915_compat_ioctls[] = {
39394 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
39395 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
39396 [DRM_I915_GETPARAM] = compat_i915_getparam,
39397@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39398 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39399 {
39400 unsigned int nr = DRM_IOCTL_NR(cmd);
39401- drm_ioctl_compat_t *fn = NULL;
39402 int ret;
39403
39404 if (nr < DRM_COMMAND_BASE)
39405 return drm_compat_ioctl(filp, cmd, arg);
39406
39407- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
39408- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39409-
39410- if (fn != NULL)
39411+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
39412+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39413 ret = (*fn) (filp, cmd, arg);
39414- else
39415+ } else
39416 ret = drm_ioctl(filp, cmd, arg);
39417
39418 return ret;
39419diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
39420index f13d5ed..8e6f36d 100644
39421--- a/drivers/gpu/drm/i915/i915_irq.c
39422+++ b/drivers/gpu/drm/i915/i915_irq.c
39423@@ -1420,7 +1420,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
39424 int pipe;
39425 u32 pipe_stats[I915_MAX_PIPES];
39426
39427- atomic_inc(&dev_priv->irq_received);
39428+ atomic_inc_unchecked(&dev_priv->irq_received);
39429
39430 while (true) {
39431 iir = I915_READ(VLV_IIR);
39432@@ -1730,7 +1730,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
39433 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
39434 irqreturn_t ret = IRQ_NONE;
39435
39436- atomic_inc(&dev_priv->irq_received);
39437+ atomic_inc_unchecked(&dev_priv->irq_received);
39438
39439 /* We get interrupts on unclaimed registers, so check for this before we
39440 * do any I915_{READ,WRITE}. */
39441@@ -1800,7 +1800,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
39442 uint32_t tmp = 0;
39443 enum pipe pipe;
39444
39445- atomic_inc(&dev_priv->irq_received);
39446+ atomic_inc_unchecked(&dev_priv->irq_received);
39447
39448 master_ctl = I915_READ(GEN8_MASTER_IRQ);
39449 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
39450@@ -2624,7 +2624,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
39451 {
39452 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39453
39454- atomic_set(&dev_priv->irq_received, 0);
39455+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39456
39457 I915_WRITE(HWSTAM, 0xeffe);
39458
39459@@ -2642,7 +2642,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
39460 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39461 int pipe;
39462
39463- atomic_set(&dev_priv->irq_received, 0);
39464+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39465
39466 /* VLV magic */
39467 I915_WRITE(VLV_IMR, 0);
39468@@ -2673,7 +2673,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
39469 struct drm_i915_private *dev_priv = dev->dev_private;
39470 int pipe;
39471
39472- atomic_set(&dev_priv->irq_received, 0);
39473+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39474
39475 I915_WRITE(GEN8_MASTER_IRQ, 0);
39476 POSTING_READ(GEN8_MASTER_IRQ);
39477@@ -2999,7 +2999,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
39478 if (!dev_priv)
39479 return;
39480
39481- atomic_set(&dev_priv->irq_received, 0);
39482+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39483
39484 I915_WRITE(GEN8_MASTER_IRQ, 0);
39485
39486@@ -3093,7 +3093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39487 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39488 int pipe;
39489
39490- atomic_set(&dev_priv->irq_received, 0);
39491+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39492
39493 for_each_pipe(pipe)
39494 I915_WRITE(PIPESTAT(pipe), 0);
39495@@ -3179,7 +3179,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39496 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39497 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39498
39499- atomic_inc(&dev_priv->irq_received);
39500+ atomic_inc_unchecked(&dev_priv->irq_received);
39501
39502 iir = I915_READ16(IIR);
39503 if (iir == 0)
39504@@ -3254,7 +3254,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39505 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39506 int pipe;
39507
39508- atomic_set(&dev_priv->irq_received, 0);
39509+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39510
39511 if (I915_HAS_HOTPLUG(dev)) {
39512 I915_WRITE(PORT_HOTPLUG_EN, 0);
39513@@ -3361,7 +3361,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39514 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39515 int pipe, ret = IRQ_NONE;
39516
39517- atomic_inc(&dev_priv->irq_received);
39518+ atomic_inc_unchecked(&dev_priv->irq_received);
39519
39520 iir = I915_READ(IIR);
39521 do {
39522@@ -3488,7 +3488,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39523 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39524 int pipe;
39525
39526- atomic_set(&dev_priv->irq_received, 0);
39527+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39528
39529 I915_WRITE(PORT_HOTPLUG_EN, 0);
39530 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39531@@ -3604,7 +3604,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39532 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39533 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39534
39535- atomic_inc(&dev_priv->irq_received);
39536+ atomic_inc_unchecked(&dev_priv->irq_received);
39537
39538 iir = I915_READ(IIR);
39539
39540diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39541index 2bde35d..529646c 100644
39542--- a/drivers/gpu/drm/i915/intel_display.c
39543+++ b/drivers/gpu/drm/i915/intel_display.c
39544@@ -10492,13 +10492,13 @@ struct intel_quirk {
39545 int subsystem_vendor;
39546 int subsystem_device;
39547 void (*hook)(struct drm_device *dev);
39548-};
39549+} __do_const;
39550
39551 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39552 struct intel_dmi_quirk {
39553 void (*hook)(struct drm_device *dev);
39554 const struct dmi_system_id (*dmi_id_list)[];
39555-};
39556+} __do_const;
39557
39558 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39559 {
39560@@ -10506,18 +10506,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39561 return 1;
39562 }
39563
39564-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39565+static const struct dmi_system_id intel_dmi_quirks_table[] = {
39566 {
39567- .dmi_id_list = &(const struct dmi_system_id[]) {
39568- {
39569- .callback = intel_dmi_reverse_brightness,
39570- .ident = "NCR Corporation",
39571- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39572- DMI_MATCH(DMI_PRODUCT_NAME, ""),
39573- },
39574- },
39575- { } /* terminating entry */
39576+ .callback = intel_dmi_reverse_brightness,
39577+ .ident = "NCR Corporation",
39578+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39579+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
39580 },
39581+ },
39582+ { } /* terminating entry */
39583+};
39584+
39585+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39586+ {
39587+ .dmi_id_list = &intel_dmi_quirks_table,
39588 .hook = quirk_invert_brightness,
39589 },
39590 };
39591diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39592index ca4bc54..ee598a2 100644
39593--- a/drivers/gpu/drm/mga/mga_drv.h
39594+++ b/drivers/gpu/drm/mga/mga_drv.h
39595@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39596 u32 clear_cmd;
39597 u32 maccess;
39598
39599- atomic_t vbl_received; /**< Number of vblanks received. */
39600+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39601 wait_queue_head_t fence_queue;
39602- atomic_t last_fence_retired;
39603+ atomic_unchecked_t last_fence_retired;
39604 u32 next_fence_to_post;
39605
39606 unsigned int fb_cpp;
39607diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39608index 709e90d..89a1c0d 100644
39609--- a/drivers/gpu/drm/mga/mga_ioc32.c
39610+++ b/drivers/gpu/drm/mga/mga_ioc32.c
39611@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39612 return 0;
39613 }
39614
39615-drm_ioctl_compat_t *mga_compat_ioctls[] = {
39616+drm_ioctl_compat_t mga_compat_ioctls[] = {
39617 [DRM_MGA_INIT] = compat_mga_init,
39618 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39619 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39620@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39621 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39622 {
39623 unsigned int nr = DRM_IOCTL_NR(cmd);
39624- drm_ioctl_compat_t *fn = NULL;
39625 int ret;
39626
39627 if (nr < DRM_COMMAND_BASE)
39628 return drm_compat_ioctl(filp, cmd, arg);
39629
39630- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39631- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39632-
39633- if (fn != NULL)
39634+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39635+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39636 ret = (*fn) (filp, cmd, arg);
39637- else
39638+ } else
39639 ret = drm_ioctl(filp, cmd, arg);
39640
39641 return ret;
39642diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39643index 2b0ceb8..517e99e 100644
39644--- a/drivers/gpu/drm/mga/mga_irq.c
39645+++ b/drivers/gpu/drm/mga/mga_irq.c
39646@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39647 if (crtc != 0)
39648 return 0;
39649
39650- return atomic_read(&dev_priv->vbl_received);
39651+ return atomic_read_unchecked(&dev_priv->vbl_received);
39652 }
39653
39654
39655@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39656 /* VBLANK interrupt */
39657 if (status & MGA_VLINEPEN) {
39658 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39659- atomic_inc(&dev_priv->vbl_received);
39660+ atomic_inc_unchecked(&dev_priv->vbl_received);
39661 drm_handle_vblank(dev, 0);
39662 handled = 1;
39663 }
39664@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39665 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39666 MGA_WRITE(MGA_PRIMEND, prim_end);
39667
39668- atomic_inc(&dev_priv->last_fence_retired);
39669+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
39670 DRM_WAKEUP(&dev_priv->fence_queue);
39671 handled = 1;
39672 }
39673@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39674 * using fences.
39675 */
39676 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39677- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39678+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39679 - *sequence) <= (1 << 23)));
39680
39681 *sequence = cur_fence;
39682diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39683index 4c3feaa..26391ce 100644
39684--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39685+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39686@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39687 struct bit_table {
39688 const char id;
39689 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39690-};
39691+} __no_const;
39692
39693 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39694
39695diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39696index 4b0fb6c..67667a9 100644
39697--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39698+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39699@@ -96,7 +96,6 @@ struct nouveau_drm {
39700 struct drm_global_reference mem_global_ref;
39701 struct ttm_bo_global_ref bo_global_ref;
39702 struct ttm_bo_device bdev;
39703- atomic_t validate_sequence;
39704 int (*move)(struct nouveau_channel *,
39705 struct ttm_buffer_object *,
39706 struct ttm_mem_reg *, struct ttm_mem_reg *);
39707diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39708index c1a7e5a..38b8539 100644
39709--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39710+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39711@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39712 unsigned long arg)
39713 {
39714 unsigned int nr = DRM_IOCTL_NR(cmd);
39715- drm_ioctl_compat_t *fn = NULL;
39716+ drm_ioctl_compat_t fn = NULL;
39717 int ret;
39718
39719 if (nr < DRM_COMMAND_BASE)
39720diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39721index 19e3757..ad16478 100644
39722--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
39723+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39724@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39725 }
39726
39727 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
39728- nouveau_vram_manager_init,
39729- nouveau_vram_manager_fini,
39730- nouveau_vram_manager_new,
39731- nouveau_vram_manager_del,
39732- nouveau_vram_manager_debug
39733+ .init = nouveau_vram_manager_init,
39734+ .takedown = nouveau_vram_manager_fini,
39735+ .get_node = nouveau_vram_manager_new,
39736+ .put_node = nouveau_vram_manager_del,
39737+ .debug = nouveau_vram_manager_debug
39738 };
39739
39740 static int
39741@@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39742 }
39743
39744 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
39745- nouveau_gart_manager_init,
39746- nouveau_gart_manager_fini,
39747- nouveau_gart_manager_new,
39748- nouveau_gart_manager_del,
39749- nouveau_gart_manager_debug
39750+ .init = nouveau_gart_manager_init,
39751+ .takedown = nouveau_gart_manager_fini,
39752+ .get_node = nouveau_gart_manager_new,
39753+ .put_node = nouveau_gart_manager_del,
39754+ .debug = nouveau_gart_manager_debug
39755 };
39756
39757 #include <core/subdev/vm/nv04.h>
39758@@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39759 }
39760
39761 const struct ttm_mem_type_manager_func nv04_gart_manager = {
39762- nv04_gart_manager_init,
39763- nv04_gart_manager_fini,
39764- nv04_gart_manager_new,
39765- nv04_gart_manager_del,
39766- nv04_gart_manager_debug
39767+ .init = nv04_gart_manager_init,
39768+ .takedown = nv04_gart_manager_fini,
39769+ .get_node = nv04_gart_manager_new,
39770+ .put_node = nv04_gart_manager_del,
39771+ .debug = nv04_gart_manager_debug
39772 };
39773
39774 int
39775diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39776index 81638d7..2e45854 100644
39777--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39778+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39779@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39780 bool can_switch;
39781
39782 spin_lock(&dev->count_lock);
39783- can_switch = (dev->open_count == 0);
39784+ can_switch = (local_read(&dev->open_count) == 0);
39785 spin_unlock(&dev->count_lock);
39786 return can_switch;
39787 }
39788diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
39789index eb89653..613cf71 100644
39790--- a/drivers/gpu/drm/qxl/qxl_cmd.c
39791+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
39792@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
39793 int ret;
39794
39795 mutex_lock(&qdev->async_io_mutex);
39796- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39797+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39798 if (qdev->last_sent_io_cmd > irq_num) {
39799 if (intr)
39800 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39801- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39802+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39803 else
39804 ret = wait_event_timeout(qdev->io_cmd_event,
39805- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39806+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39807 /* 0 is timeout, just bail the "hw" has gone away */
39808 if (ret <= 0)
39809 goto out;
39810- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39811+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39812 }
39813 outb(val, addr);
39814 qdev->last_sent_io_cmd = irq_num + 1;
39815 if (intr)
39816 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39817- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39818+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39819 else
39820 ret = wait_event_timeout(qdev->io_cmd_event,
39821- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39822+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39823 out:
39824 if (ret > 0)
39825 ret = 0;
39826diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
39827index c3c2bbd..bc3c0fb 100644
39828--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
39829+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
39830@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
39831 struct drm_info_node *node = (struct drm_info_node *) m->private;
39832 struct qxl_device *qdev = node->minor->dev->dev_private;
39833
39834- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
39835- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
39836- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
39837- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
39838+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
39839+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
39840+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
39841+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
39842 seq_printf(m, "%d\n", qdev->irq_received_error);
39843 return 0;
39844 }
39845diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
39846index 7bda32f..dd98fc5 100644
39847--- a/drivers/gpu/drm/qxl/qxl_drv.h
39848+++ b/drivers/gpu/drm/qxl/qxl_drv.h
39849@@ -290,10 +290,10 @@ struct qxl_device {
39850 unsigned int last_sent_io_cmd;
39851
39852 /* interrupt handling */
39853- atomic_t irq_received;
39854- atomic_t irq_received_display;
39855- atomic_t irq_received_cursor;
39856- atomic_t irq_received_io_cmd;
39857+ atomic_unchecked_t irq_received;
39858+ atomic_unchecked_t irq_received_display;
39859+ atomic_unchecked_t irq_received_cursor;
39860+ atomic_unchecked_t irq_received_io_cmd;
39861 unsigned irq_received_error;
39862 wait_queue_head_t display_event;
39863 wait_queue_head_t cursor_event;
39864diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
39865index 7b95c75..9cffb4f 100644
39866--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
39867+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
39868@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
39869
39870 /* TODO copy slow path code from i915 */
39871 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
39872- 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);
39873+ 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);
39874
39875 {
39876 struct qxl_drawable *draw = fb_cmd;
39877@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
39878 struct drm_qxl_reloc reloc;
39879
39880 if (DRM_COPY_FROM_USER(&reloc,
39881- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
39882+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
39883 sizeof(reloc))) {
39884 ret = -EFAULT;
39885 goto out_free_bos;
39886@@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
39887 struct drm_qxl_command *commands =
39888 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
39889
39890- if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
39891+ if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
39892 sizeof(user_cmd)))
39893 return -EFAULT;
39894
39895diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
39896index 21393dc..329f3a9 100644
39897--- a/drivers/gpu/drm/qxl/qxl_irq.c
39898+++ b/drivers/gpu/drm/qxl/qxl_irq.c
39899@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
39900
39901 pending = xchg(&qdev->ram_header->int_pending, 0);
39902
39903- atomic_inc(&qdev->irq_received);
39904+ atomic_inc_unchecked(&qdev->irq_received);
39905
39906 if (pending & QXL_INTERRUPT_DISPLAY) {
39907- atomic_inc(&qdev->irq_received_display);
39908+ atomic_inc_unchecked(&qdev->irq_received_display);
39909 wake_up_all(&qdev->display_event);
39910 qxl_queue_garbage_collect(qdev, false);
39911 }
39912 if (pending & QXL_INTERRUPT_CURSOR) {
39913- atomic_inc(&qdev->irq_received_cursor);
39914+ atomic_inc_unchecked(&qdev->irq_received_cursor);
39915 wake_up_all(&qdev->cursor_event);
39916 }
39917 if (pending & QXL_INTERRUPT_IO_CMD) {
39918- atomic_inc(&qdev->irq_received_io_cmd);
39919+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
39920 wake_up_all(&qdev->io_cmd_event);
39921 }
39922 if (pending & QXL_INTERRUPT_ERROR) {
39923@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
39924 init_waitqueue_head(&qdev->io_cmd_event);
39925 INIT_WORK(&qdev->client_monitors_config_work,
39926 qxl_client_monitors_config_work_func);
39927- atomic_set(&qdev->irq_received, 0);
39928- atomic_set(&qdev->irq_received_display, 0);
39929- atomic_set(&qdev->irq_received_cursor, 0);
39930- atomic_set(&qdev->irq_received_io_cmd, 0);
39931+ atomic_set_unchecked(&qdev->irq_received, 0);
39932+ atomic_set_unchecked(&qdev->irq_received_display, 0);
39933+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
39934+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
39935 qdev->irq_received_error = 0;
39936 ret = drm_irq_install(qdev->ddev);
39937 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
39938diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
39939index c7e7e65..7dddd4d 100644
39940--- a/drivers/gpu/drm/qxl/qxl_ttm.c
39941+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
39942@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
39943 }
39944 }
39945
39946-static struct vm_operations_struct qxl_ttm_vm_ops;
39947+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
39948 static const struct vm_operations_struct *ttm_vm_ops;
39949
39950 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39951@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
39952 return r;
39953 if (unlikely(ttm_vm_ops == NULL)) {
39954 ttm_vm_ops = vma->vm_ops;
39955+ pax_open_kernel();
39956 qxl_ttm_vm_ops = *ttm_vm_ops;
39957 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
39958+ pax_close_kernel();
39959 }
39960 vma->vm_ops = &qxl_ttm_vm_ops;
39961 return 0;
39962@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
39963 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
39964 {
39965 #if defined(CONFIG_DEBUG_FS)
39966- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
39967- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
39968- unsigned i;
39969+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
39970+ {
39971+ .name = "qxl_mem_mm",
39972+ .show = &qxl_mm_dump_table,
39973+ },
39974+ {
39975+ .name = "qxl_surf_mm",
39976+ .show = &qxl_mm_dump_table,
39977+ }
39978+ };
39979
39980- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
39981- if (i == 0)
39982- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
39983- else
39984- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
39985- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
39986- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
39987- qxl_mem_types_list[i].driver_features = 0;
39988- if (i == 0)
39989- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39990- else
39991- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39992+ pax_open_kernel();
39993+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39994+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39995+ pax_close_kernel();
39996
39997- }
39998- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
39999+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40000 #else
40001 return 0;
40002 #endif
40003diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40004index c451257..0ad2134 100644
40005--- a/drivers/gpu/drm/r128/r128_cce.c
40006+++ b/drivers/gpu/drm/r128/r128_cce.c
40007@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40008
40009 /* GH: Simple idle check.
40010 */
40011- atomic_set(&dev_priv->idle_count, 0);
40012+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40013
40014 /* We don't support anything other than bus-mastering ring mode,
40015 * but the ring can be in either AGP or PCI space for the ring
40016diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40017index 56eb5e3..c4ec43d 100644
40018--- a/drivers/gpu/drm/r128/r128_drv.h
40019+++ b/drivers/gpu/drm/r128/r128_drv.h
40020@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40021 int is_pci;
40022 unsigned long cce_buffers_offset;
40023
40024- atomic_t idle_count;
40025+ atomic_unchecked_t idle_count;
40026
40027 int page_flipping;
40028 int current_page;
40029 u32 crtc_offset;
40030 u32 crtc_offset_cntl;
40031
40032- atomic_t vbl_received;
40033+ atomic_unchecked_t vbl_received;
40034
40035 u32 color_fmt;
40036 unsigned int front_offset;
40037diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40038index a954c54..9cc595c 100644
40039--- a/drivers/gpu/drm/r128/r128_ioc32.c
40040+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40041@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40042 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40043 }
40044
40045-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40046+drm_ioctl_compat_t r128_compat_ioctls[] = {
40047 [DRM_R128_INIT] = compat_r128_init,
40048 [DRM_R128_DEPTH] = compat_r128_depth,
40049 [DRM_R128_STIPPLE] = compat_r128_stipple,
40050@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40051 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40052 {
40053 unsigned int nr = DRM_IOCTL_NR(cmd);
40054- drm_ioctl_compat_t *fn = NULL;
40055 int ret;
40056
40057 if (nr < DRM_COMMAND_BASE)
40058 return drm_compat_ioctl(filp, cmd, arg);
40059
40060- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40061- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40062-
40063- if (fn != NULL)
40064+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40065+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40066 ret = (*fn) (filp, cmd, arg);
40067- else
40068+ } else
40069 ret = drm_ioctl(filp, cmd, arg);
40070
40071 return ret;
40072diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40073index 2ea4f09..d391371 100644
40074--- a/drivers/gpu/drm/r128/r128_irq.c
40075+++ b/drivers/gpu/drm/r128/r128_irq.c
40076@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40077 if (crtc != 0)
40078 return 0;
40079
40080- return atomic_read(&dev_priv->vbl_received);
40081+ return atomic_read_unchecked(&dev_priv->vbl_received);
40082 }
40083
40084 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40085@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40086 /* VBLANK interrupt */
40087 if (status & R128_CRTC_VBLANK_INT) {
40088 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40089- atomic_inc(&dev_priv->vbl_received);
40090+ atomic_inc_unchecked(&dev_priv->vbl_received);
40091 drm_handle_vblank(dev, 0);
40092 return IRQ_HANDLED;
40093 }
40094diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40095index 01dd9ae..6352f04 100644
40096--- a/drivers/gpu/drm/r128/r128_state.c
40097+++ b/drivers/gpu/drm/r128/r128_state.c
40098@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40099
40100 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40101 {
40102- if (atomic_read(&dev_priv->idle_count) == 0)
40103+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40104 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40105 else
40106- atomic_set(&dev_priv->idle_count, 0);
40107+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40108 }
40109
40110 #endif
40111diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40112index af85299..ed9ac8d 100644
40113--- a/drivers/gpu/drm/radeon/mkregtable.c
40114+++ b/drivers/gpu/drm/radeon/mkregtable.c
40115@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40116 regex_t mask_rex;
40117 regmatch_t match[4];
40118 char buf[1024];
40119- size_t end;
40120+ long end;
40121 int len;
40122 int done = 0;
40123 int r;
40124 unsigned o;
40125 struct offset *offset;
40126 char last_reg_s[10];
40127- int last_reg;
40128+ unsigned long last_reg;
40129
40130 if (regcomp
40131 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40132diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40133index 39b033b..6efc056 100644
40134--- a/drivers/gpu/drm/radeon/radeon_device.c
40135+++ b/drivers/gpu/drm/radeon/radeon_device.c
40136@@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40137 bool can_switch;
40138
40139 spin_lock(&dev->count_lock);
40140- can_switch = (dev->open_count == 0);
40141+ can_switch = (local_read(&dev->open_count) == 0);
40142 spin_unlock(&dev->count_lock);
40143 return can_switch;
40144 }
40145diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40146index 00e0d44..08381a4 100644
40147--- a/drivers/gpu/drm/radeon/radeon_drv.h
40148+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40149@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40150
40151 /* SW interrupt */
40152 wait_queue_head_t swi_queue;
40153- atomic_t swi_emitted;
40154+ atomic_unchecked_t swi_emitted;
40155 int vblank_crtc;
40156 uint32_t irq_enable_reg;
40157 uint32_t r500_disp_irq_reg;
40158diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40159index bdb0f93..5ff558f 100644
40160--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40161+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40162@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40163 request = compat_alloc_user_space(sizeof(*request));
40164 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40165 || __put_user(req32.param, &request->param)
40166- || __put_user((void __user *)(unsigned long)req32.value,
40167+ || __put_user((unsigned long)req32.value,
40168 &request->value))
40169 return -EFAULT;
40170
40171@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40172 #define compat_radeon_cp_setparam NULL
40173 #endif /* X86_64 || IA64 */
40174
40175-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40176+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40177 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40178 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40179 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40180@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40181 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40182 {
40183 unsigned int nr = DRM_IOCTL_NR(cmd);
40184- drm_ioctl_compat_t *fn = NULL;
40185 int ret;
40186
40187 if (nr < DRM_COMMAND_BASE)
40188 return drm_compat_ioctl(filp, cmd, arg);
40189
40190- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40191- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40192-
40193- if (fn != NULL)
40194+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40195+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40196 ret = (*fn) (filp, cmd, arg);
40197- else
40198+ } else
40199 ret = drm_ioctl(filp, cmd, arg);
40200
40201 return ret;
40202diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40203index 8d68e97..9dcfed8 100644
40204--- a/drivers/gpu/drm/radeon/radeon_irq.c
40205+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40206@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40207 unsigned int ret;
40208 RING_LOCALS;
40209
40210- atomic_inc(&dev_priv->swi_emitted);
40211- ret = atomic_read(&dev_priv->swi_emitted);
40212+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40213+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40214
40215 BEGIN_RING(4);
40216 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40217@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40218 drm_radeon_private_t *dev_priv =
40219 (drm_radeon_private_t *) dev->dev_private;
40220
40221- atomic_set(&dev_priv->swi_emitted, 0);
40222+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40223 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40224
40225 dev->max_vblank_count = 0x001fffff;
40226diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40227index 4d20910..6726b6d 100644
40228--- a/drivers/gpu/drm/radeon/radeon_state.c
40229+++ b/drivers/gpu/drm/radeon/radeon_state.c
40230@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40231 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40232 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40233
40234- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40235+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40236 sarea_priv->nbox * sizeof(depth_boxes[0])))
40237 return -EFAULT;
40238
40239@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40240 {
40241 drm_radeon_private_t *dev_priv = dev->dev_private;
40242 drm_radeon_getparam_t *param = data;
40243- int value;
40244+ int value = 0;
40245
40246 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40247
40248diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40249index 71245d6..94c556d 100644
40250--- a/drivers/gpu/drm/radeon/radeon_ttm.c
40251+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40252@@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40253 man->size = size >> PAGE_SHIFT;
40254 }
40255
40256-static struct vm_operations_struct radeon_ttm_vm_ops;
40257+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40258 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40259
40260 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40261@@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40262 }
40263 if (unlikely(ttm_vm_ops == NULL)) {
40264 ttm_vm_ops = vma->vm_ops;
40265+ pax_open_kernel();
40266 radeon_ttm_vm_ops = *ttm_vm_ops;
40267 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40268+ pax_close_kernel();
40269 }
40270 vma->vm_ops = &radeon_ttm_vm_ops;
40271 return 0;
40272@@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40273 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40274 {
40275 #if defined(CONFIG_DEBUG_FS)
40276- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40277- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40278- unsigned i;
40279+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40280+ {
40281+ .name = "radeon_vram_mm",
40282+ .show = &radeon_mm_dump_table,
40283+ },
40284+ {
40285+ .name = "radeon_gtt_mm",
40286+ .show = &radeon_mm_dump_table,
40287+ },
40288+ {
40289+ .name = "ttm_page_pool",
40290+ .show = &ttm_page_alloc_debugfs,
40291+ },
40292+ {
40293+ .name = "ttm_dma_page_pool",
40294+ .show = &ttm_dma_page_alloc_debugfs,
40295+ },
40296+ };
40297+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40298
40299- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40300- if (i == 0)
40301- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40302- else
40303- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40304- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40305- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40306- radeon_mem_types_list[i].driver_features = 0;
40307- if (i == 0)
40308- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40309- else
40310- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40311-
40312- }
40313- /* Add ttm page pool to debugfs */
40314- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40315- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40316- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40317- radeon_mem_types_list[i].driver_features = 0;
40318- radeon_mem_types_list[i++].data = NULL;
40319+ pax_open_kernel();
40320+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40321+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40322+ pax_close_kernel();
40323 #ifdef CONFIG_SWIOTLB
40324- if (swiotlb_nr_tbl()) {
40325- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
40326- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40327- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
40328- radeon_mem_types_list[i].driver_features = 0;
40329- radeon_mem_types_list[i++].data = NULL;
40330- }
40331+ if (swiotlb_nr_tbl())
40332+ i++;
40333 #endif
40334 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
40335
40336diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40337index ae1cb31..5b5b6b7c 100644
40338--- a/drivers/gpu/drm/tegra/dc.c
40339+++ b/drivers/gpu/drm/tegra/dc.c
40340@@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40341 }
40342
40343 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40344- dc->debugfs_files[i].data = dc;
40345+ *(void **)&dc->debugfs_files[i].data = dc;
40346
40347 err = drm_debugfs_create_files(dc->debugfs_files,
40348 ARRAY_SIZE(debugfs_files),
40349diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40350index c58eba33..83c2728 100644
40351--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
40352+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40353@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
40354 }
40355
40356 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
40357- ttm_bo_man_init,
40358- ttm_bo_man_takedown,
40359- ttm_bo_man_get_node,
40360- ttm_bo_man_put_node,
40361- ttm_bo_man_debug
40362+ .init = ttm_bo_man_init,
40363+ .takedown = ttm_bo_man_takedown,
40364+ .get_node = ttm_bo_man_get_node,
40365+ .put_node = ttm_bo_man_put_node,
40366+ .debug = ttm_bo_man_debug
40367 };
40368 EXPORT_SYMBOL(ttm_bo_manager_func);
40369diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
40370index dbc2def..0a9f710 100644
40371--- a/drivers/gpu/drm/ttm/ttm_memory.c
40372+++ b/drivers/gpu/drm/ttm/ttm_memory.c
40373@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
40374 zone->glob = glob;
40375 glob->zone_kernel = zone;
40376 ret = kobject_init_and_add(
40377- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40378+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40379 if (unlikely(ret != 0)) {
40380 kobject_put(&zone->kobj);
40381 return ret;
40382@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
40383 zone->glob = glob;
40384 glob->zone_dma32 = zone;
40385 ret = kobject_init_and_add(
40386- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40387+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40388 if (unlikely(ret != 0)) {
40389 kobject_put(&zone->kobj);
40390 return ret;
40391diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40392index 863bef9..cba15cf 100644
40393--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
40394+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40395@@ -391,9 +391,9 @@ out:
40396 static unsigned long
40397 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
40398 {
40399- static atomic_t start_pool = ATOMIC_INIT(0);
40400+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
40401 unsigned i;
40402- unsigned pool_offset = atomic_add_return(1, &start_pool);
40403+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
40404 struct ttm_page_pool *pool;
40405 int shrink_pages = sc->nr_to_scan;
40406 unsigned long freed = 0;
40407diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
40408index 97e9d61..bf23c461 100644
40409--- a/drivers/gpu/drm/udl/udl_fb.c
40410+++ b/drivers/gpu/drm/udl/udl_fb.c
40411@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
40412 fb_deferred_io_cleanup(info);
40413 kfree(info->fbdefio);
40414 info->fbdefio = NULL;
40415- info->fbops->fb_mmap = udl_fb_mmap;
40416 }
40417
40418 pr_warn("released /dev/fb%d user=%d count=%d\n",
40419diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
40420index a811ef2..ff99b05 100644
40421--- a/drivers/gpu/drm/via/via_drv.h
40422+++ b/drivers/gpu/drm/via/via_drv.h
40423@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
40424 typedef uint32_t maskarray_t[5];
40425
40426 typedef struct drm_via_irq {
40427- atomic_t irq_received;
40428+ atomic_unchecked_t irq_received;
40429 uint32_t pending_mask;
40430 uint32_t enable_mask;
40431 wait_queue_head_t irq_queue;
40432@@ -75,7 +75,7 @@ typedef struct drm_via_private {
40433 struct timeval last_vblank;
40434 int last_vblank_valid;
40435 unsigned usec_per_vblank;
40436- atomic_t vbl_received;
40437+ atomic_unchecked_t vbl_received;
40438 drm_via_state_t hc_state;
40439 char pci_buf[VIA_PCI_BUF_SIZE];
40440 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
40441diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
40442index ac98964..5dbf512 100644
40443--- a/drivers/gpu/drm/via/via_irq.c
40444+++ b/drivers/gpu/drm/via/via_irq.c
40445@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
40446 if (crtc != 0)
40447 return 0;
40448
40449- return atomic_read(&dev_priv->vbl_received);
40450+ return atomic_read_unchecked(&dev_priv->vbl_received);
40451 }
40452
40453 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40454@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40455
40456 status = VIA_READ(VIA_REG_INTERRUPT);
40457 if (status & VIA_IRQ_VBLANK_PENDING) {
40458- atomic_inc(&dev_priv->vbl_received);
40459- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
40460+ atomic_inc_unchecked(&dev_priv->vbl_received);
40461+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
40462 do_gettimeofday(&cur_vblank);
40463 if (dev_priv->last_vblank_valid) {
40464 dev_priv->usec_per_vblank =
40465@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40466 dev_priv->last_vblank = cur_vblank;
40467 dev_priv->last_vblank_valid = 1;
40468 }
40469- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
40470+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
40471 DRM_DEBUG("US per vblank is: %u\n",
40472 dev_priv->usec_per_vblank);
40473 }
40474@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40475
40476 for (i = 0; i < dev_priv->num_irqs; ++i) {
40477 if (status & cur_irq->pending_mask) {
40478- atomic_inc(&cur_irq->irq_received);
40479+ atomic_inc_unchecked(&cur_irq->irq_received);
40480 DRM_WAKEUP(&cur_irq->irq_queue);
40481 handled = 1;
40482 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
40483@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
40484 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40485 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
40486 masks[irq][4]));
40487- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
40488+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
40489 } else {
40490 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40491 (((cur_irq_sequence =
40492- atomic_read(&cur_irq->irq_received)) -
40493+ atomic_read_unchecked(&cur_irq->irq_received)) -
40494 *sequence) <= (1 << 23)));
40495 }
40496 *sequence = cur_irq_sequence;
40497@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
40498 }
40499
40500 for (i = 0; i < dev_priv->num_irqs; ++i) {
40501- atomic_set(&cur_irq->irq_received, 0);
40502+ atomic_set_unchecked(&cur_irq->irq_received, 0);
40503 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
40504 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
40505 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
40506@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
40507 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
40508 case VIA_IRQ_RELATIVE:
40509 irqwait->request.sequence +=
40510- atomic_read(&cur_irq->irq_received);
40511+ atomic_read_unchecked(&cur_irq->irq_received);
40512 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
40513 case VIA_IRQ_ABSOLUTE:
40514 break;
40515diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40516index 20890ad..699e4f2 100644
40517--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40518+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40519@@ -342,7 +342,7 @@ struct vmw_private {
40520 * Fencing and IRQs.
40521 */
40522
40523- atomic_t marker_seq;
40524+ atomic_unchecked_t marker_seq;
40525 wait_queue_head_t fence_queue;
40526 wait_queue_head_t fifo_queue;
40527 int fence_queue_waiters; /* Protected by hw_mutex */
40528diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40529index 3eb1486..0a47ee9 100644
40530--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40531+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40532@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
40533 (unsigned int) min,
40534 (unsigned int) fifo->capabilities);
40535
40536- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40537+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40538 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
40539 vmw_marker_queue_init(&fifo->marker_queue);
40540 return vmw_fifo_send_fence(dev_priv, &dummy);
40541@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
40542 if (reserveable)
40543 iowrite32(bytes, fifo_mem +
40544 SVGA_FIFO_RESERVED);
40545- return fifo_mem + (next_cmd >> 2);
40546+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
40547 } else {
40548 need_bounce = true;
40549 }
40550@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40551
40552 fm = vmw_fifo_reserve(dev_priv, bytes);
40553 if (unlikely(fm == NULL)) {
40554- *seqno = atomic_read(&dev_priv->marker_seq);
40555+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40556 ret = -ENOMEM;
40557 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
40558 false, 3*HZ);
40559@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40560 }
40561
40562 do {
40563- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
40564+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
40565 } while (*seqno == 0);
40566
40567 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
40568diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40569index c5c054a..46f0548 100644
40570--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40571+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40572@@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
40573 }
40574
40575 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
40576- vmw_gmrid_man_init,
40577- vmw_gmrid_man_takedown,
40578- vmw_gmrid_man_get_node,
40579- vmw_gmrid_man_put_node,
40580- vmw_gmrid_man_debug
40581+ .init = vmw_gmrid_man_init,
40582+ .takedown = vmw_gmrid_man_takedown,
40583+ .get_node = vmw_gmrid_man_get_node,
40584+ .put_node = vmw_gmrid_man_put_node,
40585+ .debug = vmw_gmrid_man_debug
40586 };
40587diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40588index 45d5b5a..f3f5e4e 100644
40589--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40590+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40591@@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
40592 int ret;
40593
40594 num_clips = arg->num_clips;
40595- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40596+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40597
40598 if (unlikely(num_clips == 0))
40599 return 0;
40600@@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
40601 int ret;
40602
40603 num_clips = arg->num_clips;
40604- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40605+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40606
40607 if (unlikely(num_clips == 0))
40608 return 0;
40609diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40610index 4640adb..e1384ed 100644
40611--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40612+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40613@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
40614 * emitted. Then the fence is stale and signaled.
40615 */
40616
40617- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
40618+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
40619 > VMW_FENCE_WRAP);
40620
40621 return ret;
40622@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
40623
40624 if (fifo_idle)
40625 down_read(&fifo_state->rwsem);
40626- signal_seq = atomic_read(&dev_priv->marker_seq);
40627+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
40628 ret = 0;
40629
40630 for (;;) {
40631diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40632index 8a8725c2..afed796 100644
40633--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40634+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40635@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
40636 while (!vmw_lag_lt(queue, us)) {
40637 spin_lock(&queue->lock);
40638 if (list_empty(&queue->head))
40639- seqno = atomic_read(&dev_priv->marker_seq);
40640+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40641 else {
40642 marker = list_first_entry(&queue->head,
40643 struct vmw_marker, head);
40644diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
40645index ec0ae2d..dc0780b 100644
40646--- a/drivers/gpu/vga/vga_switcheroo.c
40647+++ b/drivers/gpu/vga/vga_switcheroo.c
40648@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
40649
40650 /* this version is for the case where the power switch is separate
40651 to the device being powered down. */
40652-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
40653+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
40654 {
40655 /* copy over all the bus versions */
40656 if (dev->bus && dev->bus->pm) {
40657@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
40658 return ret;
40659 }
40660
40661-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
40662+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
40663 {
40664 /* copy over all the bus versions */
40665 if (dev->bus && dev->bus->pm) {
40666diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
40667index 253fe23..0dfec5f 100644
40668--- a/drivers/hid/hid-core.c
40669+++ b/drivers/hid/hid-core.c
40670@@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40671
40672 int hid_add_device(struct hid_device *hdev)
40673 {
40674- static atomic_t id = ATOMIC_INIT(0);
40675+ static atomic_unchecked_t id = ATOMIC_INIT(0);
40676 int ret;
40677
40678 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40679@@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
40680 /* XXX hack, any other cleaner solution after the driver core
40681 * is converted to allow more than 20 bytes as the device name? */
40682 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40683- hdev->vendor, hdev->product, atomic_inc_return(&id));
40684+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40685
40686 hid_debug_register(hdev, dev_name(&hdev->dev));
40687 ret = device_add(&hdev->dev);
40688diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40689index c13fb5b..55a3802 100644
40690--- a/drivers/hid/hid-wiimote-debug.c
40691+++ b/drivers/hid/hid-wiimote-debug.c
40692@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40693 else if (size == 0)
40694 return -EIO;
40695
40696- if (copy_to_user(u, buf, size))
40697+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
40698 return -EFAULT;
40699
40700 *off += size;
40701diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40702index cedc6da..2c3da2a 100644
40703--- a/drivers/hid/uhid.c
40704+++ b/drivers/hid/uhid.c
40705@@ -47,7 +47,7 @@ struct uhid_device {
40706 struct mutex report_lock;
40707 wait_queue_head_t report_wait;
40708 atomic_t report_done;
40709- atomic_t report_id;
40710+ atomic_unchecked_t report_id;
40711 struct uhid_event report_buf;
40712 };
40713
40714@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40715
40716 spin_lock_irqsave(&uhid->qlock, flags);
40717 ev->type = UHID_FEATURE;
40718- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40719+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40720 ev->u.feature.rnum = rnum;
40721 ev->u.feature.rtype = report_type;
40722
40723@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40724 spin_lock_irqsave(&uhid->qlock, flags);
40725
40726 /* id for old report; drop it silently */
40727- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40728+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40729 goto unlock;
40730 if (atomic_read(&uhid->report_done))
40731 goto unlock;
40732diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40733index cea623c..73011b0 100644
40734--- a/drivers/hv/channel.c
40735+++ b/drivers/hv/channel.c
40736@@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40737 int ret = 0;
40738 int t;
40739
40740- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40741- atomic_inc(&vmbus_connection.next_gpadl_handle);
40742+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40743+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40744
40745 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40746 if (ret)
40747diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40748index f0c5e07..399256e 100644
40749--- a/drivers/hv/hv.c
40750+++ b/drivers/hv/hv.c
40751@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40752 u64 output_address = (output) ? virt_to_phys(output) : 0;
40753 u32 output_address_hi = output_address >> 32;
40754 u32 output_address_lo = output_address & 0xFFFFFFFF;
40755- void *hypercall_page = hv_context.hypercall_page;
40756+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40757
40758 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40759 "=a"(hv_status_lo) : "d" (control_hi),
40760diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40761index 7e17a54..a50a33d 100644
40762--- a/drivers/hv/hv_balloon.c
40763+++ b/drivers/hv/hv_balloon.c
40764@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40765
40766 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40767 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40768-static atomic_t trans_id = ATOMIC_INIT(0);
40769+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40770
40771 static int dm_ring_size = (5 * PAGE_SIZE);
40772
40773@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
40774 pr_info("Memory hot add failed\n");
40775
40776 dm->state = DM_INITIALIZED;
40777- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40778+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40779 vmbus_sendpacket(dm->dev->channel, &resp,
40780 sizeof(struct dm_hot_add_response),
40781 (unsigned long)NULL,
40782@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40783 memset(&status, 0, sizeof(struct dm_status));
40784 status.hdr.type = DM_STATUS_REPORT;
40785 status.hdr.size = sizeof(struct dm_status);
40786- status.hdr.trans_id = atomic_inc_return(&trans_id);
40787+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40788
40789 /*
40790 * The host expects the guest to report free memory.
40791@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40792 * send the status. This can happen if we were interrupted
40793 * after we picked our transaction ID.
40794 */
40795- if (status.hdr.trans_id != atomic_read(&trans_id))
40796+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40797 return;
40798
40799 vmbus_sendpacket(dm->dev->channel, &status,
40800@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
40801 */
40802
40803 do {
40804- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40805+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40806 ret = vmbus_sendpacket(dm_device.dev->channel,
40807 bl_resp,
40808 bl_resp->hdr.size,
40809@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40810
40811 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40812 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40813- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40814+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40815 resp.hdr.size = sizeof(struct dm_unballoon_response);
40816
40817 vmbus_sendpacket(dm_device.dev->channel, &resp,
40818@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40819 memset(&version_req, 0, sizeof(struct dm_version_request));
40820 version_req.hdr.type = DM_VERSION_REQUEST;
40821 version_req.hdr.size = sizeof(struct dm_version_request);
40822- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40823+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40824 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40825 version_req.is_last_attempt = 1;
40826
40827@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40828 memset(&version_req, 0, sizeof(struct dm_version_request));
40829 version_req.hdr.type = DM_VERSION_REQUEST;
40830 version_req.hdr.size = sizeof(struct dm_version_request);
40831- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40832+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40833 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40834 version_req.is_last_attempt = 0;
40835
40836@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40837 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40838 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40839 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40840- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40841+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40842
40843 cap_msg.caps.cap_bits.balloon = 1;
40844 cap_msg.caps.cap_bits.hot_add = 1;
40845diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40846index e055176..c22ff1f 100644
40847--- a/drivers/hv/hyperv_vmbus.h
40848+++ b/drivers/hv/hyperv_vmbus.h
40849@@ -602,7 +602,7 @@ enum vmbus_connect_state {
40850 struct vmbus_connection {
40851 enum vmbus_connect_state conn_state;
40852
40853- atomic_t next_gpadl_handle;
40854+ atomic_unchecked_t next_gpadl_handle;
40855
40856 /*
40857 * Represents channel interrupts. Each bit position represents a
40858diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40859index 48aad4f..c768fb2 100644
40860--- a/drivers/hv/vmbus_drv.c
40861+++ b/drivers/hv/vmbus_drv.c
40862@@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40863 {
40864 int ret = 0;
40865
40866- static atomic_t device_num = ATOMIC_INIT(0);
40867+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40868
40869 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40870- atomic_inc_return(&device_num));
40871+ atomic_inc_return_unchecked(&device_num));
40872
40873 child_device_obj->device.bus = &hv_bus;
40874 child_device_obj->device.parent = &hv_acpi_dev->dev;
40875diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40876index 6a34f7f..aa4c3a6 100644
40877--- a/drivers/hwmon/acpi_power_meter.c
40878+++ b/drivers/hwmon/acpi_power_meter.c
40879@@ -117,7 +117,7 @@ struct sensor_template {
40880 struct device_attribute *devattr,
40881 const char *buf, size_t count);
40882 int index;
40883-};
40884+} __do_const;
40885
40886 /* Averaging interval */
40887 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40888@@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40889 struct sensor_template *attrs)
40890 {
40891 struct device *dev = &resource->acpi_dev->dev;
40892- struct sensor_device_attribute *sensors =
40893+ sensor_device_attribute_no_const *sensors =
40894 &resource->sensors[resource->num_sensors];
40895 int res = 0;
40896
40897diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40898index 3288f13..71cfb4e 100644
40899--- a/drivers/hwmon/applesmc.c
40900+++ b/drivers/hwmon/applesmc.c
40901@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40902 {
40903 struct applesmc_node_group *grp;
40904 struct applesmc_dev_attr *node;
40905- struct attribute *attr;
40906+ attribute_no_const *attr;
40907 int ret, i;
40908
40909 for (grp = groups; grp->format; grp++) {
40910diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40911index dafc63c..4abb96c 100644
40912--- a/drivers/hwmon/asus_atk0110.c
40913+++ b/drivers/hwmon/asus_atk0110.c
40914@@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40915 struct atk_sensor_data {
40916 struct list_head list;
40917 struct atk_data *data;
40918- struct device_attribute label_attr;
40919- struct device_attribute input_attr;
40920- struct device_attribute limit1_attr;
40921- struct device_attribute limit2_attr;
40922+ device_attribute_no_const label_attr;
40923+ device_attribute_no_const input_attr;
40924+ device_attribute_no_const limit1_attr;
40925+ device_attribute_no_const limit2_attr;
40926 char label_attr_name[ATTR_NAME_SIZE];
40927 char input_attr_name[ATTR_NAME_SIZE];
40928 char limit1_attr_name[ATTR_NAME_SIZE];
40929@@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
40930 static struct device_attribute atk_name_attr =
40931 __ATTR(name, 0444, atk_name_show, NULL);
40932
40933-static void atk_init_attribute(struct device_attribute *attr, char *name,
40934+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40935 sysfs_show_func show)
40936 {
40937 sysfs_attr_init(&attr->attr);
40938diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40939index 9425098..7646cc5 100644
40940--- a/drivers/hwmon/coretemp.c
40941+++ b/drivers/hwmon/coretemp.c
40942@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40943 return NOTIFY_OK;
40944 }
40945
40946-static struct notifier_block coretemp_cpu_notifier __refdata = {
40947+static struct notifier_block coretemp_cpu_notifier = {
40948 .notifier_call = coretemp_cpu_callback,
40949 };
40950
40951diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40952index 632f1dc..57e6a58 100644
40953--- a/drivers/hwmon/ibmaem.c
40954+++ b/drivers/hwmon/ibmaem.c
40955@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40956 struct aem_rw_sensor_template *rw)
40957 {
40958 struct device *dev = &data->pdev->dev;
40959- struct sensor_device_attribute *sensors = data->sensors;
40960+ sensor_device_attribute_no_const *sensors = data->sensors;
40961 int err;
40962
40963 /* Set up read-only sensors */
40964diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40965index 708081b..fe2d4ab 100644
40966--- a/drivers/hwmon/iio_hwmon.c
40967+++ b/drivers/hwmon/iio_hwmon.c
40968@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40969 {
40970 struct device *dev = &pdev->dev;
40971 struct iio_hwmon_state *st;
40972- struct sensor_device_attribute *a;
40973+ sensor_device_attribute_no_const *a;
40974 int ret, i;
40975 int in_i = 1, temp_i = 1, curr_i = 1;
40976 enum iio_chan_type type;
40977diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
40978index cf811c1..4c17110 100644
40979--- a/drivers/hwmon/nct6775.c
40980+++ b/drivers/hwmon/nct6775.c
40981@@ -944,10 +944,10 @@ static struct attribute_group *
40982 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
40983 int repeat)
40984 {
40985- struct attribute_group *group;
40986+ attribute_group_no_const *group;
40987 struct sensor_device_attr_u *su;
40988- struct sensor_device_attribute *a;
40989- struct sensor_device_attribute_2 *a2;
40990+ sensor_device_attribute_no_const *a;
40991+ sensor_device_attribute_2_no_const *a2;
40992 struct attribute **attrs;
40993 struct sensor_device_template **t;
40994 int i, count;
40995diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40996index 3cbf66e..8c5cc2a 100644
40997--- a/drivers/hwmon/pmbus/pmbus_core.c
40998+++ b/drivers/hwmon/pmbus/pmbus_core.c
40999@@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41000 return 0;
41001 }
41002
41003-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41004+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41005 const char *name,
41006 umode_t mode,
41007 ssize_t (*show)(struct device *dev,
41008@@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41009 dev_attr->store = store;
41010 }
41011
41012-static void pmbus_attr_init(struct sensor_device_attribute *a,
41013+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41014 const char *name,
41015 umode_t mode,
41016 ssize_t (*show)(struct device *dev,
41017@@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41018 u16 reg, u8 mask)
41019 {
41020 struct pmbus_boolean *boolean;
41021- struct sensor_device_attribute *a;
41022+ sensor_device_attribute_no_const *a;
41023
41024 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41025 if (!boolean)
41026@@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41027 bool update, bool readonly)
41028 {
41029 struct pmbus_sensor *sensor;
41030- struct device_attribute *a;
41031+ device_attribute_no_const *a;
41032
41033 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41034 if (!sensor)
41035@@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41036 const char *lstring, int index)
41037 {
41038 struct pmbus_label *label;
41039- struct device_attribute *a;
41040+ device_attribute_no_const *a;
41041
41042 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41043 if (!label)
41044diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41045index 97cd45a..ac54d8b 100644
41046--- a/drivers/hwmon/sht15.c
41047+++ b/drivers/hwmon/sht15.c
41048@@ -169,7 +169,7 @@ struct sht15_data {
41049 int supply_uv;
41050 bool supply_uv_valid;
41051 struct work_struct update_supply_work;
41052- atomic_t interrupt_handled;
41053+ atomic_unchecked_t interrupt_handled;
41054 };
41055
41056 /**
41057@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41058 ret = gpio_direction_input(data->pdata->gpio_data);
41059 if (ret)
41060 return ret;
41061- atomic_set(&data->interrupt_handled, 0);
41062+ atomic_set_unchecked(&data->interrupt_handled, 0);
41063
41064 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41065 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41066 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41067 /* Only relevant if the interrupt hasn't occurred. */
41068- if (!atomic_read(&data->interrupt_handled))
41069+ if (!atomic_read_unchecked(&data->interrupt_handled))
41070 schedule_work(&data->read_work);
41071 }
41072 ret = wait_event_timeout(data->wait_queue,
41073@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41074
41075 /* First disable the interrupt */
41076 disable_irq_nosync(irq);
41077- atomic_inc(&data->interrupt_handled);
41078+ atomic_inc_unchecked(&data->interrupt_handled);
41079 /* Then schedule a reading work struct */
41080 if (data->state != SHT15_READING_NOTHING)
41081 schedule_work(&data->read_work);
41082@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41083 * If not, then start the interrupt again - care here as could
41084 * have gone low in meantime so verify it hasn't!
41085 */
41086- atomic_set(&data->interrupt_handled, 0);
41087+ atomic_set_unchecked(&data->interrupt_handled, 0);
41088 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41089 /* If still not occurred or another handler was scheduled */
41090 if (gpio_get_value(data->pdata->gpio_data)
41091- || atomic_read(&data->interrupt_handled))
41092+ || atomic_read_unchecked(&data->interrupt_handled))
41093 return;
41094 }
41095
41096diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41097index 38944e9..ae9e5ed 100644
41098--- a/drivers/hwmon/via-cputemp.c
41099+++ b/drivers/hwmon/via-cputemp.c
41100@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41101 return NOTIFY_OK;
41102 }
41103
41104-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41105+static struct notifier_block via_cputemp_cpu_notifier = {
41106 .notifier_call = via_cputemp_cpu_callback,
41107 };
41108
41109diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41110index 07f01ac..d79ad3d 100644
41111--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41112+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41113@@ -43,7 +43,7 @@
41114 extern struct i2c_adapter amd756_smbus;
41115
41116 static struct i2c_adapter *s4882_adapter;
41117-static struct i2c_algorithm *s4882_algo;
41118+static i2c_algorithm_no_const *s4882_algo;
41119
41120 /* Wrapper access functions for multiplexed SMBus */
41121 static DEFINE_MUTEX(amd756_lock);
41122diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41123index 721f7eb..0fd2a09 100644
41124--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41125+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41126@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41127 /* usb layer */
41128
41129 /* Send command to device, and get response. */
41130-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41131+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41132 {
41133 int ret = 0;
41134 int actual;
41135diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41136index 2ca268d..c6acbdf 100644
41137--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41138+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41139@@ -41,7 +41,7 @@
41140 extern struct i2c_adapter *nforce2_smbus;
41141
41142 static struct i2c_adapter *s4985_adapter;
41143-static struct i2c_algorithm *s4985_algo;
41144+static i2c_algorithm_no_const *s4985_algo;
41145
41146 /* Wrapper access functions for multiplexed SMBus */
41147 static DEFINE_MUTEX(nforce2_lock);
41148diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41149index 80b47e8..1a6040d9 100644
41150--- a/drivers/i2c/i2c-dev.c
41151+++ b/drivers/i2c/i2c-dev.c
41152@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41153 break;
41154 }
41155
41156- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41157+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41158 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41159 if (IS_ERR(rdwr_pa[i].buf)) {
41160 res = PTR_ERR(rdwr_pa[i].buf);
41161diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41162index 0b510ba..4fbb5085 100644
41163--- a/drivers/ide/ide-cd.c
41164+++ b/drivers/ide/ide-cd.c
41165@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41166 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41167 if ((unsigned long)buf & alignment
41168 || blk_rq_bytes(rq) & q->dma_pad_mask
41169- || object_is_on_stack(buf))
41170+ || object_starts_on_stack(buf))
41171 drive->dma = 0;
41172 }
41173 }
41174diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41175index 18f72e3..3722327 100644
41176--- a/drivers/iio/industrialio-core.c
41177+++ b/drivers/iio/industrialio-core.c
41178@@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41179 }
41180
41181 static
41182-int __iio_device_attr_init(struct device_attribute *dev_attr,
41183+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41184 const char *postfix,
41185 struct iio_chan_spec const *chan,
41186 ssize_t (*readfunc)(struct device *dev,
41187diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41188index f2ef7ef..743d02f 100644
41189--- a/drivers/infiniband/core/cm.c
41190+++ b/drivers/infiniband/core/cm.c
41191@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41192
41193 struct cm_counter_group {
41194 struct kobject obj;
41195- atomic_long_t counter[CM_ATTR_COUNT];
41196+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41197 };
41198
41199 struct cm_counter_attribute {
41200@@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41201 struct ib_mad_send_buf *msg = NULL;
41202 int ret;
41203
41204- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41205+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41206 counter[CM_REQ_COUNTER]);
41207
41208 /* Quick state check to discard duplicate REQs. */
41209@@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41210 if (!cm_id_priv)
41211 return;
41212
41213- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41214+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41215 counter[CM_REP_COUNTER]);
41216 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41217 if (ret)
41218@@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41219 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41220 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41221 spin_unlock_irq(&cm_id_priv->lock);
41222- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41223+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41224 counter[CM_RTU_COUNTER]);
41225 goto out;
41226 }
41227@@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41228 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41229 dreq_msg->local_comm_id);
41230 if (!cm_id_priv) {
41231- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41232+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41233 counter[CM_DREQ_COUNTER]);
41234 cm_issue_drep(work->port, work->mad_recv_wc);
41235 return -EINVAL;
41236@@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41237 case IB_CM_MRA_REP_RCVD:
41238 break;
41239 case IB_CM_TIMEWAIT:
41240- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41241+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41242 counter[CM_DREQ_COUNTER]);
41243 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41244 goto unlock;
41245@@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41246 cm_free_msg(msg);
41247 goto deref;
41248 case IB_CM_DREQ_RCVD:
41249- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41250+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41251 counter[CM_DREQ_COUNTER]);
41252 goto unlock;
41253 default:
41254@@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41255 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41256 cm_id_priv->msg, timeout)) {
41257 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41258- atomic_long_inc(&work->port->
41259+ atomic_long_inc_unchecked(&work->port->
41260 counter_group[CM_RECV_DUPLICATES].
41261 counter[CM_MRA_COUNTER]);
41262 goto out;
41263@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41264 break;
41265 case IB_CM_MRA_REQ_RCVD:
41266 case IB_CM_MRA_REP_RCVD:
41267- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41268+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41269 counter[CM_MRA_COUNTER]);
41270 /* fall through */
41271 default:
41272@@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41273 case IB_CM_LAP_IDLE:
41274 break;
41275 case IB_CM_MRA_LAP_SENT:
41276- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41277+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41278 counter[CM_LAP_COUNTER]);
41279 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41280 goto unlock;
41281@@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41282 cm_free_msg(msg);
41283 goto deref;
41284 case IB_CM_LAP_RCVD:
41285- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41286+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41287 counter[CM_LAP_COUNTER]);
41288 goto unlock;
41289 default:
41290@@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41291 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41292 if (cur_cm_id_priv) {
41293 spin_unlock_irq(&cm.lock);
41294- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41295+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41296 counter[CM_SIDR_REQ_COUNTER]);
41297 goto out; /* Duplicate message. */
41298 }
41299@@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41300 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41301 msg->retries = 1;
41302
41303- atomic_long_add(1 + msg->retries,
41304+ atomic_long_add_unchecked(1 + msg->retries,
41305 &port->counter_group[CM_XMIT].counter[attr_index]);
41306 if (msg->retries)
41307- atomic_long_add(msg->retries,
41308+ atomic_long_add_unchecked(msg->retries,
41309 &port->counter_group[CM_XMIT_RETRIES].
41310 counter[attr_index]);
41311
41312@@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41313 }
41314
41315 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41316- atomic_long_inc(&port->counter_group[CM_RECV].
41317+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41318 counter[attr_id - CM_ATTR_ID_OFFSET]);
41319
41320 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41321@@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41322 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41323
41324 return sprintf(buf, "%ld\n",
41325- atomic_long_read(&group->counter[cm_attr->index]));
41326+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41327 }
41328
41329 static const struct sysfs_ops cm_counter_ops = {
41330diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41331index 9f5ad7c..588cd84 100644
41332--- a/drivers/infiniband/core/fmr_pool.c
41333+++ b/drivers/infiniband/core/fmr_pool.c
41334@@ -98,8 +98,8 @@ struct ib_fmr_pool {
41335
41336 struct task_struct *thread;
41337
41338- atomic_t req_ser;
41339- atomic_t flush_ser;
41340+ atomic_unchecked_t req_ser;
41341+ atomic_unchecked_t flush_ser;
41342
41343 wait_queue_head_t force_wait;
41344 };
41345@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41346 struct ib_fmr_pool *pool = pool_ptr;
41347
41348 do {
41349- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41350+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41351 ib_fmr_batch_release(pool);
41352
41353- atomic_inc(&pool->flush_ser);
41354+ atomic_inc_unchecked(&pool->flush_ser);
41355 wake_up_interruptible(&pool->force_wait);
41356
41357 if (pool->flush_function)
41358@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41359 }
41360
41361 set_current_state(TASK_INTERRUPTIBLE);
41362- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
41363+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
41364 !kthread_should_stop())
41365 schedule();
41366 __set_current_state(TASK_RUNNING);
41367@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
41368 pool->dirty_watermark = params->dirty_watermark;
41369 pool->dirty_len = 0;
41370 spin_lock_init(&pool->pool_lock);
41371- atomic_set(&pool->req_ser, 0);
41372- atomic_set(&pool->flush_ser, 0);
41373+ atomic_set_unchecked(&pool->req_ser, 0);
41374+ atomic_set_unchecked(&pool->flush_ser, 0);
41375 init_waitqueue_head(&pool->force_wait);
41376
41377 pool->thread = kthread_run(ib_fmr_cleanup_thread,
41378@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41379 }
41380 spin_unlock_irq(&pool->pool_lock);
41381
41382- serial = atomic_inc_return(&pool->req_ser);
41383+ serial = atomic_inc_return_unchecked(&pool->req_ser);
41384 wake_up_process(pool->thread);
41385
41386 if (wait_event_interruptible(pool->force_wait,
41387- atomic_read(&pool->flush_ser) - serial >= 0))
41388+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41389 return -EINTR;
41390
41391 return 0;
41392@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
41393 } else {
41394 list_add_tail(&fmr->list, &pool->dirty_list);
41395 if (++pool->dirty_len >= pool->dirty_watermark) {
41396- atomic_inc(&pool->req_ser);
41397+ atomic_inc_unchecked(&pool->req_ser);
41398 wake_up_process(pool->thread);
41399 }
41400 }
41401diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
41402index 84e4500..2c9beeb 100644
41403--- a/drivers/infiniband/hw/cxgb4/mem.c
41404+++ b/drivers/infiniband/hw/cxgb4/mem.c
41405@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41406 int err;
41407 struct fw_ri_tpte tpt;
41408 u32 stag_idx;
41409- static atomic_t key;
41410+ static atomic_unchecked_t key;
41411
41412 if (c4iw_fatal_error(rdev))
41413 return -EIO;
41414@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41415 if (rdev->stats.stag.cur > rdev->stats.stag.max)
41416 rdev->stats.stag.max = rdev->stats.stag.cur;
41417 mutex_unlock(&rdev->stats.lock);
41418- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
41419+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
41420 }
41421 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
41422 __func__, stag_state, type, pdid, stag_idx);
41423diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
41424index 644c2c7..ecf0879 100644
41425--- a/drivers/infiniband/hw/ipath/ipath_dma.c
41426+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
41427@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
41428 }
41429
41430 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
41431- ipath_mapping_error,
41432- ipath_dma_map_single,
41433- ipath_dma_unmap_single,
41434- ipath_dma_map_page,
41435- ipath_dma_unmap_page,
41436- ipath_map_sg,
41437- ipath_unmap_sg,
41438- ipath_sg_dma_address,
41439- ipath_sg_dma_len,
41440- ipath_sync_single_for_cpu,
41441- ipath_sync_single_for_device,
41442- ipath_dma_alloc_coherent,
41443- ipath_dma_free_coherent
41444+ .mapping_error = ipath_mapping_error,
41445+ .map_single = ipath_dma_map_single,
41446+ .unmap_single = ipath_dma_unmap_single,
41447+ .map_page = ipath_dma_map_page,
41448+ .unmap_page = ipath_dma_unmap_page,
41449+ .map_sg = ipath_map_sg,
41450+ .unmap_sg = ipath_unmap_sg,
41451+ .dma_address = ipath_sg_dma_address,
41452+ .dma_len = ipath_sg_dma_len,
41453+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
41454+ .sync_single_for_device = ipath_sync_single_for_device,
41455+ .alloc_coherent = ipath_dma_alloc_coherent,
41456+ .free_coherent = ipath_dma_free_coherent
41457 };
41458diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
41459index 79b3dbc..96e5fcc 100644
41460--- a/drivers/infiniband/hw/ipath/ipath_rc.c
41461+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
41462@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41463 struct ib_atomic_eth *ateth;
41464 struct ipath_ack_entry *e;
41465 u64 vaddr;
41466- atomic64_t *maddr;
41467+ atomic64_unchecked_t *maddr;
41468 u64 sdata;
41469 u32 rkey;
41470 u8 next;
41471@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41472 IB_ACCESS_REMOTE_ATOMIC)))
41473 goto nack_acc_unlck;
41474 /* Perform atomic OP and save result. */
41475- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41476+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41477 sdata = be64_to_cpu(ateth->swap_data);
41478 e = &qp->s_ack_queue[qp->r_head_ack_queue];
41479 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
41480- (u64) atomic64_add_return(sdata, maddr) - sdata :
41481+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41482 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41483 be64_to_cpu(ateth->compare_data),
41484 sdata);
41485diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
41486index 1f95bba..9530f87 100644
41487--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
41488+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
41489@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
41490 unsigned long flags;
41491 struct ib_wc wc;
41492 u64 sdata;
41493- atomic64_t *maddr;
41494+ atomic64_unchecked_t *maddr;
41495 enum ib_wc_status send_status;
41496
41497 /*
41498@@ -382,11 +382,11 @@ again:
41499 IB_ACCESS_REMOTE_ATOMIC)))
41500 goto acc_err;
41501 /* Perform atomic OP and save result. */
41502- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41503+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41504 sdata = wqe->wr.wr.atomic.compare_add;
41505 *(u64 *) sqp->s_sge.sge.vaddr =
41506 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
41507- (u64) atomic64_add_return(sdata, maddr) - sdata :
41508+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41509 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41510 sdata, wqe->wr.wr.atomic.swap);
41511 goto send_comp;
41512diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
41513index f2a3f48..673ec79 100644
41514--- a/drivers/infiniband/hw/mlx4/mad.c
41515+++ b/drivers/infiniband/hw/mlx4/mad.c
41516@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
41517
41518 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
41519 {
41520- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
41521+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
41522 cpu_to_be64(0xff00000000000000LL);
41523 }
41524
41525diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
41526index 25b2cdf..099ff97 100644
41527--- a/drivers/infiniband/hw/mlx4/mcg.c
41528+++ b/drivers/infiniband/hw/mlx4/mcg.c
41529@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
41530 {
41531 char name[20];
41532
41533- atomic_set(&ctx->tid, 0);
41534+ atomic_set_unchecked(&ctx->tid, 0);
41535 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
41536 ctx->mcg_wq = create_singlethread_workqueue(name);
41537 if (!ctx->mcg_wq)
41538diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41539index 036b663..c9a8c73 100644
41540--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
41541+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41542@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
41543 struct list_head mcg_mgid0_list;
41544 struct workqueue_struct *mcg_wq;
41545 struct mlx4_ib_demux_pv_ctx **tun;
41546- atomic_t tid;
41547+ atomic_unchecked_t tid;
41548 int flushing; /* flushing the work queue */
41549 };
41550
41551diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
41552index 9d3e5c1..6f166df 100644
41553--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
41554+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
41555@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
41556 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
41557 }
41558
41559-int mthca_QUERY_FW(struct mthca_dev *dev)
41560+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
41561 {
41562 struct mthca_mailbox *mailbox;
41563 u32 *outbox;
41564@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41565 CMD_TIME_CLASS_B);
41566 }
41567
41568-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41569+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41570 int num_mtt)
41571 {
41572 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
41573@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
41574 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
41575 }
41576
41577-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41578+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41579 int eq_num)
41580 {
41581 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
41582@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
41583 CMD_TIME_CLASS_B);
41584 }
41585
41586-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41587+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41588 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
41589 void *in_mad, void *response_mad)
41590 {
41591diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
41592index 87897b9..7e79542 100644
41593--- a/drivers/infiniband/hw/mthca/mthca_main.c
41594+++ b/drivers/infiniband/hw/mthca/mthca_main.c
41595@@ -692,7 +692,7 @@ err_close:
41596 return err;
41597 }
41598
41599-static int mthca_setup_hca(struct mthca_dev *dev)
41600+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
41601 {
41602 int err;
41603
41604diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41605index ed9a989..6aa5dc2 100644
41606--- a/drivers/infiniband/hw/mthca/mthca_mr.c
41607+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41608@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
41609 * through the bitmaps)
41610 */
41611
41612-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41613+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41614 {
41615 int o;
41616 int m;
41617@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41618 return key;
41619 }
41620
41621-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41622+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41623 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41624 {
41625 struct mthca_mailbox *mailbox;
41626@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
41627 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
41628 }
41629
41630-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41631+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41632 u64 *buffer_list, int buffer_size_shift,
41633 int list_len, u64 iova, u64 total_size,
41634 u32 access, struct mthca_mr *mr)
41635diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
41636index 5b71d43..35a9e14 100644
41637--- a/drivers/infiniband/hw/mthca/mthca_provider.c
41638+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
41639@@ -763,7 +763,7 @@ unlock:
41640 return 0;
41641 }
41642
41643-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41644+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41645 {
41646 struct mthca_dev *dev = to_mdev(ibcq->device);
41647 struct mthca_cq *cq = to_mcq(ibcq);
41648diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41649index 4291410..d2ab1fb 100644
41650--- a/drivers/infiniband/hw/nes/nes.c
41651+++ b/drivers/infiniband/hw/nes/nes.c
41652@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41653 LIST_HEAD(nes_adapter_list);
41654 static LIST_HEAD(nes_dev_list);
41655
41656-atomic_t qps_destroyed;
41657+atomic_unchecked_t qps_destroyed;
41658
41659 static unsigned int ee_flsh_adapter;
41660 static unsigned int sysfs_nonidx_addr;
41661@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41662 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41663 struct nes_adapter *nesadapter = nesdev->nesadapter;
41664
41665- atomic_inc(&qps_destroyed);
41666+ atomic_inc_unchecked(&qps_destroyed);
41667
41668 /* Free the control structures */
41669
41670diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41671index 33cc589..3bd6538 100644
41672--- a/drivers/infiniband/hw/nes/nes.h
41673+++ b/drivers/infiniband/hw/nes/nes.h
41674@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41675 extern unsigned int wqm_quanta;
41676 extern struct list_head nes_adapter_list;
41677
41678-extern atomic_t cm_connects;
41679-extern atomic_t cm_accepts;
41680-extern atomic_t cm_disconnects;
41681-extern atomic_t cm_closes;
41682-extern atomic_t cm_connecteds;
41683-extern atomic_t cm_connect_reqs;
41684-extern atomic_t cm_rejects;
41685-extern atomic_t mod_qp_timouts;
41686-extern atomic_t qps_created;
41687-extern atomic_t qps_destroyed;
41688-extern atomic_t sw_qps_destroyed;
41689+extern atomic_unchecked_t cm_connects;
41690+extern atomic_unchecked_t cm_accepts;
41691+extern atomic_unchecked_t cm_disconnects;
41692+extern atomic_unchecked_t cm_closes;
41693+extern atomic_unchecked_t cm_connecteds;
41694+extern atomic_unchecked_t cm_connect_reqs;
41695+extern atomic_unchecked_t cm_rejects;
41696+extern atomic_unchecked_t mod_qp_timouts;
41697+extern atomic_unchecked_t qps_created;
41698+extern atomic_unchecked_t qps_destroyed;
41699+extern atomic_unchecked_t sw_qps_destroyed;
41700 extern u32 mh_detected;
41701 extern u32 mh_pauses_sent;
41702 extern u32 cm_packets_sent;
41703@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41704 extern u32 cm_packets_received;
41705 extern u32 cm_packets_dropped;
41706 extern u32 cm_packets_retrans;
41707-extern atomic_t cm_listens_created;
41708-extern atomic_t cm_listens_destroyed;
41709+extern atomic_unchecked_t cm_listens_created;
41710+extern atomic_unchecked_t cm_listens_destroyed;
41711 extern u32 cm_backlog_drops;
41712-extern atomic_t cm_loopbacks;
41713-extern atomic_t cm_nodes_created;
41714-extern atomic_t cm_nodes_destroyed;
41715-extern atomic_t cm_accel_dropped_pkts;
41716-extern atomic_t cm_resets_recvd;
41717-extern atomic_t pau_qps_created;
41718-extern atomic_t pau_qps_destroyed;
41719+extern atomic_unchecked_t cm_loopbacks;
41720+extern atomic_unchecked_t cm_nodes_created;
41721+extern atomic_unchecked_t cm_nodes_destroyed;
41722+extern atomic_unchecked_t cm_accel_dropped_pkts;
41723+extern atomic_unchecked_t cm_resets_recvd;
41724+extern atomic_unchecked_t pau_qps_created;
41725+extern atomic_unchecked_t pau_qps_destroyed;
41726
41727 extern u32 int_mod_timer_init;
41728 extern u32 int_mod_cq_depth_256;
41729diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41730index 6b29249..461d143 100644
41731--- a/drivers/infiniband/hw/nes/nes_cm.c
41732+++ b/drivers/infiniband/hw/nes/nes_cm.c
41733@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41734 u32 cm_packets_retrans;
41735 u32 cm_packets_created;
41736 u32 cm_packets_received;
41737-atomic_t cm_listens_created;
41738-atomic_t cm_listens_destroyed;
41739+atomic_unchecked_t cm_listens_created;
41740+atomic_unchecked_t cm_listens_destroyed;
41741 u32 cm_backlog_drops;
41742-atomic_t cm_loopbacks;
41743-atomic_t cm_nodes_created;
41744-atomic_t cm_nodes_destroyed;
41745-atomic_t cm_accel_dropped_pkts;
41746-atomic_t cm_resets_recvd;
41747+atomic_unchecked_t cm_loopbacks;
41748+atomic_unchecked_t cm_nodes_created;
41749+atomic_unchecked_t cm_nodes_destroyed;
41750+atomic_unchecked_t cm_accel_dropped_pkts;
41751+atomic_unchecked_t cm_resets_recvd;
41752
41753 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41754 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41755@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
41756 /* instance of function pointers for client API */
41757 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
41758 static struct nes_cm_ops nes_cm_api = {
41759- mini_cm_accelerated,
41760- mini_cm_listen,
41761- mini_cm_del_listen,
41762- mini_cm_connect,
41763- mini_cm_close,
41764- mini_cm_accept,
41765- mini_cm_reject,
41766- mini_cm_recv_pkt,
41767- mini_cm_dealloc_core,
41768- mini_cm_get,
41769- mini_cm_set
41770+ .accelerated = mini_cm_accelerated,
41771+ .listen = mini_cm_listen,
41772+ .stop_listener = mini_cm_del_listen,
41773+ .connect = mini_cm_connect,
41774+ .close = mini_cm_close,
41775+ .accept = mini_cm_accept,
41776+ .reject = mini_cm_reject,
41777+ .recv_pkt = mini_cm_recv_pkt,
41778+ .destroy_cm_core = mini_cm_dealloc_core,
41779+ .get = mini_cm_get,
41780+ .set = mini_cm_set
41781 };
41782
41783 static struct nes_cm_core *g_cm_core;
41784
41785-atomic_t cm_connects;
41786-atomic_t cm_accepts;
41787-atomic_t cm_disconnects;
41788-atomic_t cm_closes;
41789-atomic_t cm_connecteds;
41790-atomic_t cm_connect_reqs;
41791-atomic_t cm_rejects;
41792+atomic_unchecked_t cm_connects;
41793+atomic_unchecked_t cm_accepts;
41794+atomic_unchecked_t cm_disconnects;
41795+atomic_unchecked_t cm_closes;
41796+atomic_unchecked_t cm_connecteds;
41797+atomic_unchecked_t cm_connect_reqs;
41798+atomic_unchecked_t cm_rejects;
41799
41800 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41801 {
41802@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41803 kfree(listener);
41804 listener = NULL;
41805 ret = 0;
41806- atomic_inc(&cm_listens_destroyed);
41807+ atomic_inc_unchecked(&cm_listens_destroyed);
41808 } else {
41809 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41810 }
41811@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41812 cm_node->rem_mac);
41813
41814 add_hte_node(cm_core, cm_node);
41815- atomic_inc(&cm_nodes_created);
41816+ atomic_inc_unchecked(&cm_nodes_created);
41817
41818 return cm_node;
41819 }
41820@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41821 }
41822
41823 atomic_dec(&cm_core->node_cnt);
41824- atomic_inc(&cm_nodes_destroyed);
41825+ atomic_inc_unchecked(&cm_nodes_destroyed);
41826 nesqp = cm_node->nesqp;
41827 if (nesqp) {
41828 nesqp->cm_node = NULL;
41829@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41830
41831 static void drop_packet(struct sk_buff *skb)
41832 {
41833- atomic_inc(&cm_accel_dropped_pkts);
41834+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41835 dev_kfree_skb_any(skb);
41836 }
41837
41838@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41839 {
41840
41841 int reset = 0; /* whether to send reset in case of err.. */
41842- atomic_inc(&cm_resets_recvd);
41843+ atomic_inc_unchecked(&cm_resets_recvd);
41844 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41845 " refcnt=%d\n", cm_node, cm_node->state,
41846 atomic_read(&cm_node->ref_count));
41847@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41848 rem_ref_cm_node(cm_node->cm_core, cm_node);
41849 return NULL;
41850 }
41851- atomic_inc(&cm_loopbacks);
41852+ atomic_inc_unchecked(&cm_loopbacks);
41853 loopbackremotenode->loopbackpartner = cm_node;
41854 loopbackremotenode->tcp_cntxt.rcv_wscale =
41855 NES_CM_DEFAULT_RCV_WND_SCALE;
41856@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
41857 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
41858 else {
41859 rem_ref_cm_node(cm_core, cm_node);
41860- atomic_inc(&cm_accel_dropped_pkts);
41861+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41862 dev_kfree_skb_any(skb);
41863 }
41864 break;
41865@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41866
41867 if ((cm_id) && (cm_id->event_handler)) {
41868 if (issue_disconn) {
41869- atomic_inc(&cm_disconnects);
41870+ atomic_inc_unchecked(&cm_disconnects);
41871 cm_event.event = IW_CM_EVENT_DISCONNECT;
41872 cm_event.status = disconn_status;
41873 cm_event.local_addr = cm_id->local_addr;
41874@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41875 }
41876
41877 if (issue_close) {
41878- atomic_inc(&cm_closes);
41879+ atomic_inc_unchecked(&cm_closes);
41880 nes_disconnect(nesqp, 1);
41881
41882 cm_id->provider_data = nesqp;
41883@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41884
41885 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
41886 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
41887- atomic_inc(&cm_accepts);
41888+ atomic_inc_unchecked(&cm_accepts);
41889
41890 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
41891 netdev_refcnt_read(nesvnic->netdev));
41892@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
41893 struct nes_cm_core *cm_core;
41894 u8 *start_buff;
41895
41896- atomic_inc(&cm_rejects);
41897+ atomic_inc_unchecked(&cm_rejects);
41898 cm_node = (struct nes_cm_node *)cm_id->provider_data;
41899 loopback = cm_node->loopbackpartner;
41900 cm_core = cm_node->cm_core;
41901@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41902 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
41903 ntohs(laddr->sin_port));
41904
41905- atomic_inc(&cm_connects);
41906+ atomic_inc_unchecked(&cm_connects);
41907 nesqp->active_conn = 1;
41908
41909 /* cache the cm_id in the qp */
41910@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
41911 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
41912 return err;
41913 }
41914- atomic_inc(&cm_listens_created);
41915+ atomic_inc_unchecked(&cm_listens_created);
41916 }
41917
41918 cm_id->add_ref(cm_id);
41919@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
41920
41921 if (nesqp->destroyed)
41922 return;
41923- atomic_inc(&cm_connecteds);
41924+ atomic_inc_unchecked(&cm_connecteds);
41925 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
41926 " local port 0x%04X. jiffies = %lu.\n",
41927 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
41928@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
41929
41930 cm_id->add_ref(cm_id);
41931 ret = cm_id->event_handler(cm_id, &cm_event);
41932- atomic_inc(&cm_closes);
41933+ atomic_inc_unchecked(&cm_closes);
41934 cm_event.event = IW_CM_EVENT_CLOSE;
41935 cm_event.status = 0;
41936 cm_event.provider_data = cm_id->provider_data;
41937@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
41938 return;
41939 cm_id = cm_node->cm_id;
41940
41941- atomic_inc(&cm_connect_reqs);
41942+ atomic_inc_unchecked(&cm_connect_reqs);
41943 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41944 cm_node, cm_id, jiffies);
41945
41946@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
41947 return;
41948 cm_id = cm_node->cm_id;
41949
41950- atomic_inc(&cm_connect_reqs);
41951+ atomic_inc_unchecked(&cm_connect_reqs);
41952 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41953 cm_node, cm_id, jiffies);
41954
41955diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
41956index 4166452..fc952c3 100644
41957--- a/drivers/infiniband/hw/nes/nes_mgt.c
41958+++ b/drivers/infiniband/hw/nes/nes_mgt.c
41959@@ -40,8 +40,8 @@
41960 #include "nes.h"
41961 #include "nes_mgt.h"
41962
41963-atomic_t pau_qps_created;
41964-atomic_t pau_qps_destroyed;
41965+atomic_unchecked_t pau_qps_created;
41966+atomic_unchecked_t pau_qps_destroyed;
41967
41968 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
41969 {
41970@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
41971 {
41972 struct sk_buff *skb;
41973 unsigned long flags;
41974- atomic_inc(&pau_qps_destroyed);
41975+ atomic_inc_unchecked(&pau_qps_destroyed);
41976
41977 /* Free packets that have not yet been forwarded */
41978 /* Lock is acquired by skb_dequeue when removing the skb */
41979@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
41980 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
41981 skb_queue_head_init(&nesqp->pau_list);
41982 spin_lock_init(&nesqp->pau_lock);
41983- atomic_inc(&pau_qps_created);
41984+ atomic_inc_unchecked(&pau_qps_created);
41985 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
41986 }
41987
41988diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
41989index 49eb511..a774366 100644
41990--- a/drivers/infiniband/hw/nes/nes_nic.c
41991+++ b/drivers/infiniband/hw/nes/nes_nic.c
41992@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
41993 target_stat_values[++index] = mh_detected;
41994 target_stat_values[++index] = mh_pauses_sent;
41995 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
41996- target_stat_values[++index] = atomic_read(&cm_connects);
41997- target_stat_values[++index] = atomic_read(&cm_accepts);
41998- target_stat_values[++index] = atomic_read(&cm_disconnects);
41999- target_stat_values[++index] = atomic_read(&cm_connecteds);
42000- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42001- target_stat_values[++index] = atomic_read(&cm_rejects);
42002- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42003- target_stat_values[++index] = atomic_read(&qps_created);
42004- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42005- target_stat_values[++index] = atomic_read(&qps_destroyed);
42006- target_stat_values[++index] = atomic_read(&cm_closes);
42007+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42008+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42009+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42010+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42011+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42012+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42013+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42014+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42015+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42016+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42017+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42018 target_stat_values[++index] = cm_packets_sent;
42019 target_stat_values[++index] = cm_packets_bounced;
42020 target_stat_values[++index] = cm_packets_created;
42021 target_stat_values[++index] = cm_packets_received;
42022 target_stat_values[++index] = cm_packets_dropped;
42023 target_stat_values[++index] = cm_packets_retrans;
42024- target_stat_values[++index] = atomic_read(&cm_listens_created);
42025- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42026+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42027+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42028 target_stat_values[++index] = cm_backlog_drops;
42029- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42030- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42031- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42032- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42033- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42034+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42035+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42036+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42037+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42038+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42039 target_stat_values[++index] = nesadapter->free_4kpbl;
42040 target_stat_values[++index] = nesadapter->free_256pbl;
42041 target_stat_values[++index] = int_mod_timer_init;
42042 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42043 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42044 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42045- target_stat_values[++index] = atomic_read(&pau_qps_created);
42046- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42047+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42048+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42049 }
42050
42051 /**
42052diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42053index 8308e36..ae0d3b5 100644
42054--- a/drivers/infiniband/hw/nes/nes_verbs.c
42055+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42056@@ -46,9 +46,9 @@
42057
42058 #include <rdma/ib_umem.h>
42059
42060-atomic_t mod_qp_timouts;
42061-atomic_t qps_created;
42062-atomic_t sw_qps_destroyed;
42063+atomic_unchecked_t mod_qp_timouts;
42064+atomic_unchecked_t qps_created;
42065+atomic_unchecked_t sw_qps_destroyed;
42066
42067 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42068
42069@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42070 if (init_attr->create_flags)
42071 return ERR_PTR(-EINVAL);
42072
42073- atomic_inc(&qps_created);
42074+ atomic_inc_unchecked(&qps_created);
42075 switch (init_attr->qp_type) {
42076 case IB_QPT_RC:
42077 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42078@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42079 struct iw_cm_event cm_event;
42080 int ret = 0;
42081
42082- atomic_inc(&sw_qps_destroyed);
42083+ atomic_inc_unchecked(&sw_qps_destroyed);
42084 nesqp->destroyed = 1;
42085
42086 /* Blow away the connection if it exists. */
42087diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42088index 1946101..09766d2 100644
42089--- a/drivers/infiniband/hw/qib/qib.h
42090+++ b/drivers/infiniband/hw/qib/qib.h
42091@@ -52,6 +52,7 @@
42092 #include <linux/kref.h>
42093 #include <linux/sched.h>
42094 #include <linux/kthread.h>
42095+#include <linux/slab.h>
42096
42097 #include "qib_common.h"
42098 #include "qib_verbs.h"
42099diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42100index 24c41ba..102d71f 100644
42101--- a/drivers/input/gameport/gameport.c
42102+++ b/drivers/input/gameport/gameport.c
42103@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42104 */
42105 static void gameport_init_port(struct gameport *gameport)
42106 {
42107- static atomic_t gameport_no = ATOMIC_INIT(0);
42108+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42109
42110 __module_get(THIS_MODULE);
42111
42112 mutex_init(&gameport->drv_mutex);
42113 device_initialize(&gameport->dev);
42114 dev_set_name(&gameport->dev, "gameport%lu",
42115- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42116+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42117 gameport->dev.bus = &gameport_bus;
42118 gameport->dev.release = gameport_release_port;
42119 if (gameport->parent)
42120diff --git a/drivers/input/input.c b/drivers/input/input.c
42121index d2965e4..f52b7d7 100644
42122--- a/drivers/input/input.c
42123+++ b/drivers/input/input.c
42124@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42125 */
42126 struct input_dev *input_allocate_device(void)
42127 {
42128- static atomic_t input_no = ATOMIC_INIT(0);
42129+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42130 struct input_dev *dev;
42131
42132 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42133@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42134 INIT_LIST_HEAD(&dev->node);
42135
42136 dev_set_name(&dev->dev, "input%ld",
42137- (unsigned long) atomic_inc_return(&input_no) - 1);
42138+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42139
42140 __module_get(THIS_MODULE);
42141 }
42142diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42143index 04c69af..5f92d00 100644
42144--- a/drivers/input/joystick/sidewinder.c
42145+++ b/drivers/input/joystick/sidewinder.c
42146@@ -30,6 +30,7 @@
42147 #include <linux/kernel.h>
42148 #include <linux/module.h>
42149 #include <linux/slab.h>
42150+#include <linux/sched.h>
42151 #include <linux/init.h>
42152 #include <linux/input.h>
42153 #include <linux/gameport.h>
42154diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42155index 75e3b10..fb390fd 100644
42156--- a/drivers/input/joystick/xpad.c
42157+++ b/drivers/input/joystick/xpad.c
42158@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42159
42160 static int xpad_led_probe(struct usb_xpad *xpad)
42161 {
42162- static atomic_t led_seq = ATOMIC_INIT(0);
42163+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42164 long led_no;
42165 struct xpad_led *led;
42166 struct led_classdev *led_cdev;
42167@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42168 if (!led)
42169 return -ENOMEM;
42170
42171- led_no = (long)atomic_inc_return(&led_seq) - 1;
42172+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42173
42174 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42175 led->xpad = xpad;
42176diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42177index e204f26..8459f15 100644
42178--- a/drivers/input/misc/ims-pcu.c
42179+++ b/drivers/input/misc/ims-pcu.c
42180@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42181
42182 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42183 {
42184- static atomic_t device_no = ATOMIC_INIT(0);
42185+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42186
42187 const struct ims_pcu_device_info *info;
42188 u8 device_id;
42189@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42190 }
42191
42192 /* Device appears to be operable, complete initialization */
42193- pcu->device_no = atomic_inc_return(&device_no) - 1;
42194+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42195
42196 error = ims_pcu_setup_backlight(pcu);
42197 if (error)
42198diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42199index 2f0b39d..7370f13 100644
42200--- a/drivers/input/mouse/psmouse.h
42201+++ b/drivers/input/mouse/psmouse.h
42202@@ -116,7 +116,7 @@ struct psmouse_attribute {
42203 ssize_t (*set)(struct psmouse *psmouse, void *data,
42204 const char *buf, size_t count);
42205 bool protect;
42206-};
42207+} __do_const;
42208 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42209
42210 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42211diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42212index 4c842c3..590b0bf 100644
42213--- a/drivers/input/mousedev.c
42214+++ b/drivers/input/mousedev.c
42215@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42216
42217 spin_unlock_irq(&client->packet_lock);
42218
42219- if (copy_to_user(buffer, data, count))
42220+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42221 return -EFAULT;
42222
42223 return count;
42224diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42225index 8f4c4ab..5fc8a45 100644
42226--- a/drivers/input/serio/serio.c
42227+++ b/drivers/input/serio/serio.c
42228@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42229 */
42230 static void serio_init_port(struct serio *serio)
42231 {
42232- static atomic_t serio_no = ATOMIC_INIT(0);
42233+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42234
42235 __module_get(THIS_MODULE);
42236
42237@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42238 mutex_init(&serio->drv_mutex);
42239 device_initialize(&serio->dev);
42240 dev_set_name(&serio->dev, "serio%ld",
42241- (long)atomic_inc_return(&serio_no) - 1);
42242+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42243 serio->dev.bus = &serio_bus;
42244 serio->dev.release = serio_release_port;
42245 serio->dev.groups = serio_device_attr_groups;
42246diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42247index 59df2e7..8f1cafb 100644
42248--- a/drivers/input/serio/serio_raw.c
42249+++ b/drivers/input/serio/serio_raw.c
42250@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42251
42252 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42253 {
42254- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42255+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42256 struct serio_raw *serio_raw;
42257 int err;
42258
42259@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42260 }
42261
42262 snprintf(serio_raw->name, sizeof(serio_raw->name),
42263- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42264+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42265 kref_init(&serio_raw->kref);
42266 INIT_LIST_HEAD(&serio_raw->client_list);
42267 init_waitqueue_head(&serio_raw->wait);
42268diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42269index e5555fc..937986d 100644
42270--- a/drivers/iommu/iommu.c
42271+++ b/drivers/iommu/iommu.c
42272@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42273 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42274 {
42275 bus_register_notifier(bus, &iommu_bus_nb);
42276- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42277+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42278 }
42279
42280 /**
42281diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42282index 39f81ae..2660096 100644
42283--- a/drivers/iommu/irq_remapping.c
42284+++ b/drivers/iommu/irq_remapping.c
42285@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42286 void panic_if_irq_remap(const char *msg)
42287 {
42288 if (irq_remapping_enabled)
42289- panic(msg);
42290+ panic("%s", msg);
42291 }
42292
42293 static void ir_ack_apic_edge(struct irq_data *data)
42294@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42295
42296 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42297 {
42298- chip->irq_print_chip = ir_print_prefix;
42299- chip->irq_ack = ir_ack_apic_edge;
42300- chip->irq_eoi = ir_ack_apic_level;
42301- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42302+ pax_open_kernel();
42303+ *(void **)&chip->irq_print_chip = ir_print_prefix;
42304+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
42305+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
42306+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42307+ pax_close_kernel();
42308 }
42309
42310 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42311diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42312index 341c601..e5f407e 100644
42313--- a/drivers/irqchip/irq-gic.c
42314+++ b/drivers/irqchip/irq-gic.c
42315@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42316 * Supported arch specific GIC irq extension.
42317 * Default make them NULL.
42318 */
42319-struct irq_chip gic_arch_extn = {
42320+irq_chip_no_const gic_arch_extn = {
42321 .irq_eoi = NULL,
42322 .irq_mask = NULL,
42323 .irq_unmask = NULL,
42324@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42325 chained_irq_exit(chip, desc);
42326 }
42327
42328-static struct irq_chip gic_chip = {
42329+static irq_chip_no_const gic_chip __read_only = {
42330 .name = "GIC",
42331 .irq_mask = gic_mask_irq,
42332 .irq_unmask = gic_unmask_irq,
42333diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
42334index ac6f72b..81150f2 100644
42335--- a/drivers/isdn/capi/capi.c
42336+++ b/drivers/isdn/capi/capi.c
42337@@ -81,8 +81,8 @@ struct capiminor {
42338
42339 struct capi20_appl *ap;
42340 u32 ncci;
42341- atomic_t datahandle;
42342- atomic_t msgid;
42343+ atomic_unchecked_t datahandle;
42344+ atomic_unchecked_t msgid;
42345
42346 struct tty_port port;
42347 int ttyinstop;
42348@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
42349 capimsg_setu16(s, 2, mp->ap->applid);
42350 capimsg_setu8 (s, 4, CAPI_DATA_B3);
42351 capimsg_setu8 (s, 5, CAPI_RESP);
42352- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
42353+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
42354 capimsg_setu32(s, 8, mp->ncci);
42355 capimsg_setu16(s, 12, datahandle);
42356 }
42357@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
42358 mp->outbytes -= len;
42359 spin_unlock_bh(&mp->outlock);
42360
42361- datahandle = atomic_inc_return(&mp->datahandle);
42362+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
42363 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
42364 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42365 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42366 capimsg_setu16(skb->data, 2, mp->ap->applid);
42367 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
42368 capimsg_setu8 (skb->data, 5, CAPI_REQ);
42369- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
42370+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
42371 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
42372 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
42373 capimsg_setu16(skb->data, 16, len); /* Data length */
42374diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
42375index c44950d..10ac276 100644
42376--- a/drivers/isdn/gigaset/bas-gigaset.c
42377+++ b/drivers/isdn/gigaset/bas-gigaset.c
42378@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
42379
42380
42381 static const struct gigaset_ops gigops = {
42382- gigaset_write_cmd,
42383- gigaset_write_room,
42384- gigaset_chars_in_buffer,
42385- gigaset_brkchars,
42386- gigaset_init_bchannel,
42387- gigaset_close_bchannel,
42388- gigaset_initbcshw,
42389- gigaset_freebcshw,
42390- gigaset_reinitbcshw,
42391- gigaset_initcshw,
42392- gigaset_freecshw,
42393- gigaset_set_modem_ctrl,
42394- gigaset_baud_rate,
42395- gigaset_set_line_ctrl,
42396- gigaset_isoc_send_skb,
42397- gigaset_isoc_input,
42398+ .write_cmd = gigaset_write_cmd,
42399+ .write_room = gigaset_write_room,
42400+ .chars_in_buffer = gigaset_chars_in_buffer,
42401+ .brkchars = gigaset_brkchars,
42402+ .init_bchannel = gigaset_init_bchannel,
42403+ .close_bchannel = gigaset_close_bchannel,
42404+ .initbcshw = gigaset_initbcshw,
42405+ .freebcshw = gigaset_freebcshw,
42406+ .reinitbcshw = gigaset_reinitbcshw,
42407+ .initcshw = gigaset_initcshw,
42408+ .freecshw = gigaset_freecshw,
42409+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42410+ .baud_rate = gigaset_baud_rate,
42411+ .set_line_ctrl = gigaset_set_line_ctrl,
42412+ .send_skb = gigaset_isoc_send_skb,
42413+ .handle_input = gigaset_isoc_input,
42414 };
42415
42416 /* bas_gigaset_init
42417diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
42418index 600c79b..3752bab 100644
42419--- a/drivers/isdn/gigaset/interface.c
42420+++ b/drivers/isdn/gigaset/interface.c
42421@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
42422 }
42423 tty->driver_data = cs;
42424
42425- ++cs->port.count;
42426+ atomic_inc(&cs->port.count);
42427
42428- if (cs->port.count == 1) {
42429+ if (atomic_read(&cs->port.count) == 1) {
42430 tty_port_tty_set(&cs->port, tty);
42431 cs->port.low_latency = 1;
42432 }
42433@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
42434
42435 if (!cs->connected)
42436 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
42437- else if (!cs->port.count)
42438+ else if (!atomic_read(&cs->port.count))
42439 dev_warn(cs->dev, "%s: device not opened\n", __func__);
42440- else if (!--cs->port.count)
42441+ else if (!atomic_dec_return(&cs->port.count))
42442 tty_port_tty_set(&cs->port, NULL);
42443
42444 mutex_unlock(&cs->mutex);
42445diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
42446index 8c91fd5..14f13ce 100644
42447--- a/drivers/isdn/gigaset/ser-gigaset.c
42448+++ b/drivers/isdn/gigaset/ser-gigaset.c
42449@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
42450 }
42451
42452 static const struct gigaset_ops ops = {
42453- gigaset_write_cmd,
42454- gigaset_write_room,
42455- gigaset_chars_in_buffer,
42456- gigaset_brkchars,
42457- gigaset_init_bchannel,
42458- gigaset_close_bchannel,
42459- gigaset_initbcshw,
42460- gigaset_freebcshw,
42461- gigaset_reinitbcshw,
42462- gigaset_initcshw,
42463- gigaset_freecshw,
42464- gigaset_set_modem_ctrl,
42465- gigaset_baud_rate,
42466- gigaset_set_line_ctrl,
42467- gigaset_m10x_send_skb, /* asyncdata.c */
42468- gigaset_m10x_input, /* asyncdata.c */
42469+ .write_cmd = gigaset_write_cmd,
42470+ .write_room = gigaset_write_room,
42471+ .chars_in_buffer = gigaset_chars_in_buffer,
42472+ .brkchars = gigaset_brkchars,
42473+ .init_bchannel = gigaset_init_bchannel,
42474+ .close_bchannel = gigaset_close_bchannel,
42475+ .initbcshw = gigaset_initbcshw,
42476+ .freebcshw = gigaset_freebcshw,
42477+ .reinitbcshw = gigaset_reinitbcshw,
42478+ .initcshw = gigaset_initcshw,
42479+ .freecshw = gigaset_freecshw,
42480+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42481+ .baud_rate = gigaset_baud_rate,
42482+ .set_line_ctrl = gigaset_set_line_ctrl,
42483+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
42484+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
42485 };
42486
42487
42488diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
42489index d0a41cb..b953e50 100644
42490--- a/drivers/isdn/gigaset/usb-gigaset.c
42491+++ b/drivers/isdn/gigaset/usb-gigaset.c
42492@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
42493 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
42494 memcpy(cs->hw.usb->bchars, buf, 6);
42495 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
42496- 0, 0, &buf, 6, 2000);
42497+ 0, 0, buf, 6, 2000);
42498 }
42499
42500 static void gigaset_freebcshw(struct bc_state *bcs)
42501@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
42502 }
42503
42504 static const struct gigaset_ops ops = {
42505- gigaset_write_cmd,
42506- gigaset_write_room,
42507- gigaset_chars_in_buffer,
42508- gigaset_brkchars,
42509- gigaset_init_bchannel,
42510- gigaset_close_bchannel,
42511- gigaset_initbcshw,
42512- gigaset_freebcshw,
42513- gigaset_reinitbcshw,
42514- gigaset_initcshw,
42515- gigaset_freecshw,
42516- gigaset_set_modem_ctrl,
42517- gigaset_baud_rate,
42518- gigaset_set_line_ctrl,
42519- gigaset_m10x_send_skb,
42520- gigaset_m10x_input,
42521+ .write_cmd = gigaset_write_cmd,
42522+ .write_room = gigaset_write_room,
42523+ .chars_in_buffer = gigaset_chars_in_buffer,
42524+ .brkchars = gigaset_brkchars,
42525+ .init_bchannel = gigaset_init_bchannel,
42526+ .close_bchannel = gigaset_close_bchannel,
42527+ .initbcshw = gigaset_initbcshw,
42528+ .freebcshw = gigaset_freebcshw,
42529+ .reinitbcshw = gigaset_reinitbcshw,
42530+ .initcshw = gigaset_initcshw,
42531+ .freecshw = gigaset_freecshw,
42532+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42533+ .baud_rate = gigaset_baud_rate,
42534+ .set_line_ctrl = gigaset_set_line_ctrl,
42535+ .send_skb = gigaset_m10x_send_skb,
42536+ .handle_input = gigaset_m10x_input,
42537 };
42538
42539 /*
42540diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
42541index 4d9b195..455075c 100644
42542--- a/drivers/isdn/hardware/avm/b1.c
42543+++ b/drivers/isdn/hardware/avm/b1.c
42544@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
42545 }
42546 if (left) {
42547 if (t4file->user) {
42548- if (copy_from_user(buf, dp, left))
42549+ if (left > sizeof buf || copy_from_user(buf, dp, left))
42550 return -EFAULT;
42551 } else {
42552 memcpy(buf, dp, left);
42553@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
42554 }
42555 if (left) {
42556 if (config->user) {
42557- if (copy_from_user(buf, dp, left))
42558+ if (left > sizeof buf || copy_from_user(buf, dp, left))
42559 return -EFAULT;
42560 } else {
42561 memcpy(buf, dp, left);
42562diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42563index 9bb12ba..d4262f7 100644
42564--- a/drivers/isdn/i4l/isdn_common.c
42565+++ b/drivers/isdn/i4l/isdn_common.c
42566@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42567 } else
42568 return -EINVAL;
42569 case IIOCDBGVAR:
42570+ if (!capable(CAP_SYS_RAWIO))
42571+ return -EPERM;
42572 if (arg) {
42573 if (copy_to_user(argp, &dev, sizeof(ulong)))
42574 return -EFAULT;
42575diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
42576index 91d5730..336523e 100644
42577--- a/drivers/isdn/i4l/isdn_concap.c
42578+++ b/drivers/isdn/i4l/isdn_concap.c
42579@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
42580 }
42581
42582 struct concap_device_ops isdn_concap_reliable_dl_dops = {
42583- &isdn_concap_dl_data_req,
42584- &isdn_concap_dl_connect_req,
42585- &isdn_concap_dl_disconn_req
42586+ .data_req = &isdn_concap_dl_data_req,
42587+ .connect_req = &isdn_concap_dl_connect_req,
42588+ .disconn_req = &isdn_concap_dl_disconn_req
42589 };
42590
42591 /* The following should better go into a dedicated source file such that
42592diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42593index 3c5f249..5fac4d0 100644
42594--- a/drivers/isdn/i4l/isdn_tty.c
42595+++ b/drivers/isdn/i4l/isdn_tty.c
42596@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42597
42598 #ifdef ISDN_DEBUG_MODEM_OPEN
42599 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42600- port->count);
42601+ atomic_read(&port->count));
42602 #endif
42603- port->count++;
42604+ atomic_inc(&port->count);
42605 port->tty = tty;
42606 /*
42607 * Start up serial port
42608@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42609 #endif
42610 return;
42611 }
42612- if ((tty->count == 1) && (port->count != 1)) {
42613+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42614 /*
42615 * Uh, oh. tty->count is 1, which means that the tty
42616 * structure will be freed. Info->count should always
42617@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42618 * serial port won't be shutdown.
42619 */
42620 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42621- "info->count is %d\n", port->count);
42622- port->count = 1;
42623+ "info->count is %d\n", atomic_read(&port->count));
42624+ atomic_set(&port->count, 1);
42625 }
42626- if (--port->count < 0) {
42627+ if (atomic_dec_return(&port->count) < 0) {
42628 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42629- info->line, port->count);
42630- port->count = 0;
42631+ info->line, atomic_read(&port->count));
42632+ atomic_set(&port->count, 0);
42633 }
42634- if (port->count) {
42635+ if (atomic_read(&port->count)) {
42636 #ifdef ISDN_DEBUG_MODEM_OPEN
42637 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42638 #endif
42639@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42640 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42641 return;
42642 isdn_tty_shutdown(info);
42643- port->count = 0;
42644+ atomic_set(&port->count, 0);
42645 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42646 port->tty = NULL;
42647 wake_up_interruptible(&port->open_wait);
42648@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42649 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42650 modem_info *info = &dev->mdm.info[i];
42651
42652- if (info->port.count == 0)
42653+ if (atomic_read(&info->port.count) == 0)
42654 continue;
42655 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42656 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42657diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
42658index e2d4e58..40cd045 100644
42659--- a/drivers/isdn/i4l/isdn_x25iface.c
42660+++ b/drivers/isdn/i4l/isdn_x25iface.c
42661@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
42662
42663
42664 static struct concap_proto_ops ix25_pops = {
42665- &isdn_x25iface_proto_new,
42666- &isdn_x25iface_proto_del,
42667- &isdn_x25iface_proto_restart,
42668- &isdn_x25iface_proto_close,
42669- &isdn_x25iface_xmit,
42670- &isdn_x25iface_receive,
42671- &isdn_x25iface_connect_ind,
42672- &isdn_x25iface_disconn_ind
42673+ .proto_new = &isdn_x25iface_proto_new,
42674+ .proto_del = &isdn_x25iface_proto_del,
42675+ .restart = &isdn_x25iface_proto_restart,
42676+ .close = &isdn_x25iface_proto_close,
42677+ .encap_and_xmit = &isdn_x25iface_xmit,
42678+ .data_ind = &isdn_x25iface_receive,
42679+ .connect_ind = &isdn_x25iface_connect_ind,
42680+ .disconn_ind = &isdn_x25iface_disconn_ind
42681 };
42682
42683 /* error message helper function */
42684diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42685index 53d487f..f020f41 100644
42686--- a/drivers/isdn/icn/icn.c
42687+++ b/drivers/isdn/icn/icn.c
42688@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42689 if (count > len)
42690 count = len;
42691 if (user) {
42692- if (copy_from_user(msg, buf, count))
42693+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42694 return -EFAULT;
42695 } else
42696 memcpy(msg, buf, count);
42697diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
42698index a4f05c5..1433bc5 100644
42699--- a/drivers/isdn/mISDN/dsp_cmx.c
42700+++ b/drivers/isdn/mISDN/dsp_cmx.c
42701@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
42702 static u16 dsp_count; /* last sample count */
42703 static int dsp_count_valid; /* if we have last sample count */
42704
42705-void
42706+void __intentional_overflow(-1)
42707 dsp_cmx_send(void *arg)
42708 {
42709 struct dsp_conf *conf;
42710diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42711index d93e245..e7ece6b 100644
42712--- a/drivers/leds/leds-clevo-mail.c
42713+++ b/drivers/leds/leds-clevo-mail.c
42714@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42715 * detected as working, but in reality it is not) as low as
42716 * possible.
42717 */
42718-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
42719+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
42720 {
42721 .callback = clevo_mail_led_dmi_callback,
42722 .ident = "Clevo D410J",
42723diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42724index 5b8f938..b73d657 100644
42725--- a/drivers/leds/leds-ss4200.c
42726+++ b/drivers/leds/leds-ss4200.c
42727@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42728 * detected as working, but in reality it is not) as low as
42729 * possible.
42730 */
42731-static struct dmi_system_id nas_led_whitelist[] __initdata = {
42732+static struct dmi_system_id nas_led_whitelist[] __initconst = {
42733 {
42734 .callback = ss4200_led_dmi_callback,
42735 .ident = "Intel SS4200-E",
42736diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42737index 0bf1e4e..b4bf44e 100644
42738--- a/drivers/lguest/core.c
42739+++ b/drivers/lguest/core.c
42740@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42741 * The end address needs +1 because __get_vm_area allocates an
42742 * extra guard page, so we need space for that.
42743 */
42744+
42745+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42746+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42747+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42748+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42749+#else
42750 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42751 VM_ALLOC, switcher_addr, switcher_addr
42752 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42753+#endif
42754+
42755 if (!switcher_vma) {
42756 err = -ENOMEM;
42757 printk("lguest: could not map switcher pages high\n");
42758@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42759 * Now the Switcher is mapped at the right address, we can't fail!
42760 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42761 */
42762- memcpy(switcher_vma->addr, start_switcher_text,
42763+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42764 end_switcher_text - start_switcher_text);
42765
42766 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42767diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42768index bfb39bb..08a603b 100644
42769--- a/drivers/lguest/page_tables.c
42770+++ b/drivers/lguest/page_tables.c
42771@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42772 /*:*/
42773
42774 #ifdef CONFIG_X86_PAE
42775-static void release_pmd(pmd_t *spmd)
42776+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42777 {
42778 /* If the entry's not present, there's nothing to release. */
42779 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42780diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42781index 922a1ac..9dd0c2a 100644
42782--- a/drivers/lguest/x86/core.c
42783+++ b/drivers/lguest/x86/core.c
42784@@ -59,7 +59,7 @@ static struct {
42785 /* Offset from where switcher.S was compiled to where we've copied it */
42786 static unsigned long switcher_offset(void)
42787 {
42788- return switcher_addr - (unsigned long)start_switcher_text;
42789+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42790 }
42791
42792 /* This cpu's struct lguest_pages (after the Switcher text page) */
42793@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42794 * These copies are pretty cheap, so we do them unconditionally: */
42795 /* Save the current Host top-level page directory.
42796 */
42797+
42798+#ifdef CONFIG_PAX_PER_CPU_PGD
42799+ pages->state.host_cr3 = read_cr3();
42800+#else
42801 pages->state.host_cr3 = __pa(current->mm->pgd);
42802+#endif
42803+
42804 /*
42805 * Set up the Guest's page tables to see this CPU's pages (and no
42806 * other CPU's pages).
42807@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
42808 * compiled-in switcher code and the high-mapped copy we just made.
42809 */
42810 for (i = 0; i < IDT_ENTRIES; i++)
42811- default_idt_entries[i] += switcher_offset();
42812+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42813
42814 /*
42815 * Set up the Switcher's per-cpu areas.
42816@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
42817 * it will be undisturbed when we switch. To change %cs and jump we
42818 * need this structure to feed to Intel's "lcall" instruction.
42819 */
42820- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42821+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42822 lguest_entry.segment = LGUEST_CS;
42823
42824 /*
42825diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42826index 40634b0..4f5855e 100644
42827--- a/drivers/lguest/x86/switcher_32.S
42828+++ b/drivers/lguest/x86/switcher_32.S
42829@@ -87,6 +87,7 @@
42830 #include <asm/page.h>
42831 #include <asm/segment.h>
42832 #include <asm/lguest.h>
42833+#include <asm/processor-flags.h>
42834
42835 // We mark the start of the code to copy
42836 // It's placed in .text tho it's never run here
42837@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42838 // Changes type when we load it: damn Intel!
42839 // For after we switch over our page tables
42840 // That entry will be read-only: we'd crash.
42841+
42842+#ifdef CONFIG_PAX_KERNEXEC
42843+ mov %cr0, %edx
42844+ xor $X86_CR0_WP, %edx
42845+ mov %edx, %cr0
42846+#endif
42847+
42848 movl $(GDT_ENTRY_TSS*8), %edx
42849 ltr %dx
42850
42851@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42852 // Let's clear it again for our return.
42853 // The GDT descriptor of the Host
42854 // Points to the table after two "size" bytes
42855- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42856+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42857 // Clear "used" from type field (byte 5, bit 2)
42858- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42859+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42860+
42861+#ifdef CONFIG_PAX_KERNEXEC
42862+ mov %cr0, %eax
42863+ xor $X86_CR0_WP, %eax
42864+ mov %eax, %cr0
42865+#endif
42866
42867 // Once our page table's switched, the Guest is live!
42868 // The Host fades as we run this final step.
42869@@ -295,13 +309,12 @@ deliver_to_host:
42870 // I consulted gcc, and it gave
42871 // These instructions, which I gladly credit:
42872 leal (%edx,%ebx,8), %eax
42873- movzwl (%eax),%edx
42874- movl 4(%eax), %eax
42875- xorw %ax, %ax
42876- orl %eax, %edx
42877+ movl 4(%eax), %edx
42878+ movw (%eax), %dx
42879 // Now the address of the handler's in %edx
42880 // We call it now: its "iret" drops us home.
42881- jmp *%edx
42882+ ljmp $__KERNEL_CS, $1f
42883+1: jmp *%edx
42884
42885 // Every interrupt can come to us here
42886 // But we must truly tell each apart.
42887diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42888index 9762f1b..3e79734 100644
42889--- a/drivers/md/bcache/closure.h
42890+++ b/drivers/md/bcache/closure.h
42891@@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
42892 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42893 struct workqueue_struct *wq)
42894 {
42895- BUG_ON(object_is_on_stack(cl));
42896+ BUG_ON(object_starts_on_stack(cl));
42897 closure_set_ip(cl);
42898 cl->fn = fn;
42899 cl->wq = wq;
42900diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42901index 12dc29b..1596277 100644
42902--- a/drivers/md/bitmap.c
42903+++ b/drivers/md/bitmap.c
42904@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42905 chunk_kb ? "KB" : "B");
42906 if (bitmap->storage.file) {
42907 seq_printf(seq, ", file: ");
42908- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42909+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42910 }
42911
42912 seq_printf(seq, "\n");
42913diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42914index 5152142..623d141 100644
42915--- a/drivers/md/dm-ioctl.c
42916+++ b/drivers/md/dm-ioctl.c
42917@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42918 cmd == DM_LIST_VERSIONS_CMD)
42919 return 0;
42920
42921- if ((cmd == DM_DEV_CREATE_CMD)) {
42922+ if (cmd == DM_DEV_CREATE_CMD) {
42923 if (!*param->name) {
42924 DMWARN("name not supplied when creating device");
42925 return -EINVAL;
42926diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42927index 9584443..9fc9ac9 100644
42928--- a/drivers/md/dm-raid1.c
42929+++ b/drivers/md/dm-raid1.c
42930@@ -40,7 +40,7 @@ enum dm_raid1_error {
42931
42932 struct mirror {
42933 struct mirror_set *ms;
42934- atomic_t error_count;
42935+ atomic_unchecked_t error_count;
42936 unsigned long error_type;
42937 struct dm_dev *dev;
42938 sector_t offset;
42939@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42940 struct mirror *m;
42941
42942 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42943- if (!atomic_read(&m->error_count))
42944+ if (!atomic_read_unchecked(&m->error_count))
42945 return m;
42946
42947 return NULL;
42948@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42949 * simple way to tell if a device has encountered
42950 * errors.
42951 */
42952- atomic_inc(&m->error_count);
42953+ atomic_inc_unchecked(&m->error_count);
42954
42955 if (test_and_set_bit(error_type, &m->error_type))
42956 return;
42957@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42958 struct mirror *m = get_default_mirror(ms);
42959
42960 do {
42961- if (likely(!atomic_read(&m->error_count)))
42962+ if (likely(!atomic_read_unchecked(&m->error_count)))
42963 return m;
42964
42965 if (m-- == ms->mirror)
42966@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42967 {
42968 struct mirror *default_mirror = get_default_mirror(m->ms);
42969
42970- return !atomic_read(&default_mirror->error_count);
42971+ return !atomic_read_unchecked(&default_mirror->error_count);
42972 }
42973
42974 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42975@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42976 */
42977 if (likely(region_in_sync(ms, region, 1)))
42978 m = choose_mirror(ms, bio->bi_sector);
42979- else if (m && atomic_read(&m->error_count))
42980+ else if (m && atomic_read_unchecked(&m->error_count))
42981 m = NULL;
42982
42983 if (likely(m))
42984@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42985 }
42986
42987 ms->mirror[mirror].ms = ms;
42988- atomic_set(&(ms->mirror[mirror].error_count), 0);
42989+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42990 ms->mirror[mirror].error_type = 0;
42991 ms->mirror[mirror].offset = offset;
42992
42993@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
42994 */
42995 static char device_status_char(struct mirror *m)
42996 {
42997- if (!atomic_read(&(m->error_count)))
42998+ if (!atomic_read_unchecked(&(m->error_count)))
42999 return 'A';
43000
43001 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43002diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43003index 28a9012..9c0f6a5 100644
43004--- a/drivers/md/dm-stats.c
43005+++ b/drivers/md/dm-stats.c
43006@@ -382,7 +382,7 @@ do_sync_free:
43007 synchronize_rcu_expedited();
43008 dm_stat_free(&s->rcu_head);
43009 } else {
43010- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43011+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43012 call_rcu(&s->rcu_head, dm_stat_free);
43013 }
43014 return 0;
43015@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43016 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43017 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43018 ));
43019- ACCESS_ONCE(last->last_sector) = end_sector;
43020- ACCESS_ONCE(last->last_rw) = bi_rw;
43021+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43022+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43023 }
43024
43025 rcu_read_lock();
43026diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43027index 73c1712..7347292 100644
43028--- a/drivers/md/dm-stripe.c
43029+++ b/drivers/md/dm-stripe.c
43030@@ -21,7 +21,7 @@ struct stripe {
43031 struct dm_dev *dev;
43032 sector_t physical_start;
43033
43034- atomic_t error_count;
43035+ atomic_unchecked_t error_count;
43036 };
43037
43038 struct stripe_c {
43039@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43040 kfree(sc);
43041 return r;
43042 }
43043- atomic_set(&(sc->stripe[i].error_count), 0);
43044+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43045 }
43046
43047 ti->private = sc;
43048@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43049 DMEMIT("%d ", sc->stripes);
43050 for (i = 0; i < sc->stripes; i++) {
43051 DMEMIT("%s ", sc->stripe[i].dev->name);
43052- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43053+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43054 'D' : 'A';
43055 }
43056 buffer[i] = '\0';
43057@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43058 */
43059 for (i = 0; i < sc->stripes; i++)
43060 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43061- atomic_inc(&(sc->stripe[i].error_count));
43062- if (atomic_read(&(sc->stripe[i].error_count)) <
43063+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43064+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43065 DM_IO_ERROR_THRESHOLD)
43066 schedule_work(&sc->trigger_event);
43067 }
43068diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43069index 3ba6a38..b0fa9b0 100644
43070--- a/drivers/md/dm-table.c
43071+++ b/drivers/md/dm-table.c
43072@@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43073 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43074 struct mapped_device *md)
43075 {
43076- static char *_claim_ptr = "I belong to device-mapper";
43077+ static char _claim_ptr[] = "I belong to device-mapper";
43078 struct block_device *bdev;
43079
43080 int r;
43081@@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43082 if (!dev_size)
43083 return 0;
43084
43085- if ((start >= dev_size) || (start + len > dev_size)) {
43086+ if ((start >= dev_size) || (len > dev_size - start)) {
43087 DMWARN("%s: %s too small for target: "
43088 "start=%llu, len=%llu, dev_size=%llu",
43089 dm_device_name(ti->table->md), bdevname(bdev, b),
43090diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43091index 8a30ad5..72792d3 100644
43092--- a/drivers/md/dm-thin-metadata.c
43093+++ b/drivers/md/dm-thin-metadata.c
43094@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43095 {
43096 pmd->info.tm = pmd->tm;
43097 pmd->info.levels = 2;
43098- pmd->info.value_type.context = pmd->data_sm;
43099+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43100 pmd->info.value_type.size = sizeof(__le64);
43101 pmd->info.value_type.inc = data_block_inc;
43102 pmd->info.value_type.dec = data_block_dec;
43103@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43104
43105 pmd->bl_info.tm = pmd->tm;
43106 pmd->bl_info.levels = 1;
43107- pmd->bl_info.value_type.context = pmd->data_sm;
43108+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43109 pmd->bl_info.value_type.size = sizeof(__le64);
43110 pmd->bl_info.value_type.inc = data_block_inc;
43111 pmd->bl_info.value_type.dec = data_block_dec;
43112diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43113index 0704c52..0a33d61 100644
43114--- a/drivers/md/dm.c
43115+++ b/drivers/md/dm.c
43116@@ -185,9 +185,9 @@ struct mapped_device {
43117 /*
43118 * Event handling.
43119 */
43120- atomic_t event_nr;
43121+ atomic_unchecked_t event_nr;
43122 wait_queue_head_t eventq;
43123- atomic_t uevent_seq;
43124+ atomic_unchecked_t uevent_seq;
43125 struct list_head uevent_list;
43126 spinlock_t uevent_lock; /* Protect access to uevent_list */
43127
43128@@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43129 spin_lock_init(&md->deferred_lock);
43130 atomic_set(&md->holders, 1);
43131 atomic_set(&md->open_count, 0);
43132- atomic_set(&md->event_nr, 0);
43133- atomic_set(&md->uevent_seq, 0);
43134+ atomic_set_unchecked(&md->event_nr, 0);
43135+ atomic_set_unchecked(&md->uevent_seq, 0);
43136 INIT_LIST_HEAD(&md->uevent_list);
43137 spin_lock_init(&md->uevent_lock);
43138
43139@@ -2175,7 +2175,7 @@ static void event_callback(void *context)
43140
43141 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43142
43143- atomic_inc(&md->event_nr);
43144+ atomic_inc_unchecked(&md->event_nr);
43145 wake_up(&md->eventq);
43146 }
43147
43148@@ -2868,18 +2868,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43149
43150 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43151 {
43152- return atomic_add_return(1, &md->uevent_seq);
43153+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43154 }
43155
43156 uint32_t dm_get_event_nr(struct mapped_device *md)
43157 {
43158- return atomic_read(&md->event_nr);
43159+ return atomic_read_unchecked(&md->event_nr);
43160 }
43161
43162 int dm_wait_event(struct mapped_device *md, int event_nr)
43163 {
43164 return wait_event_interruptible(md->eventq,
43165- (event_nr != atomic_read(&md->event_nr)));
43166+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43167 }
43168
43169 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43170diff --git a/drivers/md/md.c b/drivers/md/md.c
43171index 369d919..ba7049c 100644
43172--- a/drivers/md/md.c
43173+++ b/drivers/md/md.c
43174@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43175 * start build, activate spare
43176 */
43177 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43178-static atomic_t md_event_count;
43179+static atomic_unchecked_t md_event_count;
43180 void md_new_event(struct mddev *mddev)
43181 {
43182- atomic_inc(&md_event_count);
43183+ atomic_inc_unchecked(&md_event_count);
43184 wake_up(&md_event_waiters);
43185 }
43186 EXPORT_SYMBOL_GPL(md_new_event);
43187@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43188 */
43189 static void md_new_event_inintr(struct mddev *mddev)
43190 {
43191- atomic_inc(&md_event_count);
43192+ atomic_inc_unchecked(&md_event_count);
43193 wake_up(&md_event_waiters);
43194 }
43195
43196@@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43197 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43198 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43199 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43200- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43201+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43202
43203 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43204 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43205@@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43206 else
43207 sb->resync_offset = cpu_to_le64(0);
43208
43209- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43210+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43211
43212 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43213 sb->size = cpu_to_le64(mddev->dev_sectors);
43214@@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43215 static ssize_t
43216 errors_show(struct md_rdev *rdev, char *page)
43217 {
43218- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43219+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43220 }
43221
43222 static ssize_t
43223@@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43224 char *e;
43225 unsigned long n = simple_strtoul(buf, &e, 10);
43226 if (*buf && (*e == 0 || *e == '\n')) {
43227- atomic_set(&rdev->corrected_errors, n);
43228+ atomic_set_unchecked(&rdev->corrected_errors, n);
43229 return len;
43230 }
43231 return -EINVAL;
43232@@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43233 rdev->sb_loaded = 0;
43234 rdev->bb_page = NULL;
43235 atomic_set(&rdev->nr_pending, 0);
43236- atomic_set(&rdev->read_errors, 0);
43237- atomic_set(&rdev->corrected_errors, 0);
43238+ atomic_set_unchecked(&rdev->read_errors, 0);
43239+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43240
43241 INIT_LIST_HEAD(&rdev->same_set);
43242 init_waitqueue_head(&rdev->blocked_wait);
43243@@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43244
43245 spin_unlock(&pers_lock);
43246 seq_printf(seq, "\n");
43247- seq->poll_event = atomic_read(&md_event_count);
43248+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43249 return 0;
43250 }
43251 if (v == (void*)2) {
43252@@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43253 return error;
43254
43255 seq = file->private_data;
43256- seq->poll_event = atomic_read(&md_event_count);
43257+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43258 return error;
43259 }
43260
43261@@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43262 /* always allow read */
43263 mask = POLLIN | POLLRDNORM;
43264
43265- if (seq->poll_event != atomic_read(&md_event_count))
43266+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43267 mask |= POLLERR | POLLPRI;
43268 return mask;
43269 }
43270@@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43271 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43272 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43273 (int)part_stat_read(&disk->part0, sectors[1]) -
43274- atomic_read(&disk->sync_io);
43275+ atomic_read_unchecked(&disk->sync_io);
43276 /* sync IO will cause sync_io to increase before the disk_stats
43277 * as sync_io is counted when a request starts, and
43278 * disk_stats is counted when it completes.
43279diff --git a/drivers/md/md.h b/drivers/md/md.h
43280index 0095ec8..c89277a 100644
43281--- a/drivers/md/md.h
43282+++ b/drivers/md/md.h
43283@@ -94,13 +94,13 @@ struct md_rdev {
43284 * only maintained for arrays that
43285 * support hot removal
43286 */
43287- atomic_t read_errors; /* number of consecutive read errors that
43288+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
43289 * we have tried to ignore.
43290 */
43291 struct timespec last_read_error; /* monotonic time since our
43292 * last read error
43293 */
43294- atomic_t corrected_errors; /* number of corrected read errors,
43295+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43296 * for reporting to userspace and storing
43297 * in superblock.
43298 */
43299@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43300
43301 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43302 {
43303- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43304+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43305 }
43306
43307 struct md_personality
43308diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43309index 3e6d115..ffecdeb 100644
43310--- a/drivers/md/persistent-data/dm-space-map.h
43311+++ b/drivers/md/persistent-data/dm-space-map.h
43312@@ -71,6 +71,7 @@ struct dm_space_map {
43313 dm_sm_threshold_fn fn,
43314 void *context);
43315 };
43316+typedef struct dm_space_map __no_const dm_space_map_no_const;
43317
43318 /*----------------------------------------------------------------*/
43319
43320diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
43321index a49cfcc..20b9a65 100644
43322--- a/drivers/md/raid1.c
43323+++ b/drivers/md/raid1.c
43324@@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
43325 if (r1_sync_page_io(rdev, sect, s,
43326 bio->bi_io_vec[idx].bv_page,
43327 READ) != 0)
43328- atomic_add(s, &rdev->corrected_errors);
43329+ atomic_add_unchecked(s, &rdev->corrected_errors);
43330 }
43331 sectors -= s;
43332 sect += s;
43333@@ -2148,7 +2148,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
43334 test_bit(In_sync, &rdev->flags)) {
43335 if (r1_sync_page_io(rdev, sect, s,
43336 conf->tmppage, READ)) {
43337- atomic_add(s, &rdev->corrected_errors);
43338+ atomic_add_unchecked(s, &rdev->corrected_errors);
43339 printk(KERN_INFO
43340 "md/raid1:%s: read error corrected "
43341 "(%d sectors at %llu on %s)\n",
43342diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
43343index 06eeb99..770613e 100644
43344--- a/drivers/md/raid10.c
43345+++ b/drivers/md/raid10.c
43346@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
43347 /* The write handler will notice the lack of
43348 * R10BIO_Uptodate and record any errors etc
43349 */
43350- atomic_add(r10_bio->sectors,
43351+ atomic_add_unchecked(r10_bio->sectors,
43352 &conf->mirrors[d].rdev->corrected_errors);
43353
43354 /* for reconstruct, we always reschedule after a read.
43355@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43356 {
43357 struct timespec cur_time_mon;
43358 unsigned long hours_since_last;
43359- unsigned int read_errors = atomic_read(&rdev->read_errors);
43360+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
43361
43362 ktime_get_ts(&cur_time_mon);
43363
43364@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43365 * overflowing the shift of read_errors by hours_since_last.
43366 */
43367 if (hours_since_last >= 8 * sizeof(read_errors))
43368- atomic_set(&rdev->read_errors, 0);
43369+ atomic_set_unchecked(&rdev->read_errors, 0);
43370 else
43371- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
43372+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
43373 }
43374
43375 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
43376@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43377 return;
43378
43379 check_decay_read_errors(mddev, rdev);
43380- atomic_inc(&rdev->read_errors);
43381- if (atomic_read(&rdev->read_errors) > max_read_errors) {
43382+ atomic_inc_unchecked(&rdev->read_errors);
43383+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
43384 char b[BDEVNAME_SIZE];
43385 bdevname(rdev->bdev, b);
43386
43387@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43388 "md/raid10:%s: %s: Raid device exceeded "
43389 "read_error threshold [cur %d:max %d]\n",
43390 mdname(mddev), b,
43391- atomic_read(&rdev->read_errors), max_read_errors);
43392+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
43393 printk(KERN_NOTICE
43394 "md/raid10:%s: %s: Failing raid device\n",
43395 mdname(mddev), b);
43396@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43397 sect +
43398 choose_data_offset(r10_bio, rdev)),
43399 bdevname(rdev->bdev, b));
43400- atomic_add(s, &rdev->corrected_errors);
43401+ atomic_add_unchecked(s, &rdev->corrected_errors);
43402 }
43403
43404 rdev_dec_pending(rdev, mddev);
43405diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
43406index cbb1571..47952f5 100644
43407--- a/drivers/md/raid5.c
43408+++ b/drivers/md/raid5.c
43409@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
43410 mdname(conf->mddev), STRIPE_SECTORS,
43411 (unsigned long long)s,
43412 bdevname(rdev->bdev, b));
43413- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
43414+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
43415 clear_bit(R5_ReadError, &sh->dev[i].flags);
43416 clear_bit(R5_ReWrite, &sh->dev[i].flags);
43417 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
43418 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
43419
43420- if (atomic_read(&rdev->read_errors))
43421- atomic_set(&rdev->read_errors, 0);
43422+ if (atomic_read_unchecked(&rdev->read_errors))
43423+ atomic_set_unchecked(&rdev->read_errors, 0);
43424 } else {
43425 const char *bdn = bdevname(rdev->bdev, b);
43426 int retry = 0;
43427 int set_bad = 0;
43428
43429 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
43430- atomic_inc(&rdev->read_errors);
43431+ atomic_inc_unchecked(&rdev->read_errors);
43432 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
43433 printk_ratelimited(
43434 KERN_WARNING
43435@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
43436 mdname(conf->mddev),
43437 (unsigned long long)s,
43438 bdn);
43439- } else if (atomic_read(&rdev->read_errors)
43440+ } else if (atomic_read_unchecked(&rdev->read_errors)
43441 > conf->max_nr_stripes)
43442 printk(KERN_WARNING
43443 "md/raid:%s: Too many read errors, failing device %s.\n",
43444diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
43445index 983db75..ef9248c 100644
43446--- a/drivers/media/dvb-core/dvbdev.c
43447+++ b/drivers/media/dvb-core/dvbdev.c
43448@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
43449 const struct dvb_device *template, void *priv, int type)
43450 {
43451 struct dvb_device *dvbdev;
43452- struct file_operations *dvbdevfops;
43453+ file_operations_no_const *dvbdevfops;
43454 struct device *clsdev;
43455 int minor;
43456 int id;
43457diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
43458index 9b6c3bb..baeb5c7 100644
43459--- a/drivers/media/dvb-frontends/dib3000.h
43460+++ b/drivers/media/dvb-frontends/dib3000.h
43461@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
43462 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
43463 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
43464 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
43465-};
43466+} __no_const;
43467
43468 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
43469 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
43470diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
43471index ed8cb90..5ef7f79 100644
43472--- a/drivers/media/pci/cx88/cx88-video.c
43473+++ b/drivers/media/pci/cx88/cx88-video.c
43474@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
43475
43476 /* ------------------------------------------------------------------ */
43477
43478-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43479-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43480-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43481+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43482+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43483+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43484
43485 module_param_array(video_nr, int, NULL, 0444);
43486 module_param_array(vbi_nr, int, NULL, 0444);
43487diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
43488index 802642d..5534900 100644
43489--- a/drivers/media/pci/ivtv/ivtv-driver.c
43490+++ b/drivers/media/pci/ivtv/ivtv-driver.c
43491@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
43492 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
43493
43494 /* ivtv instance counter */
43495-static atomic_t ivtv_instance = ATOMIC_INIT(0);
43496+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
43497
43498 /* Parameter declarations */
43499 static int cardtype[IVTV_MAX_CARDS];
43500diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
43501index dfd0a21..6bbb465 100644
43502--- a/drivers/media/platform/omap/omap_vout.c
43503+++ b/drivers/media/platform/omap/omap_vout.c
43504@@ -63,7 +63,6 @@ enum omap_vout_channels {
43505 OMAP_VIDEO2,
43506 };
43507
43508-static struct videobuf_queue_ops video_vbq_ops;
43509 /* Variables configurable through module params*/
43510 static u32 video1_numbuffers = 3;
43511 static u32 video2_numbuffers = 3;
43512@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
43513 {
43514 struct videobuf_queue *q;
43515 struct omap_vout_device *vout = NULL;
43516+ static struct videobuf_queue_ops video_vbq_ops = {
43517+ .buf_setup = omap_vout_buffer_setup,
43518+ .buf_prepare = omap_vout_buffer_prepare,
43519+ .buf_release = omap_vout_buffer_release,
43520+ .buf_queue = omap_vout_buffer_queue,
43521+ };
43522
43523 vout = video_drvdata(file);
43524 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
43525@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
43526 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
43527
43528 q = &vout->vbq;
43529- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
43530- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
43531- video_vbq_ops.buf_release = omap_vout_buffer_release;
43532- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
43533 spin_lock_init(&vout->vbq_lock);
43534
43535 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
43536diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
43537index fb2acc5..a2fcbdc4 100644
43538--- a/drivers/media/platform/s5p-tv/mixer.h
43539+++ b/drivers/media/platform/s5p-tv/mixer.h
43540@@ -156,7 +156,7 @@ struct mxr_layer {
43541 /** layer index (unique identifier) */
43542 int idx;
43543 /** callbacks for layer methods */
43544- struct mxr_layer_ops ops;
43545+ struct mxr_layer_ops *ops;
43546 /** format array */
43547 const struct mxr_format **fmt_array;
43548 /** size of format array */
43549diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43550index 74344c7..a39e70e 100644
43551--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43552+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43553@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
43554 {
43555 struct mxr_layer *layer;
43556 int ret;
43557- struct mxr_layer_ops ops = {
43558+ static struct mxr_layer_ops ops = {
43559 .release = mxr_graph_layer_release,
43560 .buffer_set = mxr_graph_buffer_set,
43561 .stream_set = mxr_graph_stream_set,
43562diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
43563index b713403..53cb5ad 100644
43564--- a/drivers/media/platform/s5p-tv/mixer_reg.c
43565+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
43566@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
43567 layer->update_buf = next;
43568 }
43569
43570- layer->ops.buffer_set(layer, layer->update_buf);
43571+ layer->ops->buffer_set(layer, layer->update_buf);
43572
43573 if (done && done != layer->shadow_buf)
43574 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
43575diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
43576index 81b97db..b089ccd 100644
43577--- a/drivers/media/platform/s5p-tv/mixer_video.c
43578+++ b/drivers/media/platform/s5p-tv/mixer_video.c
43579@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
43580 layer->geo.src.height = layer->geo.src.full_height;
43581
43582 mxr_geometry_dump(mdev, &layer->geo);
43583- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43584+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43585 mxr_geometry_dump(mdev, &layer->geo);
43586 }
43587
43588@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43589 layer->geo.dst.full_width = mbus_fmt.width;
43590 layer->geo.dst.full_height = mbus_fmt.height;
43591 layer->geo.dst.field = mbus_fmt.field;
43592- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43593+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43594
43595 mxr_geometry_dump(mdev, &layer->geo);
43596 }
43597@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43598 /* set source size to highest accepted value */
43599 geo->src.full_width = max(geo->dst.full_width, pix->width);
43600 geo->src.full_height = max(geo->dst.full_height, pix->height);
43601- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43602+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43603 mxr_geometry_dump(mdev, &layer->geo);
43604 /* set cropping to total visible screen */
43605 geo->src.width = pix->width;
43606@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43607 geo->src.x_offset = 0;
43608 geo->src.y_offset = 0;
43609 /* assure consistency of geometry */
43610- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43611+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43612 mxr_geometry_dump(mdev, &layer->geo);
43613 /* set full size to lowest possible value */
43614 geo->src.full_width = 0;
43615 geo->src.full_height = 0;
43616- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43617+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43618 mxr_geometry_dump(mdev, &layer->geo);
43619
43620 /* returning results */
43621@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43622 target->width = s->r.width;
43623 target->height = s->r.height;
43624
43625- layer->ops.fix_geometry(layer, stage, s->flags);
43626+ layer->ops->fix_geometry(layer, stage, s->flags);
43627
43628 /* retrieve update selection rectangle */
43629 res.left = target->x_offset;
43630@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43631 mxr_output_get(mdev);
43632
43633 mxr_layer_update_output(layer);
43634- layer->ops.format_set(layer);
43635+ layer->ops->format_set(layer);
43636 /* enabling layer in hardware */
43637 spin_lock_irqsave(&layer->enq_slock, flags);
43638 layer->state = MXR_LAYER_STREAMING;
43639 spin_unlock_irqrestore(&layer->enq_slock, flags);
43640
43641- layer->ops.stream_set(layer, MXR_ENABLE);
43642+ layer->ops->stream_set(layer, MXR_ENABLE);
43643 mxr_streamer_get(mdev);
43644
43645 return 0;
43646@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43647 spin_unlock_irqrestore(&layer->enq_slock, flags);
43648
43649 /* disabling layer in hardware */
43650- layer->ops.stream_set(layer, MXR_DISABLE);
43651+ layer->ops->stream_set(layer, MXR_DISABLE);
43652 /* remove one streamer */
43653 mxr_streamer_put(mdev);
43654 /* allow changes in output configuration */
43655@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43656
43657 void mxr_layer_release(struct mxr_layer *layer)
43658 {
43659- if (layer->ops.release)
43660- layer->ops.release(layer);
43661+ if (layer->ops->release)
43662+ layer->ops->release(layer);
43663 }
43664
43665 void mxr_base_layer_release(struct mxr_layer *layer)
43666@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43667
43668 layer->mdev = mdev;
43669 layer->idx = idx;
43670- layer->ops = *ops;
43671+ layer->ops = ops;
43672
43673 spin_lock_init(&layer->enq_slock);
43674 INIT_LIST_HEAD(&layer->enq_list);
43675diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43676index c9388c4..ce71ece 100644
43677--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43678+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43679@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43680 {
43681 struct mxr_layer *layer;
43682 int ret;
43683- struct mxr_layer_ops ops = {
43684+ static struct mxr_layer_ops ops = {
43685 .release = mxr_vp_layer_release,
43686 .buffer_set = mxr_vp_buffer_set,
43687 .stream_set = mxr_vp_stream_set,
43688diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
43689index 2d4e73b..8b4d5b6 100644
43690--- a/drivers/media/platform/vivi.c
43691+++ b/drivers/media/platform/vivi.c
43692@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
43693 MODULE_LICENSE("Dual BSD/GPL");
43694 MODULE_VERSION(VIVI_VERSION);
43695
43696-static unsigned video_nr = -1;
43697-module_param(video_nr, uint, 0644);
43698+static int video_nr = -1;
43699+module_param(video_nr, int, 0644);
43700 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
43701
43702 static unsigned n_devs = 1;
43703diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43704index 545c04c..a14bded 100644
43705--- a/drivers/media/radio/radio-cadet.c
43706+++ b/drivers/media/radio/radio-cadet.c
43707@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43708 unsigned char readbuf[RDS_BUFFER];
43709 int i = 0;
43710
43711+ if (count > RDS_BUFFER)
43712+ return -EFAULT;
43713 mutex_lock(&dev->lock);
43714 if (dev->rdsstat == 0)
43715 cadet_start_rds(dev);
43716@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43717 while (i < count && dev->rdsin != dev->rdsout)
43718 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43719
43720- if (i && copy_to_user(data, readbuf, i))
43721+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43722 i = -EFAULT;
43723 unlock:
43724 mutex_unlock(&dev->lock);
43725diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43726index 5236035..c622c74 100644
43727--- a/drivers/media/radio/radio-maxiradio.c
43728+++ b/drivers/media/radio/radio-maxiradio.c
43729@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43730 /* TEA5757 pin mappings */
43731 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43732
43733-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43734+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43735
43736 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43737 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43738diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43739index 050b3bb..79f62b9 100644
43740--- a/drivers/media/radio/radio-shark.c
43741+++ b/drivers/media/radio/radio-shark.c
43742@@ -79,7 +79,7 @@ struct shark_device {
43743 u32 last_val;
43744 };
43745
43746-static atomic_t shark_instance = ATOMIC_INIT(0);
43747+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43748
43749 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43750 {
43751diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43752index 8654e0d..0608a64 100644
43753--- a/drivers/media/radio/radio-shark2.c
43754+++ b/drivers/media/radio/radio-shark2.c
43755@@ -74,7 +74,7 @@ struct shark_device {
43756 u8 *transfer_buffer;
43757 };
43758
43759-static atomic_t shark_instance = ATOMIC_INIT(0);
43760+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43761
43762 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43763 {
43764diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43765index 2fd9009..278cc1e 100644
43766--- a/drivers/media/radio/radio-si476x.c
43767+++ b/drivers/media/radio/radio-si476x.c
43768@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43769 struct si476x_radio *radio;
43770 struct v4l2_ctrl *ctrl;
43771
43772- static atomic_t instance = ATOMIC_INIT(0);
43773+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43774
43775 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43776 if (!radio)
43777diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43778index 46da365..3ba4206 100644
43779--- a/drivers/media/rc/rc-main.c
43780+++ b/drivers/media/rc/rc-main.c
43781@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43782 int rc_register_device(struct rc_dev *dev)
43783 {
43784 static bool raw_init = false; /* raw decoders loaded? */
43785- static atomic_t devno = ATOMIC_INIT(0);
43786+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43787 struct rc_map *rc_map;
43788 const char *path;
43789 int rc;
43790@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
43791 */
43792 mutex_lock(&dev->lock);
43793
43794- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43795+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43796 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43797 dev_set_drvdata(&dev->dev, dev);
43798 rc = device_add(&dev->dev);
43799diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43800index 20e345d..da56fe4 100644
43801--- a/drivers/media/usb/dvb-usb/cxusb.c
43802+++ b/drivers/media/usb/dvb-usb/cxusb.c
43803@@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43804
43805 struct dib0700_adapter_state {
43806 int (*set_param_save) (struct dvb_frontend *);
43807-};
43808+} __no_const;
43809
43810 static int dib7070_set_param_override(struct dvb_frontend *fe)
43811 {
43812diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43813index c1a63b2..dbcbfb6 100644
43814--- a/drivers/media/usb/dvb-usb/dw2102.c
43815+++ b/drivers/media/usb/dvb-usb/dw2102.c
43816@@ -121,7 +121,7 @@ struct su3000_state {
43817
43818 struct s6x0_state {
43819 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43820-};
43821+} __no_const;
43822
43823 /* debug */
43824 static int dvb_usb_dw2102_debug;
43825diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43826index 8f7a6a4..eb0e1d4 100644
43827--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43828+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43829@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43830 __u32 reserved;
43831 };
43832
43833-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43834+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43835 enum v4l2_memory memory)
43836 {
43837 void __user *up_pln;
43838@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43839 return 0;
43840 }
43841
43842-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43843+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43844 enum v4l2_memory memory)
43845 {
43846 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43847@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43848 * by passing a very big num_planes value */
43849 uplane = compat_alloc_user_space(num_planes *
43850 sizeof(struct v4l2_plane));
43851- kp->m.planes = uplane;
43852+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
43853
43854 while (--num_planes >= 0) {
43855 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
43856@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43857 if (num_planes == 0)
43858 return 0;
43859
43860- uplane = kp->m.planes;
43861+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
43862 if (get_user(p, &up->m.planes))
43863 return -EFAULT;
43864 uplane32 = compat_ptr(p);
43865@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
43866 get_user(kp->capability, &up->capability) ||
43867 get_user(kp->flags, &up->flags))
43868 return -EFAULT;
43869- kp->base = compat_ptr(tmp);
43870+ kp->base = (void __force_kernel *)compat_ptr(tmp);
43871 get_v4l2_pix_format(&kp->fmt, &up->fmt);
43872 return 0;
43873 }
43874@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
43875 n * sizeof(struct v4l2_ext_control32)))
43876 return -EFAULT;
43877 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
43878- kp->controls = kcontrols;
43879+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
43880 while (--n >= 0) {
43881 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
43882 return -EFAULT;
43883@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
43884 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
43885 {
43886 struct v4l2_ext_control32 __user *ucontrols;
43887- struct v4l2_ext_control __user *kcontrols = kp->controls;
43888+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
43889 int n = kp->count;
43890 compat_caddr_t p;
43891
43892@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43893 put_user(kp->start_block, &up->start_block) ||
43894 put_user(kp->blocks, &up->blocks) ||
43895 put_user(tmp, &up->edid) ||
43896- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43897+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43898 return -EFAULT;
43899 return 0;
43900 }
43901diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
43902index fb46790..ae1f8fa 100644
43903--- a/drivers/media/v4l2-core/v4l2-ctrls.c
43904+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
43905@@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
43906 return 0;
43907
43908 case V4L2_CTRL_TYPE_STRING:
43909- len = strlen(c->string);
43910- if (len < ctrl->minimum)
43911+ len = strlen_user(c->string);
43912+ if (!len || len < ctrl->minimum)
43913 return -ERANGE;
43914 if ((len - ctrl->minimum) % ctrl->step)
43915 return -ERANGE;
43916diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43917index 02d1b63..5fd6b16 100644
43918--- a/drivers/media/v4l2-core/v4l2-device.c
43919+++ b/drivers/media/v4l2-core/v4l2-device.c
43920@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43921 EXPORT_SYMBOL_GPL(v4l2_device_put);
43922
43923 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43924- atomic_t *instance)
43925+ atomic_unchecked_t *instance)
43926 {
43927- int num = atomic_inc_return(instance) - 1;
43928+ int num = atomic_inc_return_unchecked(instance) - 1;
43929 int len = strlen(basename);
43930
43931 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43932diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43933index 68e6b5e..8eb2aec 100644
43934--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43935+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43936@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43937 struct file *file, void *fh, void *p);
43938 } u;
43939 void (*debug)(const void *arg, bool write_only);
43940-};
43941+} __do_const;
43942+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43943
43944 /* This control needs a priority check */
43945 #define INFO_FL_PRIO (1 << 0)
43946@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43947 struct video_device *vfd = video_devdata(file);
43948 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43949 bool write_only = false;
43950- struct v4l2_ioctl_info default_info;
43951+ v4l2_ioctl_info_no_const default_info;
43952 const struct v4l2_ioctl_info *info;
43953 void *fh = file->private_data;
43954 struct v4l2_fh *vfh = NULL;
43955@@ -2194,7 +2195,7 @@ done:
43956 }
43957
43958 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43959- void * __user *user_ptr, void ***kernel_ptr)
43960+ void __user **user_ptr, void ***kernel_ptr)
43961 {
43962 int ret = 0;
43963
43964@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43965 ret = -EINVAL;
43966 break;
43967 }
43968- *user_ptr = (void __user *)buf->m.planes;
43969+ *user_ptr = (void __force_user *)buf->m.planes;
43970 *kernel_ptr = (void *)&buf->m.planes;
43971 *array_size = sizeof(struct v4l2_plane) * buf->length;
43972 ret = 1;
43973@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43974 ret = -EINVAL;
43975 break;
43976 }
43977- *user_ptr = (void __user *)ctrls->controls;
43978+ *user_ptr = (void __force_user *)ctrls->controls;
43979 *kernel_ptr = (void *)&ctrls->controls;
43980 *array_size = sizeof(struct v4l2_ext_control)
43981 * ctrls->count;
43982@@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
43983 err = -ENOTTY;
43984
43985 if (has_array_args) {
43986- *kernel_ptr = user_ptr;
43987+ *kernel_ptr = (void __force_kernel *)user_ptr;
43988 if (copy_to_user(user_ptr, mbuf, array_size))
43989 err = -EFAULT;
43990 goto out_array_args;
43991diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43992index 767ff4d..c69d259 100644
43993--- a/drivers/message/fusion/mptbase.c
43994+++ b/drivers/message/fusion/mptbase.c
43995@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43996 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43997 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43998
43999+#ifdef CONFIG_GRKERNSEC_HIDESYM
44000+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44001+#else
44002 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44003 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44004+#endif
44005+
44006 /*
44007 * Rounding UP to nearest 4-kB boundary here...
44008 */
44009@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44010 ioc->facts.GlobalCredits);
44011
44012 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44013+#ifdef CONFIG_GRKERNSEC_HIDESYM
44014+ NULL, NULL);
44015+#else
44016 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44017+#endif
44018 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44019 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44020 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44021diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44022index dd239bd..689c4f7 100644
44023--- a/drivers/message/fusion/mptsas.c
44024+++ b/drivers/message/fusion/mptsas.c
44025@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44026 return 0;
44027 }
44028
44029+static inline void
44030+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44031+{
44032+ if (phy_info->port_details) {
44033+ phy_info->port_details->rphy = rphy;
44034+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44035+ ioc->name, rphy));
44036+ }
44037+
44038+ if (rphy) {
44039+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44040+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44041+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44042+ ioc->name, rphy, rphy->dev.release));
44043+ }
44044+}
44045+
44046 /* no mutex */
44047 static void
44048 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44049@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44050 return NULL;
44051 }
44052
44053-static inline void
44054-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44055-{
44056- if (phy_info->port_details) {
44057- phy_info->port_details->rphy = rphy;
44058- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44059- ioc->name, rphy));
44060- }
44061-
44062- if (rphy) {
44063- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44064- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44065- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44066- ioc->name, rphy, rphy->dev.release));
44067- }
44068-}
44069-
44070 static inline struct sas_port *
44071 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44072 {
44073diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44074index 727819c..ad74694 100644
44075--- a/drivers/message/fusion/mptscsih.c
44076+++ b/drivers/message/fusion/mptscsih.c
44077@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44078
44079 h = shost_priv(SChost);
44080
44081- if (h) {
44082- if (h->info_kbuf == NULL)
44083- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44084- return h->info_kbuf;
44085- h->info_kbuf[0] = '\0';
44086+ if (!h)
44087+ return NULL;
44088
44089- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44090- h->info_kbuf[size-1] = '\0';
44091- }
44092+ if (h->info_kbuf == NULL)
44093+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44094+ return h->info_kbuf;
44095+ h->info_kbuf[0] = '\0';
44096+
44097+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44098+ h->info_kbuf[size-1] = '\0';
44099
44100 return h->info_kbuf;
44101 }
44102diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44103index b7d87cd..3fb36da 100644
44104--- a/drivers/message/i2o/i2o_proc.c
44105+++ b/drivers/message/i2o/i2o_proc.c
44106@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44107 "Array Controller Device"
44108 };
44109
44110-static char *chtostr(char *tmp, u8 *chars, int n)
44111-{
44112- tmp[0] = 0;
44113- return strncat(tmp, (char *)chars, n);
44114-}
44115-
44116 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44117 char *group)
44118 {
44119@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44120 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44121 {
44122 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44123- static u32 work32[5];
44124- static u8 *work8 = (u8 *) work32;
44125- static u16 *work16 = (u16 *) work32;
44126+ u32 work32[5];
44127+ u8 *work8 = (u8 *) work32;
44128+ u16 *work16 = (u16 *) work32;
44129 int token;
44130 u32 hwcap;
44131
44132@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44133 } *result;
44134
44135 i2o_exec_execute_ddm_table ddm_table;
44136- char tmp[28 + 1];
44137
44138 result = kmalloc(sizeof(*result), GFP_KERNEL);
44139 if (!result)
44140@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44141
44142 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44143 seq_printf(seq, "%-#8x", ddm_table.module_id);
44144- seq_printf(seq, "%-29s",
44145- chtostr(tmp, ddm_table.module_name_version, 28));
44146+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44147 seq_printf(seq, "%9d ", ddm_table.data_size);
44148 seq_printf(seq, "%8d", ddm_table.code_size);
44149
44150@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44151
44152 i2o_driver_result_table *result;
44153 i2o_driver_store_table *dst;
44154- char tmp[28 + 1];
44155
44156 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44157 if (result == NULL)
44158@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44159
44160 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44161 seq_printf(seq, "%-#8x", dst->module_id);
44162- seq_printf(seq, "%-29s",
44163- chtostr(tmp, dst->module_name_version, 28));
44164- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44165+ seq_printf(seq, "%-.28s", dst->module_name_version);
44166+ seq_printf(seq, "%-.8s", dst->date);
44167 seq_printf(seq, "%8d ", dst->module_size);
44168 seq_printf(seq, "%8d ", dst->mpb_size);
44169 seq_printf(seq, "0x%04x", dst->module_flags);
44170@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44171 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44172 {
44173 struct i2o_device *d = (struct i2o_device *)seq->private;
44174- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44175+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44176 // == (allow) 512d bytes (max)
44177- static u16 *work16 = (u16 *) work32;
44178+ u16 *work16 = (u16 *) work32;
44179 int token;
44180- char tmp[16 + 1];
44181
44182 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44183
44184@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44185 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44186 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44187 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44188- seq_printf(seq, "Vendor info : %s\n",
44189- chtostr(tmp, (u8 *) (work32 + 2), 16));
44190- seq_printf(seq, "Product info : %s\n",
44191- chtostr(tmp, (u8 *) (work32 + 6), 16));
44192- seq_printf(seq, "Description : %s\n",
44193- chtostr(tmp, (u8 *) (work32 + 10), 16));
44194- seq_printf(seq, "Product rev. : %s\n",
44195- chtostr(tmp, (u8 *) (work32 + 14), 8));
44196+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44197+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44198+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44199+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44200
44201 seq_printf(seq, "Serial number : ");
44202 print_serial_number(seq, (u8 *) (work32 + 16),
44203@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44204 u8 pad[256]; // allow up to 256 byte (max) serial number
44205 } result;
44206
44207- char tmp[24 + 1];
44208-
44209 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44210
44211 if (token < 0) {
44212@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44213 }
44214
44215 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44216- seq_printf(seq, "Module name : %s\n",
44217- chtostr(tmp, result.module_name, 24));
44218- seq_printf(seq, "Module revision : %s\n",
44219- chtostr(tmp, result.module_rev, 8));
44220+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
44221+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44222
44223 seq_printf(seq, "Serial number : ");
44224 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44225@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44226 u8 instance_number[4];
44227 } result;
44228
44229- char tmp[64 + 1];
44230-
44231 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44232
44233 if (token < 0) {
44234@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44235 return 0;
44236 }
44237
44238- seq_printf(seq, "Device name : %s\n",
44239- chtostr(tmp, result.device_name, 64));
44240- seq_printf(seq, "Service name : %s\n",
44241- chtostr(tmp, result.service_name, 64));
44242- seq_printf(seq, "Physical name : %s\n",
44243- chtostr(tmp, result.physical_location, 64));
44244- seq_printf(seq, "Instance number : %s\n",
44245- chtostr(tmp, result.instance_number, 4));
44246+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
44247+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
44248+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44249+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44250
44251 return 0;
44252 }
44253@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44254 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44255 {
44256 struct i2o_device *d = (struct i2o_device *)seq->private;
44257- static u32 work32[12];
44258- static u16 *work16 = (u16 *) work32;
44259- static u8 *work8 = (u8 *) work32;
44260+ u32 work32[12];
44261+ u16 *work16 = (u16 *) work32;
44262+ u8 *work8 = (u8 *) work32;
44263 int token;
44264
44265 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44266diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44267index a8c08f3..155fe3d 100644
44268--- a/drivers/message/i2o/iop.c
44269+++ b/drivers/message/i2o/iop.c
44270@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44271
44272 spin_lock_irqsave(&c->context_list_lock, flags);
44273
44274- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44275- atomic_inc(&c->context_list_counter);
44276+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44277+ atomic_inc_unchecked(&c->context_list_counter);
44278
44279- entry->context = atomic_read(&c->context_list_counter);
44280+ entry->context = atomic_read_unchecked(&c->context_list_counter);
44281
44282 list_add(&entry->list, &c->context_list);
44283
44284@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44285
44286 #if BITS_PER_LONG == 64
44287 spin_lock_init(&c->context_list_lock);
44288- atomic_set(&c->context_list_counter, 0);
44289+ atomic_set_unchecked(&c->context_list_counter, 0);
44290 INIT_LIST_HEAD(&c->context_list);
44291 #endif
44292
44293diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44294index fcbb2e9..2635e11 100644
44295--- a/drivers/mfd/janz-cmodio.c
44296+++ b/drivers/mfd/janz-cmodio.c
44297@@ -13,6 +13,7 @@
44298
44299 #include <linux/kernel.h>
44300 #include <linux/module.h>
44301+#include <linux/slab.h>
44302 #include <linux/init.h>
44303 #include <linux/pci.h>
44304 #include <linux/interrupt.h>
44305diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
44306index 176aa26..27811b2 100644
44307--- a/drivers/mfd/max8925-i2c.c
44308+++ b/drivers/mfd/max8925-i2c.c
44309@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
44310 const struct i2c_device_id *id)
44311 {
44312 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
44313- static struct max8925_chip *chip;
44314+ struct max8925_chip *chip;
44315 struct device_node *node = client->dev.of_node;
44316
44317 if (node && !pdata) {
44318diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
44319index c0f608e..286f8ec 100644
44320--- a/drivers/mfd/tps65910.c
44321+++ b/drivers/mfd/tps65910.c
44322@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
44323 struct tps65910_platform_data *pdata)
44324 {
44325 int ret = 0;
44326- static struct regmap_irq_chip *tps6591x_irqs_chip;
44327+ struct regmap_irq_chip *tps6591x_irqs_chip;
44328
44329 if (!irq) {
44330 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
44331diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
44332index 9aa6d1e..1631bfc 100644
44333--- a/drivers/mfd/twl4030-irq.c
44334+++ b/drivers/mfd/twl4030-irq.c
44335@@ -35,6 +35,7 @@
44336 #include <linux/of.h>
44337 #include <linux/irqdomain.h>
44338 #include <linux/i2c/twl.h>
44339+#include <asm/pgtable.h>
44340
44341 #include "twl-core.h"
44342
44343@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
44344 * Install an irq handler for each of the SIH modules;
44345 * clone dummy irq_chip since PIH can't *do* anything
44346 */
44347- twl4030_irq_chip = dummy_irq_chip;
44348- twl4030_irq_chip.name = "twl4030";
44349+ pax_open_kernel();
44350+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
44351+ *(const char **)&twl4030_irq_chip.name = "twl4030";
44352
44353- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44354+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44355+ pax_close_kernel();
44356
44357 for (i = irq_base; i < irq_end; i++) {
44358 irq_set_chip_and_handler(i, &twl4030_irq_chip,
44359diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
44360index 464419b..64bae8d 100644
44361--- a/drivers/misc/c2port/core.c
44362+++ b/drivers/misc/c2port/core.c
44363@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
44364 goto error_idr_alloc;
44365 c2dev->id = ret;
44366
44367- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44368+ pax_open_kernel();
44369+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44370+ pax_close_kernel();
44371
44372 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
44373 "c2port%d", c2dev->id);
44374diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
44375index 36f5d52..32311c3 100644
44376--- a/drivers/misc/kgdbts.c
44377+++ b/drivers/misc/kgdbts.c
44378@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
44379 char before[BREAK_INSTR_SIZE];
44380 char after[BREAK_INSTR_SIZE];
44381
44382- probe_kernel_read(before, (char *)kgdbts_break_test,
44383+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
44384 BREAK_INSTR_SIZE);
44385 init_simple_test();
44386 ts.tst = plant_and_detach_test;
44387@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
44388 /* Activate test with initial breakpoint */
44389 if (!is_early)
44390 kgdb_breakpoint();
44391- probe_kernel_read(after, (char *)kgdbts_break_test,
44392+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
44393 BREAK_INSTR_SIZE);
44394 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
44395 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
44396diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
44397index 036effe..b3a6336 100644
44398--- a/drivers/misc/lis3lv02d/lis3lv02d.c
44399+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
44400@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
44401 * the lid is closed. This leads to interrupts as soon as a little move
44402 * is done.
44403 */
44404- atomic_inc(&lis3->count);
44405+ atomic_inc_unchecked(&lis3->count);
44406
44407 wake_up_interruptible(&lis3->misc_wait);
44408 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
44409@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
44410 if (lis3->pm_dev)
44411 pm_runtime_get_sync(lis3->pm_dev);
44412
44413- atomic_set(&lis3->count, 0);
44414+ atomic_set_unchecked(&lis3->count, 0);
44415 return 0;
44416 }
44417
44418@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
44419 add_wait_queue(&lis3->misc_wait, &wait);
44420 while (true) {
44421 set_current_state(TASK_INTERRUPTIBLE);
44422- data = atomic_xchg(&lis3->count, 0);
44423+ data = atomic_xchg_unchecked(&lis3->count, 0);
44424 if (data)
44425 break;
44426
44427@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
44428 struct lis3lv02d, miscdev);
44429
44430 poll_wait(file, &lis3->misc_wait, wait);
44431- if (atomic_read(&lis3->count))
44432+ if (atomic_read_unchecked(&lis3->count))
44433 return POLLIN | POLLRDNORM;
44434 return 0;
44435 }
44436diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
44437index c439c82..1f20f57 100644
44438--- a/drivers/misc/lis3lv02d/lis3lv02d.h
44439+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
44440@@ -297,7 +297,7 @@ struct lis3lv02d {
44441 struct input_polled_dev *idev; /* input device */
44442 struct platform_device *pdev; /* platform device */
44443 struct regulator_bulk_data regulators[2];
44444- atomic_t count; /* interrupt count after last read */
44445+ atomic_unchecked_t count; /* interrupt count after last read */
44446 union axis_conversion ac; /* hw -> logical axis */
44447 int mapped_btns[3];
44448
44449diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
44450index 2f30bad..c4c13d0 100644
44451--- a/drivers/misc/sgi-gru/gruhandles.c
44452+++ b/drivers/misc/sgi-gru/gruhandles.c
44453@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
44454 unsigned long nsec;
44455
44456 nsec = CLKS2NSEC(clks);
44457- atomic_long_inc(&mcs_op_statistics[op].count);
44458- atomic_long_add(nsec, &mcs_op_statistics[op].total);
44459+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
44460+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
44461 if (mcs_op_statistics[op].max < nsec)
44462 mcs_op_statistics[op].max = nsec;
44463 }
44464diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
44465index 4f76359..cdfcb2e 100644
44466--- a/drivers/misc/sgi-gru/gruprocfs.c
44467+++ b/drivers/misc/sgi-gru/gruprocfs.c
44468@@ -32,9 +32,9 @@
44469
44470 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
44471
44472-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
44473+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
44474 {
44475- unsigned long val = atomic_long_read(v);
44476+ unsigned long val = atomic_long_read_unchecked(v);
44477
44478 seq_printf(s, "%16lu %s\n", val, id);
44479 }
44480@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
44481
44482 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
44483 for (op = 0; op < mcsop_last; op++) {
44484- count = atomic_long_read(&mcs_op_statistics[op].count);
44485- total = atomic_long_read(&mcs_op_statistics[op].total);
44486+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
44487+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
44488 max = mcs_op_statistics[op].max;
44489 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
44490 count ? total / count : 0, max);
44491diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
44492index 5c3ce24..4915ccb 100644
44493--- a/drivers/misc/sgi-gru/grutables.h
44494+++ b/drivers/misc/sgi-gru/grutables.h
44495@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
44496 * GRU statistics.
44497 */
44498 struct gru_stats_s {
44499- atomic_long_t vdata_alloc;
44500- atomic_long_t vdata_free;
44501- atomic_long_t gts_alloc;
44502- atomic_long_t gts_free;
44503- atomic_long_t gms_alloc;
44504- atomic_long_t gms_free;
44505- atomic_long_t gts_double_allocate;
44506- atomic_long_t assign_context;
44507- atomic_long_t assign_context_failed;
44508- atomic_long_t free_context;
44509- atomic_long_t load_user_context;
44510- atomic_long_t load_kernel_context;
44511- atomic_long_t lock_kernel_context;
44512- atomic_long_t unlock_kernel_context;
44513- atomic_long_t steal_user_context;
44514- atomic_long_t steal_kernel_context;
44515- atomic_long_t steal_context_failed;
44516- atomic_long_t nopfn;
44517- atomic_long_t asid_new;
44518- atomic_long_t asid_next;
44519- atomic_long_t asid_wrap;
44520- atomic_long_t asid_reuse;
44521- atomic_long_t intr;
44522- atomic_long_t intr_cbr;
44523- atomic_long_t intr_tfh;
44524- atomic_long_t intr_spurious;
44525- atomic_long_t intr_mm_lock_failed;
44526- atomic_long_t call_os;
44527- atomic_long_t call_os_wait_queue;
44528- atomic_long_t user_flush_tlb;
44529- atomic_long_t user_unload_context;
44530- atomic_long_t user_exception;
44531- atomic_long_t set_context_option;
44532- atomic_long_t check_context_retarget_intr;
44533- atomic_long_t check_context_unload;
44534- atomic_long_t tlb_dropin;
44535- atomic_long_t tlb_preload_page;
44536- atomic_long_t tlb_dropin_fail_no_asid;
44537- atomic_long_t tlb_dropin_fail_upm;
44538- atomic_long_t tlb_dropin_fail_invalid;
44539- atomic_long_t tlb_dropin_fail_range_active;
44540- atomic_long_t tlb_dropin_fail_idle;
44541- atomic_long_t tlb_dropin_fail_fmm;
44542- atomic_long_t tlb_dropin_fail_no_exception;
44543- atomic_long_t tfh_stale_on_fault;
44544- atomic_long_t mmu_invalidate_range;
44545- atomic_long_t mmu_invalidate_page;
44546- atomic_long_t flush_tlb;
44547- atomic_long_t flush_tlb_gru;
44548- atomic_long_t flush_tlb_gru_tgh;
44549- atomic_long_t flush_tlb_gru_zero_asid;
44550+ atomic_long_unchecked_t vdata_alloc;
44551+ atomic_long_unchecked_t vdata_free;
44552+ atomic_long_unchecked_t gts_alloc;
44553+ atomic_long_unchecked_t gts_free;
44554+ atomic_long_unchecked_t gms_alloc;
44555+ atomic_long_unchecked_t gms_free;
44556+ atomic_long_unchecked_t gts_double_allocate;
44557+ atomic_long_unchecked_t assign_context;
44558+ atomic_long_unchecked_t assign_context_failed;
44559+ atomic_long_unchecked_t free_context;
44560+ atomic_long_unchecked_t load_user_context;
44561+ atomic_long_unchecked_t load_kernel_context;
44562+ atomic_long_unchecked_t lock_kernel_context;
44563+ atomic_long_unchecked_t unlock_kernel_context;
44564+ atomic_long_unchecked_t steal_user_context;
44565+ atomic_long_unchecked_t steal_kernel_context;
44566+ atomic_long_unchecked_t steal_context_failed;
44567+ atomic_long_unchecked_t nopfn;
44568+ atomic_long_unchecked_t asid_new;
44569+ atomic_long_unchecked_t asid_next;
44570+ atomic_long_unchecked_t asid_wrap;
44571+ atomic_long_unchecked_t asid_reuse;
44572+ atomic_long_unchecked_t intr;
44573+ atomic_long_unchecked_t intr_cbr;
44574+ atomic_long_unchecked_t intr_tfh;
44575+ atomic_long_unchecked_t intr_spurious;
44576+ atomic_long_unchecked_t intr_mm_lock_failed;
44577+ atomic_long_unchecked_t call_os;
44578+ atomic_long_unchecked_t call_os_wait_queue;
44579+ atomic_long_unchecked_t user_flush_tlb;
44580+ atomic_long_unchecked_t user_unload_context;
44581+ atomic_long_unchecked_t user_exception;
44582+ atomic_long_unchecked_t set_context_option;
44583+ atomic_long_unchecked_t check_context_retarget_intr;
44584+ atomic_long_unchecked_t check_context_unload;
44585+ atomic_long_unchecked_t tlb_dropin;
44586+ atomic_long_unchecked_t tlb_preload_page;
44587+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
44588+ atomic_long_unchecked_t tlb_dropin_fail_upm;
44589+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
44590+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
44591+ atomic_long_unchecked_t tlb_dropin_fail_idle;
44592+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
44593+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
44594+ atomic_long_unchecked_t tfh_stale_on_fault;
44595+ atomic_long_unchecked_t mmu_invalidate_range;
44596+ atomic_long_unchecked_t mmu_invalidate_page;
44597+ atomic_long_unchecked_t flush_tlb;
44598+ atomic_long_unchecked_t flush_tlb_gru;
44599+ atomic_long_unchecked_t flush_tlb_gru_tgh;
44600+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
44601
44602- atomic_long_t copy_gpa;
44603- atomic_long_t read_gpa;
44604+ atomic_long_unchecked_t copy_gpa;
44605+ atomic_long_unchecked_t read_gpa;
44606
44607- atomic_long_t mesq_receive;
44608- atomic_long_t mesq_receive_none;
44609- atomic_long_t mesq_send;
44610- atomic_long_t mesq_send_failed;
44611- atomic_long_t mesq_noop;
44612- atomic_long_t mesq_send_unexpected_error;
44613- atomic_long_t mesq_send_lb_overflow;
44614- atomic_long_t mesq_send_qlimit_reached;
44615- atomic_long_t mesq_send_amo_nacked;
44616- atomic_long_t mesq_send_put_nacked;
44617- atomic_long_t mesq_page_overflow;
44618- atomic_long_t mesq_qf_locked;
44619- atomic_long_t mesq_qf_noop_not_full;
44620- atomic_long_t mesq_qf_switch_head_failed;
44621- atomic_long_t mesq_qf_unexpected_error;
44622- atomic_long_t mesq_noop_unexpected_error;
44623- atomic_long_t mesq_noop_lb_overflow;
44624- atomic_long_t mesq_noop_qlimit_reached;
44625- atomic_long_t mesq_noop_amo_nacked;
44626- atomic_long_t mesq_noop_put_nacked;
44627- atomic_long_t mesq_noop_page_overflow;
44628+ atomic_long_unchecked_t mesq_receive;
44629+ atomic_long_unchecked_t mesq_receive_none;
44630+ atomic_long_unchecked_t mesq_send;
44631+ atomic_long_unchecked_t mesq_send_failed;
44632+ atomic_long_unchecked_t mesq_noop;
44633+ atomic_long_unchecked_t mesq_send_unexpected_error;
44634+ atomic_long_unchecked_t mesq_send_lb_overflow;
44635+ atomic_long_unchecked_t mesq_send_qlimit_reached;
44636+ atomic_long_unchecked_t mesq_send_amo_nacked;
44637+ atomic_long_unchecked_t mesq_send_put_nacked;
44638+ atomic_long_unchecked_t mesq_page_overflow;
44639+ atomic_long_unchecked_t mesq_qf_locked;
44640+ atomic_long_unchecked_t mesq_qf_noop_not_full;
44641+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
44642+ atomic_long_unchecked_t mesq_qf_unexpected_error;
44643+ atomic_long_unchecked_t mesq_noop_unexpected_error;
44644+ atomic_long_unchecked_t mesq_noop_lb_overflow;
44645+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
44646+ atomic_long_unchecked_t mesq_noop_amo_nacked;
44647+ atomic_long_unchecked_t mesq_noop_put_nacked;
44648+ atomic_long_unchecked_t mesq_noop_page_overflow;
44649
44650 };
44651
44652@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
44653 tghop_invalidate, mcsop_last};
44654
44655 struct mcs_op_statistic {
44656- atomic_long_t count;
44657- atomic_long_t total;
44658+ atomic_long_unchecked_t count;
44659+ atomic_long_unchecked_t total;
44660 unsigned long max;
44661 };
44662
44663@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
44664
44665 #define STAT(id) do { \
44666 if (gru_options & OPT_STATS) \
44667- atomic_long_inc(&gru_stats.id); \
44668+ atomic_long_inc_unchecked(&gru_stats.id); \
44669 } while (0)
44670
44671 #ifdef CONFIG_SGI_GRU_DEBUG
44672diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
44673index c862cd4..0d176fe 100644
44674--- a/drivers/misc/sgi-xp/xp.h
44675+++ b/drivers/misc/sgi-xp/xp.h
44676@@ -288,7 +288,7 @@ struct xpc_interface {
44677 xpc_notify_func, void *);
44678 void (*received) (short, int, void *);
44679 enum xp_retval (*partid_to_nasids) (short, void *);
44680-};
44681+} __no_const;
44682
44683 extern struct xpc_interface xpc_interface;
44684
44685diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
44686index 01be66d..e3a0c7e 100644
44687--- a/drivers/misc/sgi-xp/xp_main.c
44688+++ b/drivers/misc/sgi-xp/xp_main.c
44689@@ -78,13 +78,13 @@ xpc_notloaded(void)
44690 }
44691
44692 struct xpc_interface xpc_interface = {
44693- (void (*)(int))xpc_notloaded,
44694- (void (*)(int))xpc_notloaded,
44695- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44696- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44697+ .connect = (void (*)(int))xpc_notloaded,
44698+ .disconnect = (void (*)(int))xpc_notloaded,
44699+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44700+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44701 void *))xpc_notloaded,
44702- (void (*)(short, int, void *))xpc_notloaded,
44703- (enum xp_retval(*)(short, void *))xpc_notloaded
44704+ .received = (void (*)(short, int, void *))xpc_notloaded,
44705+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
44706 };
44707 EXPORT_SYMBOL_GPL(xpc_interface);
44708
44709diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44710index b94d5f7..7f494c5 100644
44711--- a/drivers/misc/sgi-xp/xpc.h
44712+++ b/drivers/misc/sgi-xp/xpc.h
44713@@ -835,6 +835,7 @@ struct xpc_arch_operations {
44714 void (*received_payload) (struct xpc_channel *, void *);
44715 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44716 };
44717+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44718
44719 /* struct xpc_partition act_state values (for XPC HB) */
44720
44721@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44722 /* found in xpc_main.c */
44723 extern struct device *xpc_part;
44724 extern struct device *xpc_chan;
44725-extern struct xpc_arch_operations xpc_arch_ops;
44726+extern xpc_arch_operations_no_const xpc_arch_ops;
44727 extern int xpc_disengage_timelimit;
44728 extern int xpc_disengage_timedout;
44729 extern int xpc_activate_IRQ_rcvd;
44730diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44731index 82dc574..8539ab2 100644
44732--- a/drivers/misc/sgi-xp/xpc_main.c
44733+++ b/drivers/misc/sgi-xp/xpc_main.c
44734@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44735 .notifier_call = xpc_system_die,
44736 };
44737
44738-struct xpc_arch_operations xpc_arch_ops;
44739+xpc_arch_operations_no_const xpc_arch_ops;
44740
44741 /*
44742 * Timer function to enforce the timelimit on the partition disengage.
44743@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44744
44745 if (((die_args->trapnr == X86_TRAP_MF) ||
44746 (die_args->trapnr == X86_TRAP_XF)) &&
44747- !user_mode_vm(die_args->regs))
44748+ !user_mode(die_args->regs))
44749 xpc_die_deactivate();
44750
44751 break;
44752diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
44753index 29d5d98..fea356f 100644
44754--- a/drivers/mmc/card/block.c
44755+++ b/drivers/mmc/card/block.c
44756@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
44757 if (idata->ic.postsleep_min_us)
44758 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
44759
44760- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
44761+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
44762 err = -EFAULT;
44763 goto cmd_rel_host;
44764 }
44765diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44766index e5b5eeb..7bf2212 100644
44767--- a/drivers/mmc/core/mmc_ops.c
44768+++ b/drivers/mmc/core/mmc_ops.c
44769@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44770 void *data_buf;
44771 int is_on_stack;
44772
44773- is_on_stack = object_is_on_stack(buf);
44774+ is_on_stack = object_starts_on_stack(buf);
44775 if (is_on_stack) {
44776 /*
44777 * dma onto stack is unsafe/nonportable, but callers to this
44778diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44779index 6bf24ab..13d0293b 100644
44780--- a/drivers/mmc/host/dw_mmc.h
44781+++ b/drivers/mmc/host/dw_mmc.h
44782@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
44783 int (*parse_dt)(struct dw_mci *host);
44784 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
44785 struct dw_mci_tuning_data *tuning_data);
44786-};
44787+} __do_const;
44788 #endif /* _DW_MMC_H_ */
44789diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44790index f320579..7b7ebac 100644
44791--- a/drivers/mmc/host/mmci.c
44792+++ b/drivers/mmc/host/mmci.c
44793@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
44794 }
44795
44796 if (variant->busy_detect) {
44797- mmci_ops.card_busy = mmci_card_busy;
44798+ pax_open_kernel();
44799+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
44800+ pax_close_kernel();
44801 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44802 }
44803
44804diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44805index 6debda9..2ba7427 100644
44806--- a/drivers/mmc/host/sdhci-s3c.c
44807+++ b/drivers/mmc/host/sdhci-s3c.c
44808@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44809 * we can use overriding functions instead of default.
44810 */
44811 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44812- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44813- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44814- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44815+ pax_open_kernel();
44816+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44817+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44818+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44819+ pax_close_kernel();
44820 }
44821
44822 /* It supports additional host capabilities if needed */
44823diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
44824index 096993f..f02c23b 100644
44825--- a/drivers/mtd/chips/cfi_cmdset_0020.c
44826+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
44827@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
44828 size_t totlen = 0, thislen;
44829 int ret = 0;
44830 size_t buflen = 0;
44831- static char *buffer;
44832+ char *buffer;
44833
44834 if (!ECCBUF_SIZE) {
44835 /* We should fall back to a general writev implementation.
44836diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44837index 370b9dd..1a1176b 100644
44838--- a/drivers/mtd/nand/denali.c
44839+++ b/drivers/mtd/nand/denali.c
44840@@ -24,6 +24,7 @@
44841 #include <linux/slab.h>
44842 #include <linux/mtd/mtd.h>
44843 #include <linux/module.h>
44844+#include <linux/slab.h>
44845
44846 #include "denali.h"
44847
44848diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44849index 51b9d6a..52af9a7 100644
44850--- a/drivers/mtd/nftlmount.c
44851+++ b/drivers/mtd/nftlmount.c
44852@@ -24,6 +24,7 @@
44853 #include <asm/errno.h>
44854 #include <linux/delay.h>
44855 #include <linux/slab.h>
44856+#include <linux/sched.h>
44857 #include <linux/mtd/mtd.h>
44858 #include <linux/mtd/nand.h>
44859 #include <linux/mtd/nftl.h>
44860diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44861index 4b8e895..6b3c498 100644
44862--- a/drivers/mtd/sm_ftl.c
44863+++ b/drivers/mtd/sm_ftl.c
44864@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44865 #define SM_CIS_VENDOR_OFFSET 0x59
44866 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44867 {
44868- struct attribute_group *attr_group;
44869+ attribute_group_no_const *attr_group;
44870 struct attribute **attributes;
44871 struct sm_sysfs_attribute *vendor_attribute;
44872
44873diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44874index 4b8c58b..a200546 100644
44875--- a/drivers/net/bonding/bond_main.c
44876+++ b/drivers/net/bonding/bond_main.c
44877@@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
44878
44879 bond_netlink_fini();
44880 unregister_pernet_subsys(&bond_net_ops);
44881+ rtnl_link_unregister(&bond_link_ops);
44882
44883 #ifdef CONFIG_NET_POLL_CONTROLLER
44884 /*
44885diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
44886index 40e7b1c..6a70fff 100644
44887--- a/drivers/net/bonding/bond_netlink.c
44888+++ b/drivers/net/bonding/bond_netlink.c
44889@@ -102,7 +102,7 @@ nla_put_failure:
44890 return -EMSGSIZE;
44891 }
44892
44893-struct rtnl_link_ops bond_link_ops __read_mostly = {
44894+struct rtnl_link_ops bond_link_ops = {
44895 .kind = "bond",
44896 .priv_size = sizeof(struct bonding),
44897 .setup = bond_setup,
44898diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44899index 36fa577..a158806 100644
44900--- a/drivers/net/ethernet/8390/ax88796.c
44901+++ b/drivers/net/ethernet/8390/ax88796.c
44902@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44903 if (ax->plat->reg_offsets)
44904 ei_local->reg_offset = ax->plat->reg_offsets;
44905 else {
44906+ resource_size_t _mem_size = mem_size;
44907+ do_div(_mem_size, 0x18);
44908 ei_local->reg_offset = ax->reg_offsets;
44909 for (ret = 0; ret < 0x18; ret++)
44910- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44911+ ax->reg_offsets[ret] = _mem_size * ret;
44912 }
44913
44914 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44915diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44916index 41f3ca5a..1ee5364 100644
44917--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44918+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44919@@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44920 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44921 {
44922 /* RX_MODE controlling object */
44923- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44924+ bnx2x_init_rx_mode_obj(bp);
44925
44926 /* multicast configuration controlling object */
44927 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44928diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44929index 18438a5..c923b8e 100644
44930--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44931+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44932@@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44933 return rc;
44934 }
44935
44936-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44937- struct bnx2x_rx_mode_obj *o)
44938+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44939 {
44940 if (CHIP_IS_E1x(bp)) {
44941- o->wait_comp = bnx2x_empty_rx_mode_wait;
44942- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44943+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44944+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44945 } else {
44946- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44947- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44948+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44949+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44950 }
44951 }
44952
44953diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44954index 6a53c15..6e7d1e7 100644
44955--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44956+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44957@@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44958
44959 /********************* RX MODE ****************/
44960
44961-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44962- struct bnx2x_rx_mode_obj *o);
44963+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44964
44965 /**
44966 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44967diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44968index 5c3835a..d18b952 100644
44969--- a/drivers/net/ethernet/broadcom/tg3.h
44970+++ b/drivers/net/ethernet/broadcom/tg3.h
44971@@ -150,6 +150,7 @@
44972 #define CHIPREV_ID_5750_A0 0x4000
44973 #define CHIPREV_ID_5750_A1 0x4001
44974 #define CHIPREV_ID_5750_A3 0x4003
44975+#define CHIPREV_ID_5750_C1 0x4201
44976 #define CHIPREV_ID_5750_C2 0x4202
44977 #define CHIPREV_ID_5752_A0_HW 0x5000
44978 #define CHIPREV_ID_5752_A0 0x6000
44979diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
44980index 3ca77fa..fcc015f 100644
44981--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
44982+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
44983@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
44984 }
44985
44986 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
44987- bna_cb_ioceth_enable,
44988- bna_cb_ioceth_disable,
44989- bna_cb_ioceth_hbfail,
44990- bna_cb_ioceth_reset
44991+ .enable_cbfn = bna_cb_ioceth_enable,
44992+ .disable_cbfn = bna_cb_ioceth_disable,
44993+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
44994+ .reset_cbfn = bna_cb_ioceth_reset
44995 };
44996
44997 static void bna_attr_init(struct bna_ioceth *ioceth)
44998diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44999index 8cffcdf..aadf043 100644
45000--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45001+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45002@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45003 */
45004 struct l2t_skb_cb {
45005 arp_failure_handler_func arp_failure_handler;
45006-};
45007+} __no_const;
45008
45009 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45010
45011diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45012index fff02ed..d421412 100644
45013--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45014+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45015@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45016
45017 int i;
45018 struct adapter *ap = netdev2adap(dev);
45019- static const unsigned int *reg_ranges;
45020+ const unsigned int *reg_ranges;
45021 int arr_size = 0, buf_size = 0;
45022
45023 if (is_t4(ap->params.chip)) {
45024diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45025index c05b66d..ed69872 100644
45026--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45027+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45028@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45029 for (i=0; i<ETH_ALEN; i++) {
45030 tmp.addr[i] = dev->dev_addr[i];
45031 }
45032- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45033+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45034 break;
45035
45036 case DE4X5_SET_HWADDR: /* Set the hardware address */
45037@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45038 spin_lock_irqsave(&lp->lock, flags);
45039 memcpy(&statbuf, &lp->pktStats, ioc->len);
45040 spin_unlock_irqrestore(&lp->lock, flags);
45041- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45042+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45043 return -EFAULT;
45044 break;
45045 }
45046diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45047index a37039d..a51d7e8 100644
45048--- a/drivers/net/ethernet/emulex/benet/be_main.c
45049+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45050@@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45051
45052 if (wrapped)
45053 newacc += 65536;
45054- ACCESS_ONCE(*acc) = newacc;
45055+ ACCESS_ONCE_RW(*acc) = newacc;
45056 }
45057
45058 static void populate_erx_stats(struct be_adapter *adapter,
45059diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45060index 212f44b..fb69959 100644
45061--- a/drivers/net/ethernet/faraday/ftgmac100.c
45062+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45063@@ -31,6 +31,8 @@
45064 #include <linux/netdevice.h>
45065 #include <linux/phy.h>
45066 #include <linux/platform_device.h>
45067+#include <linux/interrupt.h>
45068+#include <linux/irqreturn.h>
45069 #include <net/ip.h>
45070
45071 #include "ftgmac100.h"
45072diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45073index 8be5b40..081bc1b 100644
45074--- a/drivers/net/ethernet/faraday/ftmac100.c
45075+++ b/drivers/net/ethernet/faraday/ftmac100.c
45076@@ -31,6 +31,8 @@
45077 #include <linux/module.h>
45078 #include <linux/netdevice.h>
45079 #include <linux/platform_device.h>
45080+#include <linux/interrupt.h>
45081+#include <linux/irqreturn.h>
45082
45083 #include "ftmac100.h"
45084
45085diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45086index 5184e2a..acb28c3 100644
45087--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45088+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45089@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45090 }
45091
45092 /* update the base incval used to calculate frequency adjustment */
45093- ACCESS_ONCE(adapter->base_incval) = incval;
45094+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45095 smp_mb();
45096
45097 /* need lock to prevent incorrect read while modifying cyclecounter */
45098diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45099index fbe5363..266b4e3 100644
45100--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45101+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45102@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45103 struct __vxge_hw_fifo *fifo;
45104 struct vxge_hw_fifo_config *config;
45105 u32 txdl_size, txdl_per_memblock;
45106- struct vxge_hw_mempool_cbs fifo_mp_callback;
45107+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45108+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45109+ };
45110+
45111 struct __vxge_hw_virtualpath *vpath;
45112
45113 if ((vp == NULL) || (attr == NULL)) {
45114@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45115 goto exit;
45116 }
45117
45118- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45119-
45120 fifo->mempool =
45121 __vxge_hw_mempool_create(vpath->hldev,
45122 fifo->config->memblock_size,
45123diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45124index 918e18d..4ca3650 100644
45125--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45126+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45127@@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45128 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45129 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45130 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45131- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45132+ pax_open_kernel();
45133+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45134+ pax_close_kernel();
45135 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45136 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45137 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45138diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45139index 734d286..b017bf5 100644
45140--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45141+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45142@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45143 case QLCNIC_NON_PRIV_FUNC:
45144 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45145 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45146- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45147+ pax_open_kernel();
45148+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45149+ pax_close_kernel();
45150 break;
45151 case QLCNIC_PRIV_FUNC:
45152 ahw->op_mode = QLCNIC_PRIV_FUNC;
45153 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45154- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45155+ pax_open_kernel();
45156+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45157+ pax_close_kernel();
45158 break;
45159 case QLCNIC_MGMT_FUNC:
45160 ahw->op_mode = QLCNIC_MGMT_FUNC;
45161 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45162- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45163+ pax_open_kernel();
45164+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45165+ pax_close_kernel();
45166 break;
45167 default:
45168 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45169diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45170index 7763962..c3499a7 100644
45171--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45172+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45173@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45174 struct qlcnic_dump_entry *entry;
45175 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45176 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45177- static const struct qlcnic_dump_operations *fw_dump_ops;
45178+ const struct qlcnic_dump_operations *fw_dump_ops;
45179 struct device *dev = &adapter->pdev->dev;
45180 struct qlcnic_hardware_context *ahw;
45181 void *temp_buffer;
45182diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45183index c737f0e..32b8682 100644
45184--- a/drivers/net/ethernet/realtek/r8169.c
45185+++ b/drivers/net/ethernet/realtek/r8169.c
45186@@ -759,22 +759,22 @@ struct rtl8169_private {
45187 struct mdio_ops {
45188 void (*write)(struct rtl8169_private *, int, int);
45189 int (*read)(struct rtl8169_private *, int);
45190- } mdio_ops;
45191+ } __no_const mdio_ops;
45192
45193 struct pll_power_ops {
45194 void (*down)(struct rtl8169_private *);
45195 void (*up)(struct rtl8169_private *);
45196- } pll_power_ops;
45197+ } __no_const pll_power_ops;
45198
45199 struct jumbo_ops {
45200 void (*enable)(struct rtl8169_private *);
45201 void (*disable)(struct rtl8169_private *);
45202- } jumbo_ops;
45203+ } __no_const jumbo_ops;
45204
45205 struct csi_ops {
45206 void (*write)(struct rtl8169_private *, int, int);
45207 u32 (*read)(struct rtl8169_private *, int);
45208- } csi_ops;
45209+ } __no_const csi_ops;
45210
45211 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45212 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45213diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45214index 3dd39dc..85efa46 100644
45215--- a/drivers/net/ethernet/sfc/ptp.c
45216+++ b/drivers/net/ethernet/sfc/ptp.c
45217@@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45218 ptp->start.dma_addr);
45219
45220 /* Clear flag that signals MC ready */
45221- ACCESS_ONCE(*start) = 0;
45222+ ACCESS_ONCE_RW(*start) = 0;
45223 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45224 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45225 EFX_BUG_ON_PARANOID(rc);
45226diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45227index 50617c5..b13724c 100644
45228--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45229+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45230@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45231
45232 writel(value, ioaddr + MMC_CNTRL);
45233
45234- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45235- MMC_CNTRL, value);
45236+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45237+// MMC_CNTRL, value);
45238 }
45239
45240 /* To mask all all interrupts.*/
45241diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
45242index e6fe0d8..2b7d752 100644
45243--- a/drivers/net/hyperv/hyperv_net.h
45244+++ b/drivers/net/hyperv/hyperv_net.h
45245@@ -101,7 +101,7 @@ struct rndis_device {
45246
45247 enum rndis_device_state state;
45248 bool link_state;
45249- atomic_t new_req_id;
45250+ atomic_unchecked_t new_req_id;
45251
45252 spinlock_t request_lock;
45253 struct list_head req_list;
45254diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
45255index 0775f0a..d4fb316 100644
45256--- a/drivers/net/hyperv/rndis_filter.c
45257+++ b/drivers/net/hyperv/rndis_filter.c
45258@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
45259 * template
45260 */
45261 set = &rndis_msg->msg.set_req;
45262- set->req_id = atomic_inc_return(&dev->new_req_id);
45263+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45264
45265 /* Add to the request list */
45266 spin_lock_irqsave(&dev->request_lock, flags);
45267@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
45268
45269 /* Setup the rndis set */
45270 halt = &request->request_msg.msg.halt_req;
45271- halt->req_id = atomic_inc_return(&dev->new_req_id);
45272+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45273
45274 /* Ignore return since this msg is optional. */
45275 rndis_filter_send_request(dev, request);
45276diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
45277index bf0d55e..82bcfbd1 100644
45278--- a/drivers/net/ieee802154/fakehard.c
45279+++ b/drivers/net/ieee802154/fakehard.c
45280@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
45281 phy->transmit_power = 0xbf;
45282
45283 dev->netdev_ops = &fake_ops;
45284- dev->ml_priv = &fake_mlme;
45285+ dev->ml_priv = (void *)&fake_mlme;
45286
45287 priv = netdev_priv(dev);
45288 priv->phy = phy;
45289diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
45290index bc8faae..e51e25d 100644
45291--- a/drivers/net/macvlan.c
45292+++ b/drivers/net/macvlan.c
45293@@ -990,13 +990,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
45294 int macvlan_link_register(struct rtnl_link_ops *ops)
45295 {
45296 /* common fields */
45297- ops->priv_size = sizeof(struct macvlan_dev);
45298- ops->validate = macvlan_validate;
45299- ops->maxtype = IFLA_MACVLAN_MAX;
45300- ops->policy = macvlan_policy;
45301- ops->changelink = macvlan_changelink;
45302- ops->get_size = macvlan_get_size;
45303- ops->fill_info = macvlan_fill_info;
45304+ pax_open_kernel();
45305+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
45306+ *(void **)&ops->validate = macvlan_validate;
45307+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
45308+ *(const void **)&ops->policy = macvlan_policy;
45309+ *(void **)&ops->changelink = macvlan_changelink;
45310+ *(void **)&ops->get_size = macvlan_get_size;
45311+ *(void **)&ops->fill_info = macvlan_fill_info;
45312+ pax_close_kernel();
45313
45314 return rtnl_link_register(ops);
45315 };
45316@@ -1051,7 +1053,7 @@ static int macvlan_device_event(struct notifier_block *unused,
45317 return NOTIFY_DONE;
45318 }
45319
45320-static struct notifier_block macvlan_notifier_block __read_mostly = {
45321+static struct notifier_block macvlan_notifier_block = {
45322 .notifier_call = macvlan_device_event,
45323 };
45324
45325diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
45326index 2a89da0..c17fe1d 100644
45327--- a/drivers/net/macvtap.c
45328+++ b/drivers/net/macvtap.c
45329@@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
45330 }
45331
45332 ret = 0;
45333- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45334+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45335 put_user(q->flags, &ifr->ifr_flags))
45336 ret = -EFAULT;
45337 macvtap_put_vlan(vlan);
45338@@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
45339 return NOTIFY_DONE;
45340 }
45341
45342-static struct notifier_block macvtap_notifier_block __read_mostly = {
45343+static struct notifier_block macvtap_notifier_block = {
45344 .notifier_call = macvtap_device_event,
45345 };
45346
45347diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
45348index daec9b0..6428fcb 100644
45349--- a/drivers/net/phy/mdio-bitbang.c
45350+++ b/drivers/net/phy/mdio-bitbang.c
45351@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
45352 struct mdiobb_ctrl *ctrl = bus->priv;
45353
45354 module_put(ctrl->ops->owner);
45355+ mdiobus_unregister(bus);
45356 mdiobus_free(bus);
45357 }
45358 EXPORT_SYMBOL(free_mdio_bitbang);
45359diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
45360index 72ff14b..11d442d 100644
45361--- a/drivers/net/ppp/ppp_generic.c
45362+++ b/drivers/net/ppp/ppp_generic.c
45363@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45364 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
45365 struct ppp_stats stats;
45366 struct ppp_comp_stats cstats;
45367- char *vers;
45368
45369 switch (cmd) {
45370 case SIOCGPPPSTATS:
45371@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45372 break;
45373
45374 case SIOCGPPPVER:
45375- vers = PPP_VERSION;
45376- if (copy_to_user(addr, vers, strlen(vers) + 1))
45377+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
45378 break;
45379 err = 0;
45380 break;
45381diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
45382index 1252d9c..80e660b 100644
45383--- a/drivers/net/slip/slhc.c
45384+++ b/drivers/net/slip/slhc.c
45385@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
45386 register struct tcphdr *thp;
45387 register struct iphdr *ip;
45388 register struct cstate *cs;
45389- int len, hdrlen;
45390+ long len, hdrlen;
45391 unsigned char *cp = icp;
45392
45393 /* We've got a compressed packet; read the change byte */
45394diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
45395index b75ae5b..953c157 100644
45396--- a/drivers/net/team/team.c
45397+++ b/drivers/net/team/team.c
45398@@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
45399 return NOTIFY_DONE;
45400 }
45401
45402-static struct notifier_block team_notifier_block __read_mostly = {
45403+static struct notifier_block team_notifier_block = {
45404 .notifier_call = team_device_event,
45405 };
45406
45407diff --git a/drivers/net/tun.c b/drivers/net/tun.c
45408index ecec802..614f08f 100644
45409--- a/drivers/net/tun.c
45410+++ b/drivers/net/tun.c
45411@@ -1839,7 +1839,7 @@ unlock:
45412 }
45413
45414 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45415- unsigned long arg, int ifreq_len)
45416+ unsigned long arg, size_t ifreq_len)
45417 {
45418 struct tun_file *tfile = file->private_data;
45419 struct tun_struct *tun;
45420@@ -1852,6 +1852,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45421 unsigned int ifindex;
45422 int ret;
45423
45424+ if (ifreq_len > sizeof ifr)
45425+ return -EFAULT;
45426+
45427 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
45428 if (copy_from_user(&ifr, argp, ifreq_len))
45429 return -EFAULT;
45430diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
45431index 1a48234..a555339 100644
45432--- a/drivers/net/usb/hso.c
45433+++ b/drivers/net/usb/hso.c
45434@@ -71,7 +71,7 @@
45435 #include <asm/byteorder.h>
45436 #include <linux/serial_core.h>
45437 #include <linux/serial.h>
45438-
45439+#include <asm/local.h>
45440
45441 #define MOD_AUTHOR "Option Wireless"
45442 #define MOD_DESCRIPTION "USB High Speed Option driver"
45443@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
45444 struct urb *urb;
45445
45446 urb = serial->rx_urb[0];
45447- if (serial->port.count > 0) {
45448+ if (atomic_read(&serial->port.count) > 0) {
45449 count = put_rxbuf_data(urb, serial);
45450 if (count == -1)
45451 return;
45452@@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
45453 DUMP1(urb->transfer_buffer, urb->actual_length);
45454
45455 /* Anyone listening? */
45456- if (serial->port.count == 0)
45457+ if (atomic_read(&serial->port.count) == 0)
45458 return;
45459
45460 if (status == 0) {
45461@@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45462 tty_port_tty_set(&serial->port, tty);
45463
45464 /* check for port already opened, if not set the termios */
45465- serial->port.count++;
45466- if (serial->port.count == 1) {
45467+ if (atomic_inc_return(&serial->port.count) == 1) {
45468 serial->rx_state = RX_IDLE;
45469 /* Force default termio settings */
45470 _hso_serial_set_termios(tty, NULL);
45471@@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45472 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
45473 if (result) {
45474 hso_stop_serial_device(serial->parent);
45475- serial->port.count--;
45476+ atomic_dec(&serial->port.count);
45477 kref_put(&serial->parent->ref, hso_serial_ref_free);
45478 }
45479 } else {
45480@@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
45481
45482 /* reset the rts and dtr */
45483 /* do the actual close */
45484- serial->port.count--;
45485+ atomic_dec(&serial->port.count);
45486
45487- if (serial->port.count <= 0) {
45488- serial->port.count = 0;
45489+ if (atomic_read(&serial->port.count) <= 0) {
45490+ atomic_set(&serial->port.count, 0);
45491 tty_port_tty_set(&serial->port, NULL);
45492 if (!usb_gone)
45493 hso_stop_serial_device(serial->parent);
45494@@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
45495
45496 /* the actual setup */
45497 spin_lock_irqsave(&serial->serial_lock, flags);
45498- if (serial->port.count)
45499+ if (atomic_read(&serial->port.count))
45500 _hso_serial_set_termios(tty, old);
45501 else
45502 tty->termios = *old;
45503@@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
45504 D1("Pending read interrupt on port %d\n", i);
45505 spin_lock(&serial->serial_lock);
45506 if (serial->rx_state == RX_IDLE &&
45507- serial->port.count > 0) {
45508+ atomic_read(&serial->port.count) > 0) {
45509 /* Setup and send a ctrl req read on
45510 * port i */
45511 if (!serial->rx_urb_filled[0]) {
45512@@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
45513 /* Start all serial ports */
45514 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
45515 if (serial_table[i] && (serial_table[i]->interface == iface)) {
45516- if (dev2ser(serial_table[i])->port.count) {
45517+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
45518 result =
45519 hso_start_serial_device(serial_table[i], GFP_NOIO);
45520 hso_kick_transmit(dev2ser(serial_table[i]));
45521diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
45522index a79e9d3..78cd4fa 100644
45523--- a/drivers/net/usb/sierra_net.c
45524+++ b/drivers/net/usb/sierra_net.c
45525@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
45526 /* atomic counter partially included in MAC address to make sure 2 devices
45527 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
45528 */
45529-static atomic_t iface_counter = ATOMIC_INIT(0);
45530+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
45531
45532 /*
45533 * SYNC Timer Delay definition used to set the expiry time
45534@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
45535 dev->net->netdev_ops = &sierra_net_device_ops;
45536
45537 /* change MAC addr to include, ifacenum, and to be unique */
45538- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
45539+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
45540 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
45541
45542 /* we will have to manufacture ethernet headers, prepare template */
45543diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
45544index ed384fe..9e3f4f4 100644
45545--- a/drivers/net/vxlan.c
45546+++ b/drivers/net/vxlan.c
45547@@ -2617,7 +2617,7 @@ nla_put_failure:
45548 return -EMSGSIZE;
45549 }
45550
45551-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
45552+static struct rtnl_link_ops vxlan_link_ops = {
45553 .kind = "vxlan",
45554 .maxtype = IFLA_VXLAN_MAX,
45555 .policy = vxlan_policy,
45556diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
45557index 5920c99..ff2e4a5 100644
45558--- a/drivers/net/wan/lmc/lmc_media.c
45559+++ b/drivers/net/wan/lmc/lmc_media.c
45560@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
45561 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
45562
45563 lmc_media_t lmc_ds3_media = {
45564- lmc_ds3_init, /* special media init stuff */
45565- lmc_ds3_default, /* reset to default state */
45566- lmc_ds3_set_status, /* reset status to state provided */
45567- lmc_dummy_set_1, /* set clock source */
45568- lmc_dummy_set2_1, /* set line speed */
45569- lmc_ds3_set_100ft, /* set cable length */
45570- lmc_ds3_set_scram, /* set scrambler */
45571- lmc_ds3_get_link_status, /* get link status */
45572- lmc_dummy_set_1, /* set link status */
45573- lmc_ds3_set_crc_length, /* set CRC length */
45574- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45575- lmc_ds3_watchdog
45576+ .init = lmc_ds3_init, /* special media init stuff */
45577+ .defaults = lmc_ds3_default, /* reset to default state */
45578+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
45579+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
45580+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45581+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
45582+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
45583+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
45584+ .set_link_status = lmc_dummy_set_1, /* set link status */
45585+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
45586+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45587+ .watchdog = lmc_ds3_watchdog
45588 };
45589
45590 lmc_media_t lmc_hssi_media = {
45591- lmc_hssi_init, /* special media init stuff */
45592- lmc_hssi_default, /* reset to default state */
45593- lmc_hssi_set_status, /* reset status to state provided */
45594- lmc_hssi_set_clock, /* set clock source */
45595- lmc_dummy_set2_1, /* set line speed */
45596- lmc_dummy_set_1, /* set cable length */
45597- lmc_dummy_set_1, /* set scrambler */
45598- lmc_hssi_get_link_status, /* get link status */
45599- lmc_hssi_set_link_status, /* set link status */
45600- lmc_hssi_set_crc_length, /* set CRC length */
45601- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45602- lmc_hssi_watchdog
45603+ .init = lmc_hssi_init, /* special media init stuff */
45604+ .defaults = lmc_hssi_default, /* reset to default state */
45605+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
45606+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
45607+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45608+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45609+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45610+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
45611+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
45612+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
45613+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45614+ .watchdog = lmc_hssi_watchdog
45615 };
45616
45617-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
45618- lmc_ssi_default, /* reset to default state */
45619- lmc_ssi_set_status, /* reset status to state provided */
45620- lmc_ssi_set_clock, /* set clock source */
45621- lmc_ssi_set_speed, /* set line speed */
45622- lmc_dummy_set_1, /* set cable length */
45623- lmc_dummy_set_1, /* set scrambler */
45624- lmc_ssi_get_link_status, /* get link status */
45625- lmc_ssi_set_link_status, /* set link status */
45626- lmc_ssi_set_crc_length, /* set CRC length */
45627- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45628- lmc_ssi_watchdog
45629+lmc_media_t lmc_ssi_media = {
45630+ .init = lmc_ssi_init, /* special media init stuff */
45631+ .defaults = lmc_ssi_default, /* reset to default state */
45632+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
45633+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
45634+ .set_speed = lmc_ssi_set_speed, /* set line speed */
45635+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45636+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45637+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
45638+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
45639+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
45640+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45641+ .watchdog = lmc_ssi_watchdog
45642 };
45643
45644 lmc_media_t lmc_t1_media = {
45645- lmc_t1_init, /* special media init stuff */
45646- lmc_t1_default, /* reset to default state */
45647- lmc_t1_set_status, /* reset status to state provided */
45648- lmc_t1_set_clock, /* set clock source */
45649- lmc_dummy_set2_1, /* set line speed */
45650- lmc_dummy_set_1, /* set cable length */
45651- lmc_dummy_set_1, /* set scrambler */
45652- lmc_t1_get_link_status, /* get link status */
45653- lmc_dummy_set_1, /* set link status */
45654- lmc_t1_set_crc_length, /* set CRC length */
45655- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45656- lmc_t1_watchdog
45657+ .init = lmc_t1_init, /* special media init stuff */
45658+ .defaults = lmc_t1_default, /* reset to default state */
45659+ .set_status = lmc_t1_set_status, /* reset status to state provided */
45660+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
45661+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45662+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45663+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45664+ .get_link_status = lmc_t1_get_link_status, /* get link status */
45665+ .set_link_status = lmc_dummy_set_1, /* set link status */
45666+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
45667+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45668+ .watchdog = lmc_t1_watchdog
45669 };
45670
45671 static void
45672diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
45673index feacc3b..5bac0de 100644
45674--- a/drivers/net/wan/z85230.c
45675+++ b/drivers/net/wan/z85230.c
45676@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
45677
45678 struct z8530_irqhandler z8530_sync =
45679 {
45680- z8530_rx,
45681- z8530_tx,
45682- z8530_status
45683+ .rx = z8530_rx,
45684+ .tx = z8530_tx,
45685+ .status = z8530_status
45686 };
45687
45688 EXPORT_SYMBOL(z8530_sync);
45689@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
45690 }
45691
45692 static struct z8530_irqhandler z8530_dma_sync = {
45693- z8530_dma_rx,
45694- z8530_dma_tx,
45695- z8530_dma_status
45696+ .rx = z8530_dma_rx,
45697+ .tx = z8530_dma_tx,
45698+ .status = z8530_dma_status
45699 };
45700
45701 static struct z8530_irqhandler z8530_txdma_sync = {
45702- z8530_rx,
45703- z8530_dma_tx,
45704- z8530_dma_status
45705+ .rx = z8530_rx,
45706+ .tx = z8530_dma_tx,
45707+ .status = z8530_dma_status
45708 };
45709
45710 /**
45711@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
45712
45713 struct z8530_irqhandler z8530_nop=
45714 {
45715- z8530_rx_clear,
45716- z8530_tx_clear,
45717- z8530_status_clear
45718+ .rx = z8530_rx_clear,
45719+ .tx = z8530_tx_clear,
45720+ .status = z8530_status_clear
45721 };
45722
45723
45724diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
45725index 0b60295..b8bfa5b 100644
45726--- a/drivers/net/wimax/i2400m/rx.c
45727+++ b/drivers/net/wimax/i2400m/rx.c
45728@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
45729 if (i2400m->rx_roq == NULL)
45730 goto error_roq_alloc;
45731
45732- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
45733+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
45734 GFP_KERNEL);
45735 if (rd == NULL) {
45736 result = -ENOMEM;
45737diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
45738index edf4b57..68b51c0 100644
45739--- a/drivers/net/wireless/airo.c
45740+++ b/drivers/net/wireless/airo.c
45741@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
45742 struct airo_info *ai = dev->ml_priv;
45743 int ridcode;
45744 int enabled;
45745- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45746+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45747 unsigned char *iobuf;
45748
45749 /* Only super-user can write RIDs */
45750diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
45751index 34c8a33..3261fdc 100644
45752--- a/drivers/net/wireless/at76c50x-usb.c
45753+++ b/drivers/net/wireless/at76c50x-usb.c
45754@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
45755 }
45756
45757 /* Convert timeout from the DFU status to jiffies */
45758-static inline unsigned long at76_get_timeout(struct dfu_status *s)
45759+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
45760 {
45761 return msecs_to_jiffies((s->poll_timeout[2] << 16)
45762 | (s->poll_timeout[1] << 8)
45763diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
45764index edae50b..b24278c 100644
45765--- a/drivers/net/wireless/ath/ath10k/htc.c
45766+++ b/drivers/net/wireless/ath/ath10k/htc.c
45767@@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
45768 /* registered target arrival callback from the HIF layer */
45769 int ath10k_htc_init(struct ath10k *ar)
45770 {
45771- struct ath10k_hif_cb htc_callbacks;
45772+ static struct ath10k_hif_cb htc_callbacks = {
45773+ .rx_completion = ath10k_htc_rx_completion_handler,
45774+ .tx_completion = ath10k_htc_tx_completion_handler,
45775+ };
45776 struct ath10k_htc_ep *ep = NULL;
45777 struct ath10k_htc *htc = &ar->htc;
45778
45779@@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
45780 ath10k_htc_reset_endpoint_states(htc);
45781
45782 /* setup HIF layer callbacks */
45783- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
45784- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
45785 htc->ar = ar;
45786
45787 /* Get HIF default pipe for HTC message exchange */
45788diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
45789index 4716d33..a688310 100644
45790--- a/drivers/net/wireless/ath/ath10k/htc.h
45791+++ b/drivers/net/wireless/ath/ath10k/htc.h
45792@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
45793
45794 struct ath10k_htc_ops {
45795 void (*target_send_suspend_complete)(struct ath10k *ar);
45796-};
45797+} __no_const;
45798
45799 struct ath10k_htc_ep_ops {
45800 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
45801 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
45802 void (*ep_tx_credits)(struct ath10k *);
45803-};
45804+} __no_const;
45805
45806 /* service connection information */
45807 struct ath10k_htc_svc_conn_req {
45808diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45809index a366d6b..b6f28f8 100644
45810--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45811+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45812@@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45813 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
45814 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
45815
45816- ACCESS_ONCE(ads->ds_link) = i->link;
45817- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
45818+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
45819+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
45820
45821 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
45822 ctl6 = SM(i->keytype, AR_EncrType);
45823@@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45824
45825 if ((i->is_first || i->is_last) &&
45826 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
45827- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
45828+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
45829 | set11nTries(i->rates, 1)
45830 | set11nTries(i->rates, 2)
45831 | set11nTries(i->rates, 3)
45832 | (i->dur_update ? AR_DurUpdateEna : 0)
45833 | SM(0, AR_BurstDur);
45834
45835- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
45836+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
45837 | set11nRate(i->rates, 1)
45838 | set11nRate(i->rates, 2)
45839 | set11nRate(i->rates, 3);
45840 } else {
45841- ACCESS_ONCE(ads->ds_ctl2) = 0;
45842- ACCESS_ONCE(ads->ds_ctl3) = 0;
45843+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
45844+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
45845 }
45846
45847 if (!i->is_first) {
45848- ACCESS_ONCE(ads->ds_ctl0) = 0;
45849- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45850- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45851+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
45852+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45853+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45854 return;
45855 }
45856
45857@@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45858 break;
45859 }
45860
45861- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
45862+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
45863 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45864 | SM(i->txpower, AR_XmitPower)
45865 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45866@@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45867 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
45868 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
45869
45870- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45871- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45872+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45873+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45874
45875 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
45876 return;
45877
45878- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45879+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45880 | set11nPktDurRTSCTS(i->rates, 1);
45881
45882- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
45883+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
45884 | set11nPktDurRTSCTS(i->rates, 3);
45885
45886- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45887+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45888 | set11nRateFlags(i->rates, 1)
45889 | set11nRateFlags(i->rates, 2)
45890 | set11nRateFlags(i->rates, 3)
45891diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45892index f6c5c1b..6058354 100644
45893--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45894+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45895@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45896 (i->qcu << AR_TxQcuNum_S) | desc_len;
45897
45898 checksum += val;
45899- ACCESS_ONCE(ads->info) = val;
45900+ ACCESS_ONCE_RW(ads->info) = val;
45901
45902 checksum += i->link;
45903- ACCESS_ONCE(ads->link) = i->link;
45904+ ACCESS_ONCE_RW(ads->link) = i->link;
45905
45906 checksum += i->buf_addr[0];
45907- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
45908+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
45909 checksum += i->buf_addr[1];
45910- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
45911+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
45912 checksum += i->buf_addr[2];
45913- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
45914+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
45915 checksum += i->buf_addr[3];
45916- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
45917+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
45918
45919 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
45920- ACCESS_ONCE(ads->ctl3) = val;
45921+ ACCESS_ONCE_RW(ads->ctl3) = val;
45922 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
45923- ACCESS_ONCE(ads->ctl5) = val;
45924+ ACCESS_ONCE_RW(ads->ctl5) = val;
45925 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
45926- ACCESS_ONCE(ads->ctl7) = val;
45927+ ACCESS_ONCE_RW(ads->ctl7) = val;
45928 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
45929- ACCESS_ONCE(ads->ctl9) = val;
45930+ ACCESS_ONCE_RW(ads->ctl9) = val;
45931
45932 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
45933- ACCESS_ONCE(ads->ctl10) = checksum;
45934+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
45935
45936 if (i->is_first || i->is_last) {
45937- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
45938+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
45939 | set11nTries(i->rates, 1)
45940 | set11nTries(i->rates, 2)
45941 | set11nTries(i->rates, 3)
45942 | (i->dur_update ? AR_DurUpdateEna : 0)
45943 | SM(0, AR_BurstDur);
45944
45945- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
45946+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
45947 | set11nRate(i->rates, 1)
45948 | set11nRate(i->rates, 2)
45949 | set11nRate(i->rates, 3);
45950 } else {
45951- ACCESS_ONCE(ads->ctl13) = 0;
45952- ACCESS_ONCE(ads->ctl14) = 0;
45953+ ACCESS_ONCE_RW(ads->ctl13) = 0;
45954+ ACCESS_ONCE_RW(ads->ctl14) = 0;
45955 }
45956
45957 ads->ctl20 = 0;
45958@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45959
45960 ctl17 = SM(i->keytype, AR_EncrType);
45961 if (!i->is_first) {
45962- ACCESS_ONCE(ads->ctl11) = 0;
45963- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45964- ACCESS_ONCE(ads->ctl15) = 0;
45965- ACCESS_ONCE(ads->ctl16) = 0;
45966- ACCESS_ONCE(ads->ctl17) = ctl17;
45967- ACCESS_ONCE(ads->ctl18) = 0;
45968- ACCESS_ONCE(ads->ctl19) = 0;
45969+ ACCESS_ONCE_RW(ads->ctl11) = 0;
45970+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45971+ ACCESS_ONCE_RW(ads->ctl15) = 0;
45972+ ACCESS_ONCE_RW(ads->ctl16) = 0;
45973+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45974+ ACCESS_ONCE_RW(ads->ctl18) = 0;
45975+ ACCESS_ONCE_RW(ads->ctl19) = 0;
45976 return;
45977 }
45978
45979- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45980+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45981 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45982 | SM(i->txpower, AR_XmitPower)
45983 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45984@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45985 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45986 ctl12 |= SM(val, AR_PAPRDChainMask);
45987
45988- ACCESS_ONCE(ads->ctl12) = ctl12;
45989- ACCESS_ONCE(ads->ctl17) = ctl17;
45990+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45991+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45992
45993- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45994+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45995 | set11nPktDurRTSCTS(i->rates, 1);
45996
45997- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45998+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45999 | set11nPktDurRTSCTS(i->rates, 3);
46000
46001- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46002+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46003 | set11nRateFlags(i->rates, 1)
46004 | set11nRateFlags(i->rates, 2)
46005 | set11nRateFlags(i->rates, 3)
46006 | SM(i->rtscts_rate, AR_RTSCTSRate);
46007
46008- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46009+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46010 }
46011
46012 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46013diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46014index a2c9a5d..b52273e 100644
46015--- a/drivers/net/wireless/ath/ath9k/hw.h
46016+++ b/drivers/net/wireless/ath/ath9k/hw.h
46017@@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46018
46019 /* ANI */
46020 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46021-};
46022+} __no_const;
46023
46024 /**
46025 * struct ath_spec_scan - parameters for Atheros spectral scan
46026@@ -711,7 +711,7 @@ struct ath_hw_ops {
46027 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46028 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46029 #endif
46030-};
46031+} __no_const;
46032
46033 struct ath_nf_limits {
46034 s16 max;
46035diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46036index 92190da..f3a4c4c 100644
46037--- a/drivers/net/wireless/b43/phy_lp.c
46038+++ b/drivers/net/wireless/b43/phy_lp.c
46039@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46040 {
46041 struct ssb_bus *bus = dev->dev->sdev->bus;
46042
46043- static const struct b206x_channel *chandata = NULL;
46044+ const struct b206x_channel *chandata = NULL;
46045 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46046 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46047 u16 old_comm15, scale;
46048diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46049index dea3b50..543db99 100644
46050--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46051+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46052@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46053 */
46054 if (il3945_mod_params.disable_hw_scan) {
46055 D_INFO("Disabling hw_scan\n");
46056- il3945_mac_ops.hw_scan = NULL;
46057+ pax_open_kernel();
46058+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46059+ pax_close_kernel();
46060 }
46061
46062 D_INFO("*** LOAD DRIVER ***\n");
46063diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46064index d94f8ab..5b568c8 100644
46065--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46066+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46067@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46068 {
46069 struct iwl_priv *priv = file->private_data;
46070 char buf[64];
46071- int buf_size;
46072+ size_t buf_size;
46073 u32 offset, len;
46074
46075 memset(buf, 0, sizeof(buf));
46076@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46077 struct iwl_priv *priv = file->private_data;
46078
46079 char buf[8];
46080- int buf_size;
46081+ size_t buf_size;
46082 u32 reset_flag;
46083
46084 memset(buf, 0, sizeof(buf));
46085@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46086 {
46087 struct iwl_priv *priv = file->private_data;
46088 char buf[8];
46089- int buf_size;
46090+ size_t buf_size;
46091 int ht40;
46092
46093 memset(buf, 0, sizeof(buf));
46094@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46095 {
46096 struct iwl_priv *priv = file->private_data;
46097 char buf[8];
46098- int buf_size;
46099+ size_t buf_size;
46100 int value;
46101
46102 memset(buf, 0, sizeof(buf));
46103@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46104 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46105 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46106
46107-static const char *fmt_value = " %-30s %10u\n";
46108-static const char *fmt_hex = " %-30s 0x%02X\n";
46109-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46110-static const char *fmt_header =
46111+static const char fmt_value[] = " %-30s %10u\n";
46112+static const char fmt_hex[] = " %-30s 0x%02X\n";
46113+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46114+static const char fmt_header[] =
46115 "%-32s current cumulative delta max\n";
46116
46117 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46118@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46119 {
46120 struct iwl_priv *priv = file->private_data;
46121 char buf[8];
46122- int buf_size;
46123+ size_t buf_size;
46124 int clear;
46125
46126 memset(buf, 0, sizeof(buf));
46127@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46128 {
46129 struct iwl_priv *priv = file->private_data;
46130 char buf[8];
46131- int buf_size;
46132+ size_t buf_size;
46133 int trace;
46134
46135 memset(buf, 0, sizeof(buf));
46136@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46137 {
46138 struct iwl_priv *priv = file->private_data;
46139 char buf[8];
46140- int buf_size;
46141+ size_t buf_size;
46142 int missed;
46143
46144 memset(buf, 0, sizeof(buf));
46145@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46146
46147 struct iwl_priv *priv = file->private_data;
46148 char buf[8];
46149- int buf_size;
46150+ size_t buf_size;
46151 int plcp;
46152
46153 memset(buf, 0, sizeof(buf));
46154@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46155
46156 struct iwl_priv *priv = file->private_data;
46157 char buf[8];
46158- int buf_size;
46159+ size_t buf_size;
46160 int flush;
46161
46162 memset(buf, 0, sizeof(buf));
46163@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46164
46165 struct iwl_priv *priv = file->private_data;
46166 char buf[8];
46167- int buf_size;
46168+ size_t buf_size;
46169 int rts;
46170
46171 if (!priv->cfg->ht_params)
46172@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46173 {
46174 struct iwl_priv *priv = file->private_data;
46175 char buf[8];
46176- int buf_size;
46177+ size_t buf_size;
46178
46179 memset(buf, 0, sizeof(buf));
46180 buf_size = min(count, sizeof(buf) - 1);
46181@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46182 struct iwl_priv *priv = file->private_data;
46183 u32 event_log_flag;
46184 char buf[8];
46185- int buf_size;
46186+ size_t buf_size;
46187
46188 /* check that the interface is up */
46189 if (!iwl_is_ready(priv))
46190@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46191 struct iwl_priv *priv = file->private_data;
46192 char buf[8];
46193 u32 calib_disabled;
46194- int buf_size;
46195+ size_t buf_size;
46196
46197 memset(buf, 0, sizeof(buf));
46198 buf_size = min(count, sizeof(buf) - 1);
46199diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46200index 7aad766..06addb4 100644
46201--- a/drivers/net/wireless/iwlwifi/dvm/main.c
46202+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46203@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46204 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46205 {
46206 struct iwl_nvm_data *data = priv->nvm_data;
46207- char *debug_msg;
46208+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46209
46210 if (data->sku_cap_11n_enable &&
46211 !priv->cfg->ht_params) {
46212@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46213 return -EINVAL;
46214 }
46215
46216- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46217 IWL_DEBUG_INFO(priv, debug_msg,
46218 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46219 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46220diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46221index cde9c16..e485cfe 100644
46222--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46223+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46224@@ -1368,7 +1368,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46225 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46226
46227 char buf[8];
46228- int buf_size;
46229+ size_t buf_size;
46230 u32 reset_flag;
46231
46232 memset(buf, 0, sizeof(buf));
46233@@ -1389,7 +1389,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46234 {
46235 struct iwl_trans *trans = file->private_data;
46236 char buf[8];
46237- int buf_size;
46238+ size_t buf_size;
46239 int csr;
46240
46241 memset(buf, 0, sizeof(buf));
46242diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
46243index a1b32ee..94b3c3d 100644
46244--- a/drivers/net/wireless/mac80211_hwsim.c
46245+++ b/drivers/net/wireless/mac80211_hwsim.c
46246@@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
46247
46248 if (channels > 1) {
46249 hwsim_if_comb.num_different_channels = channels;
46250- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46251- mac80211_hwsim_ops.cancel_hw_scan =
46252- mac80211_hwsim_cancel_hw_scan;
46253- mac80211_hwsim_ops.sw_scan_start = NULL;
46254- mac80211_hwsim_ops.sw_scan_complete = NULL;
46255- mac80211_hwsim_ops.remain_on_channel =
46256- mac80211_hwsim_roc;
46257- mac80211_hwsim_ops.cancel_remain_on_channel =
46258- mac80211_hwsim_croc;
46259- mac80211_hwsim_ops.add_chanctx =
46260- mac80211_hwsim_add_chanctx;
46261- mac80211_hwsim_ops.remove_chanctx =
46262- mac80211_hwsim_remove_chanctx;
46263- mac80211_hwsim_ops.change_chanctx =
46264- mac80211_hwsim_change_chanctx;
46265- mac80211_hwsim_ops.assign_vif_chanctx =
46266- mac80211_hwsim_assign_vif_chanctx;
46267- mac80211_hwsim_ops.unassign_vif_chanctx =
46268- mac80211_hwsim_unassign_vif_chanctx;
46269+ pax_open_kernel();
46270+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46271+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46272+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
46273+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
46274+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
46275+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46276+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46277+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46278+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
46279+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
46280+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
46281+ pax_close_kernel();
46282 }
46283
46284 spin_lock_init(&hwsim_radio_lock);
46285diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
46286index 8169a85..7fa3b47 100644
46287--- a/drivers/net/wireless/rndis_wlan.c
46288+++ b/drivers/net/wireless/rndis_wlan.c
46289@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
46290
46291 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
46292
46293- if (rts_threshold < 0 || rts_threshold > 2347)
46294+ if (rts_threshold > 2347)
46295 rts_threshold = 2347;
46296
46297 tmp = cpu_to_le32(rts_threshold);
46298diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
46299index e4ba2ce..63d7417 100644
46300--- a/drivers/net/wireless/rt2x00/rt2x00.h
46301+++ b/drivers/net/wireless/rt2x00/rt2x00.h
46302@@ -377,7 +377,7 @@ struct rt2x00_intf {
46303 * for hardware which doesn't support hardware
46304 * sequence counting.
46305 */
46306- atomic_t seqno;
46307+ atomic_unchecked_t seqno;
46308 };
46309
46310 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
46311diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
46312index a5d38e8..d3c24ea 100644
46313--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
46314+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
46315@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
46316 * sequence counter given by mac80211.
46317 */
46318 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
46319- seqno = atomic_add_return(0x10, &intf->seqno);
46320+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
46321 else
46322- seqno = atomic_read(&intf->seqno);
46323+ seqno = atomic_read_unchecked(&intf->seqno);
46324
46325 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
46326 hdr->seq_ctrl |= cpu_to_le16(seqno);
46327diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
46328index e2b3d9c..67a5184 100644
46329--- a/drivers/net/wireless/ti/wl1251/sdio.c
46330+++ b/drivers/net/wireless/ti/wl1251/sdio.c
46331@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
46332
46333 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
46334
46335- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46336- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46337+ pax_open_kernel();
46338+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46339+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46340+ pax_close_kernel();
46341
46342 wl1251_info("using dedicated interrupt line");
46343 } else {
46344- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46345- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46346+ pax_open_kernel();
46347+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46348+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46349+ pax_close_kernel();
46350
46351 wl1251_info("using SDIO interrupt");
46352 }
46353diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
46354index be7129b..4161356 100644
46355--- a/drivers/net/wireless/ti/wl12xx/main.c
46356+++ b/drivers/net/wireless/ti/wl12xx/main.c
46357@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46358 sizeof(wl->conf.mem));
46359
46360 /* read data preparation is only needed by wl127x */
46361- wl->ops->prepare_read = wl127x_prepare_read;
46362+ pax_open_kernel();
46363+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46364+ pax_close_kernel();
46365
46366 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46367 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46368@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46369 sizeof(wl->conf.mem));
46370
46371 /* read data preparation is only needed by wl127x */
46372- wl->ops->prepare_read = wl127x_prepare_read;
46373+ pax_open_kernel();
46374+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46375+ pax_close_kernel();
46376
46377 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46378 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46379diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
46380index ec37b16..7e34d66 100644
46381--- a/drivers/net/wireless/ti/wl18xx/main.c
46382+++ b/drivers/net/wireless/ti/wl18xx/main.c
46383@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
46384 }
46385
46386 if (!checksum_param) {
46387- wl18xx_ops.set_rx_csum = NULL;
46388- wl18xx_ops.init_vif = NULL;
46389+ pax_open_kernel();
46390+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
46391+ *(void **)&wl18xx_ops.init_vif = NULL;
46392+ pax_close_kernel();
46393 }
46394
46395 /* Enable 11a Band only if we have 5G antennas */
46396diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
46397index 84d94f5..bd6c61c 100644
46398--- a/drivers/net/wireless/zd1211rw/zd_usb.c
46399+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
46400@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
46401 {
46402 struct zd_usb *usb = urb->context;
46403 struct zd_usb_interrupt *intr = &usb->intr;
46404- int len;
46405+ unsigned int len;
46406 u16 int_num;
46407
46408 ZD_ASSERT(in_interrupt());
46409diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
46410index 7130864..00e64de 100644
46411--- a/drivers/nfc/nfcwilink.c
46412+++ b/drivers/nfc/nfcwilink.c
46413@@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
46414
46415 static int nfcwilink_probe(struct platform_device *pdev)
46416 {
46417- static struct nfcwilink *drv;
46418+ struct nfcwilink *drv;
46419 int rc;
46420 __u32 protocols;
46421
46422diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
46423index d93b2b6..ae50401 100644
46424--- a/drivers/oprofile/buffer_sync.c
46425+++ b/drivers/oprofile/buffer_sync.c
46426@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
46427 if (cookie == NO_COOKIE)
46428 offset = pc;
46429 if (cookie == INVALID_COOKIE) {
46430- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46431+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46432 offset = pc;
46433 }
46434 if (cookie != last_cookie) {
46435@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
46436 /* add userspace sample */
46437
46438 if (!mm) {
46439- atomic_inc(&oprofile_stats.sample_lost_no_mm);
46440+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
46441 return 0;
46442 }
46443
46444 cookie = lookup_dcookie(mm, s->eip, &offset);
46445
46446 if (cookie == INVALID_COOKIE) {
46447- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46448+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46449 return 0;
46450 }
46451
46452@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
46453 /* ignore backtraces if failed to add a sample */
46454 if (state == sb_bt_start) {
46455 state = sb_bt_ignore;
46456- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
46457+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
46458 }
46459 }
46460 release_mm(mm);
46461diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
46462index c0cc4e7..44d4e54 100644
46463--- a/drivers/oprofile/event_buffer.c
46464+++ b/drivers/oprofile/event_buffer.c
46465@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
46466 }
46467
46468 if (buffer_pos == buffer_size) {
46469- atomic_inc(&oprofile_stats.event_lost_overflow);
46470+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
46471 return;
46472 }
46473
46474diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
46475index ed2c3ec..deda85a 100644
46476--- a/drivers/oprofile/oprof.c
46477+++ b/drivers/oprofile/oprof.c
46478@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
46479 if (oprofile_ops.switch_events())
46480 return;
46481
46482- atomic_inc(&oprofile_stats.multiplex_counter);
46483+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
46484 start_switch_worker();
46485 }
46486
46487diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
46488index ee2cfce..7f8f699 100644
46489--- a/drivers/oprofile/oprofile_files.c
46490+++ b/drivers/oprofile/oprofile_files.c
46491@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
46492
46493 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
46494
46495-static ssize_t timeout_read(struct file *file, char __user *buf,
46496+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
46497 size_t count, loff_t *offset)
46498 {
46499 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
46500diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
46501index 59659ce..6c860a0 100644
46502--- a/drivers/oprofile/oprofile_stats.c
46503+++ b/drivers/oprofile/oprofile_stats.c
46504@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
46505 cpu_buf->sample_invalid_eip = 0;
46506 }
46507
46508- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
46509- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
46510- atomic_set(&oprofile_stats.event_lost_overflow, 0);
46511- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
46512- atomic_set(&oprofile_stats.multiplex_counter, 0);
46513+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
46514+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
46515+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
46516+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
46517+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
46518 }
46519
46520
46521diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
46522index 1fc622b..8c48fc3 100644
46523--- a/drivers/oprofile/oprofile_stats.h
46524+++ b/drivers/oprofile/oprofile_stats.h
46525@@ -13,11 +13,11 @@
46526 #include <linux/atomic.h>
46527
46528 struct oprofile_stat_struct {
46529- atomic_t sample_lost_no_mm;
46530- atomic_t sample_lost_no_mapping;
46531- atomic_t bt_lost_no_mapping;
46532- atomic_t event_lost_overflow;
46533- atomic_t multiplex_counter;
46534+ atomic_unchecked_t sample_lost_no_mm;
46535+ atomic_unchecked_t sample_lost_no_mapping;
46536+ atomic_unchecked_t bt_lost_no_mapping;
46537+ atomic_unchecked_t event_lost_overflow;
46538+ atomic_unchecked_t multiplex_counter;
46539 };
46540
46541 extern struct oprofile_stat_struct oprofile_stats;
46542diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
46543index 3f49345..c750d0b 100644
46544--- a/drivers/oprofile/oprofilefs.c
46545+++ b/drivers/oprofile/oprofilefs.c
46546@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
46547
46548 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
46549 {
46550- atomic_t *val = file->private_data;
46551- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
46552+ atomic_unchecked_t *val = file->private_data;
46553+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
46554 }
46555
46556
46557@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
46558
46559
46560 int oprofilefs_create_ro_atomic(struct dentry *root,
46561- char const *name, atomic_t *val)
46562+ char const *name, atomic_unchecked_t *val)
46563 {
46564 return __oprofilefs_create_file(root, name,
46565 &atomic_ro_fops, 0444, val);
46566diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
46567index 61be1d9..dec05d7 100644
46568--- a/drivers/oprofile/timer_int.c
46569+++ b/drivers/oprofile/timer_int.c
46570@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
46571 return NOTIFY_OK;
46572 }
46573
46574-static struct notifier_block __refdata oprofile_cpu_notifier = {
46575+static struct notifier_block oprofile_cpu_notifier = {
46576 .notifier_call = oprofile_cpu_notify,
46577 };
46578
46579diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
46580index 92ed045..62d39bd7 100644
46581--- a/drivers/parport/procfs.c
46582+++ b/drivers/parport/procfs.c
46583@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
46584
46585 *ppos += len;
46586
46587- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
46588+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
46589 }
46590
46591 #ifdef CONFIG_PARPORT_1284
46592@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
46593
46594 *ppos += len;
46595
46596- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
46597+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
46598 }
46599 #endif /* IEEE1284.3 support. */
46600
46601diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
46602index ecfac7e..41be7028 100644
46603--- a/drivers/pci/hotplug/acpiphp_ibm.c
46604+++ b/drivers/pci/hotplug/acpiphp_ibm.c
46605@@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
46606 goto init_cleanup;
46607 }
46608
46609- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46610+ pax_open_kernel();
46611+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46612+ pax_close_kernel();
46613 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
46614
46615 return retval;
46616diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
46617index 7536eef..52dc8fa 100644
46618--- a/drivers/pci/hotplug/cpcihp_generic.c
46619+++ b/drivers/pci/hotplug/cpcihp_generic.c
46620@@ -73,7 +73,6 @@ static u16 port;
46621 static unsigned int enum_bit;
46622 static u8 enum_mask;
46623
46624-static struct cpci_hp_controller_ops generic_hpc_ops;
46625 static struct cpci_hp_controller generic_hpc;
46626
46627 static int __init validate_parameters(void)
46628@@ -139,6 +138,10 @@ static int query_enum(void)
46629 return ((value & enum_mask) == enum_mask);
46630 }
46631
46632+static struct cpci_hp_controller_ops generic_hpc_ops = {
46633+ .query_enum = query_enum,
46634+};
46635+
46636 static int __init cpcihp_generic_init(void)
46637 {
46638 int status;
46639@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
46640 pci_dev_put(dev);
46641
46642 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
46643- generic_hpc_ops.query_enum = query_enum;
46644 generic_hpc.ops = &generic_hpc_ops;
46645
46646 status = cpci_hp_register_controller(&generic_hpc);
46647diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
46648index e8c4a7c..7046f5c 100644
46649--- a/drivers/pci/hotplug/cpcihp_zt5550.c
46650+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
46651@@ -59,7 +59,6 @@
46652 /* local variables */
46653 static bool debug;
46654 static bool poll;
46655-static struct cpci_hp_controller_ops zt5550_hpc_ops;
46656 static struct cpci_hp_controller zt5550_hpc;
46657
46658 /* Primary cPCI bus bridge device */
46659@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
46660 return 0;
46661 }
46662
46663+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
46664+ .query_enum = zt5550_hc_query_enum,
46665+};
46666+
46667 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
46668 {
46669 int status;
46670@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
46671 dbg("returned from zt5550_hc_config");
46672
46673 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
46674- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
46675 zt5550_hpc.ops = &zt5550_hpc_ops;
46676 if(!poll) {
46677 zt5550_hpc.irq = hc_dev->irq;
46678 zt5550_hpc.irq_flags = IRQF_SHARED;
46679 zt5550_hpc.dev_id = hc_dev;
46680
46681- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46682- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46683- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46684+ pax_open_kernel();
46685+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46686+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46687+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46688+ pax_open_kernel();
46689 } else {
46690 info("using ENUM# polling mode");
46691 }
46692diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
46693index 76ba8a1..20ca857 100644
46694--- a/drivers/pci/hotplug/cpqphp_nvram.c
46695+++ b/drivers/pci/hotplug/cpqphp_nvram.c
46696@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
46697
46698 void compaq_nvram_init (void __iomem *rom_start)
46699 {
46700+
46701+#ifndef CONFIG_PAX_KERNEXEC
46702 if (rom_start) {
46703 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
46704 }
46705+#endif
46706+
46707 dbg("int15 entry = %p\n", compaq_int15_entry_point);
46708
46709 /* initialize our int15 lock */
46710diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
46711index cfa92a9..29539c5 100644
46712--- a/drivers/pci/hotplug/pci_hotplug_core.c
46713+++ b/drivers/pci/hotplug/pci_hotplug_core.c
46714@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
46715 return -EINVAL;
46716 }
46717
46718- slot->ops->owner = owner;
46719- slot->ops->mod_name = mod_name;
46720+ pax_open_kernel();
46721+ *(struct module **)&slot->ops->owner = owner;
46722+ *(const char **)&slot->ops->mod_name = mod_name;
46723+ pax_close_kernel();
46724
46725 mutex_lock(&pci_hp_mutex);
46726 /*
46727diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
46728index bbd48bb..6907ef4 100644
46729--- a/drivers/pci/hotplug/pciehp_core.c
46730+++ b/drivers/pci/hotplug/pciehp_core.c
46731@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
46732 struct slot *slot = ctrl->slot;
46733 struct hotplug_slot *hotplug = NULL;
46734 struct hotplug_slot_info *info = NULL;
46735- struct hotplug_slot_ops *ops = NULL;
46736+ hotplug_slot_ops_no_const *ops = NULL;
46737 char name[SLOT_NAME_SIZE];
46738 int retval = -ENOMEM;
46739
46740diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
46741index c91e6c1..5c723ef 100644
46742--- a/drivers/pci/pci-sysfs.c
46743+++ b/drivers/pci/pci-sysfs.c
46744@@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
46745 {
46746 /* allocate attribute structure, piggyback attribute name */
46747 int name_len = write_combine ? 13 : 10;
46748- struct bin_attribute *res_attr;
46749+ bin_attribute_no_const *res_attr;
46750 int retval;
46751
46752 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
46753@@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
46754 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
46755 {
46756 int retval;
46757- struct bin_attribute *attr;
46758+ bin_attribute_no_const *attr;
46759
46760 /* If the device has VPD, try to expose it in sysfs. */
46761 if (dev->vpd) {
46762@@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
46763 {
46764 int retval;
46765 int rom_size = 0;
46766- struct bin_attribute *attr;
46767+ bin_attribute_no_const *attr;
46768
46769 if (!sysfs_initialized)
46770 return -EACCES;
46771diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
46772index 9c91ecc..bda4796 100644
46773--- a/drivers/pci/pci.h
46774+++ b/drivers/pci/pci.h
46775@@ -95,7 +95,7 @@ struct pci_vpd_ops {
46776 struct pci_vpd {
46777 unsigned int len;
46778 const struct pci_vpd_ops *ops;
46779- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
46780+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
46781 };
46782
46783 int pci_vpd_pci22_init(struct pci_dev *dev);
46784diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
46785index f1272dc..e92a1ac 100644
46786--- a/drivers/pci/pcie/aspm.c
46787+++ b/drivers/pci/pcie/aspm.c
46788@@ -27,9 +27,9 @@
46789 #define MODULE_PARAM_PREFIX "pcie_aspm."
46790
46791 /* Note: those are not register definitions */
46792-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
46793-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
46794-#define ASPM_STATE_L1 (4) /* L1 state */
46795+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
46796+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
46797+#define ASPM_STATE_L1 (4U) /* L1 state */
46798 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
46799 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
46800
46801diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
46802index 38e403d..a2ce55a 100644
46803--- a/drivers/pci/probe.c
46804+++ b/drivers/pci/probe.c
46805@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
46806 struct pci_bus_region region, inverted_region;
46807 bool bar_too_big = false, bar_disabled = false;
46808
46809- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
46810+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
46811
46812 /* No printks while decoding is disabled! */
46813 if (!dev->mmio_always_on) {
46814diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
46815index 46d1378..30e452b 100644
46816--- a/drivers/pci/proc.c
46817+++ b/drivers/pci/proc.c
46818@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
46819 static int __init pci_proc_init(void)
46820 {
46821 struct pci_dev *dev = NULL;
46822+
46823+#ifdef CONFIG_GRKERNSEC_PROC_ADD
46824+#ifdef CONFIG_GRKERNSEC_PROC_USER
46825+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
46826+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46827+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46828+#endif
46829+#else
46830 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
46831+#endif
46832 proc_create("devices", 0, proc_bus_pci_dir,
46833 &proc_bus_pci_dev_operations);
46834 proc_initialized = 1;
46835diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
46836index 3e5b4497..dcdfb70 100644
46837--- a/drivers/platform/chrome/chromeos_laptop.c
46838+++ b/drivers/platform/chrome/chromeos_laptop.c
46839@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
46840 return 0;
46841 }
46842
46843-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
46844+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
46845 {
46846 .ident = "Samsung Series 5 550 - Touchpad",
46847 .matches = {
46848diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
46849index 19c313b..ed28b38 100644
46850--- a/drivers/platform/x86/asus-wmi.c
46851+++ b/drivers/platform/x86/asus-wmi.c
46852@@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
46853 int err;
46854 u32 retval = -1;
46855
46856+#ifdef CONFIG_GRKERNSEC_KMEM
46857+ return -EPERM;
46858+#endif
46859+
46860 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
46861
46862 if (err < 0)
46863@@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
46864 int err;
46865 u32 retval = -1;
46866
46867+#ifdef CONFIG_GRKERNSEC_KMEM
46868+ return -EPERM;
46869+#endif
46870+
46871 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
46872 &retval);
46873
46874@@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
46875 union acpi_object *obj;
46876 acpi_status status;
46877
46878+#ifdef CONFIG_GRKERNSEC_KMEM
46879+ return -EPERM;
46880+#endif
46881+
46882 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
46883 1, asus->debug.method_id,
46884 &input, &output);
46885diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
46886index 62f8030..c7f2a45 100644
46887--- a/drivers/platform/x86/msi-laptop.c
46888+++ b/drivers/platform/x86/msi-laptop.c
46889@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
46890
46891 if (!quirks->ec_read_only) {
46892 /* allow userland write sysfs file */
46893- dev_attr_bluetooth.store = store_bluetooth;
46894- dev_attr_wlan.store = store_wlan;
46895- dev_attr_threeg.store = store_threeg;
46896- dev_attr_bluetooth.attr.mode |= S_IWUSR;
46897- dev_attr_wlan.attr.mode |= S_IWUSR;
46898- dev_attr_threeg.attr.mode |= S_IWUSR;
46899+ pax_open_kernel();
46900+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
46901+ *(void **)&dev_attr_wlan.store = store_wlan;
46902+ *(void **)&dev_attr_threeg.store = store_threeg;
46903+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
46904+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
46905+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
46906+ pax_close_kernel();
46907 }
46908
46909 /* disable hardware control by fn key */
46910diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
46911index 70222f2..8c8ce66 100644
46912--- a/drivers/platform/x86/msi-wmi.c
46913+++ b/drivers/platform/x86/msi-wmi.c
46914@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
46915 static void msi_wmi_notify(u32 value, void *context)
46916 {
46917 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
46918- static struct key_entry *key;
46919+ struct key_entry *key;
46920 union acpi_object *obj;
46921 acpi_status status;
46922
46923diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
46924index fb233ae..23a325c 100644
46925--- a/drivers/platform/x86/sony-laptop.c
46926+++ b/drivers/platform/x86/sony-laptop.c
46927@@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
46928 }
46929
46930 /* High speed charging function */
46931-static struct device_attribute *hsc_handle;
46932+static device_attribute_no_const *hsc_handle;
46933
46934 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
46935 struct device_attribute *attr,
46936diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
46937index 58b0274..6704626 100644
46938--- a/drivers/platform/x86/thinkpad_acpi.c
46939+++ b/drivers/platform/x86/thinkpad_acpi.c
46940@@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
46941 return 0;
46942 }
46943
46944-void static hotkey_mask_warn_incomplete_mask(void)
46945+static void hotkey_mask_warn_incomplete_mask(void)
46946 {
46947 /* log only what the user can fix... */
46948 const u32 wantedmask = hotkey_driver_mask &
46949@@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
46950 }
46951 }
46952
46953-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46954- struct tp_nvram_state *newn,
46955- const u32 event_mask)
46956-{
46957-
46958 #define TPACPI_COMPARE_KEY(__scancode, __member) \
46959 do { \
46960 if ((event_mask & (1 << __scancode)) && \
46961@@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46962 tpacpi_hotkey_send_key(__scancode); \
46963 } while (0)
46964
46965- void issue_volchange(const unsigned int oldvol,
46966- const unsigned int newvol)
46967- {
46968- unsigned int i = oldvol;
46969+static void issue_volchange(const unsigned int oldvol,
46970+ const unsigned int newvol,
46971+ const u32 event_mask)
46972+{
46973+ unsigned int i = oldvol;
46974
46975- while (i > newvol) {
46976- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46977- i--;
46978- }
46979- while (i < newvol) {
46980- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46981- i++;
46982- }
46983+ while (i > newvol) {
46984+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46985+ i--;
46986 }
46987+ while (i < newvol) {
46988+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46989+ i++;
46990+ }
46991+}
46992
46993- void issue_brightnesschange(const unsigned int oldbrt,
46994- const unsigned int newbrt)
46995- {
46996- unsigned int i = oldbrt;
46997+static void issue_brightnesschange(const unsigned int oldbrt,
46998+ const unsigned int newbrt,
46999+ const u32 event_mask)
47000+{
47001+ unsigned int i = oldbrt;
47002
47003- while (i > newbrt) {
47004- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47005- i--;
47006- }
47007- while (i < newbrt) {
47008- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47009- i++;
47010- }
47011+ while (i > newbrt) {
47012+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47013+ i--;
47014+ }
47015+ while (i < newbrt) {
47016+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47017+ i++;
47018 }
47019+}
47020
47021+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47022+ struct tp_nvram_state *newn,
47023+ const u32 event_mask)
47024+{
47025 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47026 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47027 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47028@@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47029 oldn->volume_level != newn->volume_level) {
47030 /* recently muted, or repeated mute keypress, or
47031 * multiple presses ending in mute */
47032- issue_volchange(oldn->volume_level, newn->volume_level);
47033+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47034 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47035 }
47036 } else {
47037@@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47038 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47039 }
47040 if (oldn->volume_level != newn->volume_level) {
47041- issue_volchange(oldn->volume_level, newn->volume_level);
47042+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47043 } else if (oldn->volume_toggle != newn->volume_toggle) {
47044 /* repeated vol up/down keypress at end of scale ? */
47045 if (newn->volume_level == 0)
47046@@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47047 /* handle brightness */
47048 if (oldn->brightness_level != newn->brightness_level) {
47049 issue_brightnesschange(oldn->brightness_level,
47050- newn->brightness_level);
47051+ newn->brightness_level,
47052+ event_mask);
47053 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47054 /* repeated key presses that didn't change state */
47055 if (newn->brightness_level == 0)
47056@@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47057 && !tp_features.bright_unkfw)
47058 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47059 }
47060+}
47061
47062 #undef TPACPI_COMPARE_KEY
47063 #undef TPACPI_MAY_SEND_KEY
47064-}
47065
47066 /*
47067 * Polling driver
47068diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47069index 769d265..a3a05ca 100644
47070--- a/drivers/pnp/pnpbios/bioscalls.c
47071+++ b/drivers/pnp/pnpbios/bioscalls.c
47072@@ -58,7 +58,7 @@ do { \
47073 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47074 } while(0)
47075
47076-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47077+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47078 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47079
47080 /*
47081@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47082
47083 cpu = get_cpu();
47084 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47085+
47086+ pax_open_kernel();
47087 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47088+ pax_close_kernel();
47089
47090 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47091 spin_lock_irqsave(&pnp_bios_lock, flags);
47092@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47093 :"memory");
47094 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47095
47096+ pax_open_kernel();
47097 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47098+ pax_close_kernel();
47099+
47100 put_cpu();
47101
47102 /* If we get here and this is set then the PnP BIOS faulted on us. */
47103@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47104 return status;
47105 }
47106
47107-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47108+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47109 {
47110 int i;
47111
47112@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47113 pnp_bios_callpoint.offset = header->fields.pm16offset;
47114 pnp_bios_callpoint.segment = PNP_CS16;
47115
47116+ pax_open_kernel();
47117+
47118 for_each_possible_cpu(i) {
47119 struct desc_struct *gdt = get_cpu_gdt_table(i);
47120 if (!gdt)
47121@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47122 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47123 (unsigned long)__va(header->fields.pm16dseg));
47124 }
47125+
47126+ pax_close_kernel();
47127 }
47128diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47129index d95e101..67f0c3f 100644
47130--- a/drivers/pnp/resource.c
47131+++ b/drivers/pnp/resource.c
47132@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47133 return 1;
47134
47135 /* check if the resource is valid */
47136- if (*irq < 0 || *irq > 15)
47137+ if (*irq > 15)
47138 return 0;
47139
47140 /* check if the resource is reserved */
47141@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47142 return 1;
47143
47144 /* check if the resource is valid */
47145- if (*dma < 0 || *dma == 4 || *dma > 7)
47146+ if (*dma == 4 || *dma > 7)
47147 return 0;
47148
47149 /* check if the resource is reserved */
47150diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47151index 0c52e2a..3421ab7 100644
47152--- a/drivers/power/pda_power.c
47153+++ b/drivers/power/pda_power.c
47154@@ -37,7 +37,11 @@ static int polling;
47155
47156 #if IS_ENABLED(CONFIG_USB_PHY)
47157 static struct usb_phy *transceiver;
47158-static struct notifier_block otg_nb;
47159+static int otg_handle_notification(struct notifier_block *nb,
47160+ unsigned long event, void *unused);
47161+static struct notifier_block otg_nb = {
47162+ .notifier_call = otg_handle_notification
47163+};
47164 #endif
47165
47166 static struct regulator *ac_draw;
47167@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47168
47169 #if IS_ENABLED(CONFIG_USB_PHY)
47170 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47171- otg_nb.notifier_call = otg_handle_notification;
47172 ret = usb_register_notifier(transceiver, &otg_nb);
47173 if (ret) {
47174 dev_err(dev, "failure to register otg notifier\n");
47175diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47176index cc439fd..8fa30df 100644
47177--- a/drivers/power/power_supply.h
47178+++ b/drivers/power/power_supply.h
47179@@ -16,12 +16,12 @@ struct power_supply;
47180
47181 #ifdef CONFIG_SYSFS
47182
47183-extern void power_supply_init_attrs(struct device_type *dev_type);
47184+extern void power_supply_init_attrs(void);
47185 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47186
47187 #else
47188
47189-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47190+static inline void power_supply_init_attrs(void) {}
47191 #define power_supply_uevent NULL
47192
47193 #endif /* CONFIG_SYSFS */
47194diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47195index 557af94..84dc1fe 100644
47196--- a/drivers/power/power_supply_core.c
47197+++ b/drivers/power/power_supply_core.c
47198@@ -24,7 +24,10 @@
47199 struct class *power_supply_class;
47200 EXPORT_SYMBOL_GPL(power_supply_class);
47201
47202-static struct device_type power_supply_dev_type;
47203+extern const struct attribute_group *power_supply_attr_groups[];
47204+static struct device_type power_supply_dev_type = {
47205+ .groups = power_supply_attr_groups,
47206+};
47207
47208 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47209 struct power_supply *supply)
47210@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47211 return PTR_ERR(power_supply_class);
47212
47213 power_supply_class->dev_uevent = power_supply_uevent;
47214- power_supply_init_attrs(&power_supply_dev_type);
47215+ power_supply_init_attrs();
47216
47217 return 0;
47218 }
47219diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47220index 44420d1..967126e 100644
47221--- a/drivers/power/power_supply_sysfs.c
47222+++ b/drivers/power/power_supply_sysfs.c
47223@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47224 .is_visible = power_supply_attr_is_visible,
47225 };
47226
47227-static const struct attribute_group *power_supply_attr_groups[] = {
47228+const struct attribute_group *power_supply_attr_groups[] = {
47229 &power_supply_attr_group,
47230 NULL,
47231 };
47232
47233-void power_supply_init_attrs(struct device_type *dev_type)
47234+void power_supply_init_attrs(void)
47235 {
47236 int i;
47237
47238- dev_type->groups = power_supply_attr_groups;
47239-
47240 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
47241 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
47242 }
47243diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
47244index 84419af..268ede8 100644
47245--- a/drivers/powercap/powercap_sys.c
47246+++ b/drivers/powercap/powercap_sys.c
47247@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
47248 struct device_attribute name_attr;
47249 };
47250
47251+static ssize_t show_constraint_name(struct device *dev,
47252+ struct device_attribute *dev_attr,
47253+ char *buf);
47254+
47255 static struct powercap_constraint_attr
47256- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
47257+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
47258+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
47259+ .power_limit_attr = {
47260+ .attr = {
47261+ .name = NULL,
47262+ .mode = S_IWUSR | S_IRUGO
47263+ },
47264+ .show = show_constraint_power_limit_uw,
47265+ .store = store_constraint_power_limit_uw
47266+ },
47267+
47268+ .time_window_attr = {
47269+ .attr = {
47270+ .name = NULL,
47271+ .mode = S_IWUSR | S_IRUGO
47272+ },
47273+ .show = show_constraint_time_window_us,
47274+ .store = store_constraint_time_window_us
47275+ },
47276+
47277+ .max_power_attr = {
47278+ .attr = {
47279+ .name = NULL,
47280+ .mode = S_IRUGO
47281+ },
47282+ .show = show_constraint_max_power_uw,
47283+ .store = NULL
47284+ },
47285+
47286+ .min_power_attr = {
47287+ .attr = {
47288+ .name = NULL,
47289+ .mode = S_IRUGO
47290+ },
47291+ .show = show_constraint_min_power_uw,
47292+ .store = NULL
47293+ },
47294+
47295+ .max_time_window_attr = {
47296+ .attr = {
47297+ .name = NULL,
47298+ .mode = S_IRUGO
47299+ },
47300+ .show = show_constraint_max_time_window_us,
47301+ .store = NULL
47302+ },
47303+
47304+ .min_time_window_attr = {
47305+ .attr = {
47306+ .name = NULL,
47307+ .mode = S_IRUGO
47308+ },
47309+ .show = show_constraint_min_time_window_us,
47310+ .store = NULL
47311+ },
47312+
47313+ .name_attr = {
47314+ .attr = {
47315+ .name = NULL,
47316+ .mode = S_IRUGO
47317+ },
47318+ .show = show_constraint_name,
47319+ .store = NULL
47320+ }
47321+ }
47322+};
47323
47324 /* A list of powercap control_types */
47325 static LIST_HEAD(powercap_cntrl_list);
47326@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
47327 }
47328
47329 static int create_constraint_attribute(int id, const char *name,
47330- int mode,
47331- struct device_attribute *dev_attr,
47332- ssize_t (*show)(struct device *,
47333- struct device_attribute *, char *),
47334- ssize_t (*store)(struct device *,
47335- struct device_attribute *,
47336- const char *, size_t)
47337- )
47338+ struct device_attribute *dev_attr)
47339 {
47340+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
47341
47342- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
47343- id, name);
47344- if (!dev_attr->attr.name)
47345+ if (!name)
47346 return -ENOMEM;
47347- dev_attr->attr.mode = mode;
47348- dev_attr->show = show;
47349- dev_attr->store = store;
47350+
47351+ pax_open_kernel();
47352+ *(const char **)&dev_attr->attr.name = name;
47353+ pax_close_kernel();
47354
47355 return 0;
47356 }
47357@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
47358
47359 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
47360 ret = create_constraint_attribute(i, "power_limit_uw",
47361- S_IWUSR | S_IRUGO,
47362- &constraint_attrs[i].power_limit_attr,
47363- show_constraint_power_limit_uw,
47364- store_constraint_power_limit_uw);
47365+ &constraint_attrs[i].power_limit_attr);
47366 if (ret)
47367 goto err_alloc;
47368 ret = create_constraint_attribute(i, "time_window_us",
47369- S_IWUSR | S_IRUGO,
47370- &constraint_attrs[i].time_window_attr,
47371- show_constraint_time_window_us,
47372- store_constraint_time_window_us);
47373+ &constraint_attrs[i].time_window_attr);
47374 if (ret)
47375 goto err_alloc;
47376- ret = create_constraint_attribute(i, "name", S_IRUGO,
47377- &constraint_attrs[i].name_attr,
47378- show_constraint_name,
47379- NULL);
47380+ ret = create_constraint_attribute(i, "name",
47381+ &constraint_attrs[i].name_attr);
47382 if (ret)
47383 goto err_alloc;
47384- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
47385- &constraint_attrs[i].max_power_attr,
47386- show_constraint_max_power_uw,
47387- NULL);
47388+ ret = create_constraint_attribute(i, "max_power_uw",
47389+ &constraint_attrs[i].max_power_attr);
47390 if (ret)
47391 goto err_alloc;
47392- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
47393- &constraint_attrs[i].min_power_attr,
47394- show_constraint_min_power_uw,
47395- NULL);
47396+ ret = create_constraint_attribute(i, "min_power_uw",
47397+ &constraint_attrs[i].min_power_attr);
47398 if (ret)
47399 goto err_alloc;
47400 ret = create_constraint_attribute(i, "max_time_window_us",
47401- S_IRUGO,
47402- &constraint_attrs[i].max_time_window_attr,
47403- show_constraint_max_time_window_us,
47404- NULL);
47405+ &constraint_attrs[i].max_time_window_attr);
47406 if (ret)
47407 goto err_alloc;
47408 ret = create_constraint_attribute(i, "min_time_window_us",
47409- S_IRUGO,
47410- &constraint_attrs[i].min_time_window_attr,
47411- show_constraint_min_time_window_us,
47412- NULL);
47413+ &constraint_attrs[i].min_time_window_attr);
47414 if (ret)
47415 goto err_alloc;
47416
47417@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
47418 power_zone->zone_dev_attrs[count++] =
47419 &dev_attr_max_energy_range_uj.attr;
47420 if (power_zone->ops->get_energy_uj) {
47421+ pax_open_kernel();
47422 if (power_zone->ops->reset_energy_uj)
47423- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47424+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47425 else
47426- dev_attr_energy_uj.attr.mode = S_IRUGO;
47427+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
47428+ pax_close_kernel();
47429 power_zone->zone_dev_attrs[count++] =
47430 &dev_attr_energy_uj.attr;
47431 }
47432diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
47433index d85f313..ae857d0 100644
47434--- a/drivers/regulator/core.c
47435+++ b/drivers/regulator/core.c
47436@@ -3362,7 +3362,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47437 {
47438 const struct regulation_constraints *constraints = NULL;
47439 const struct regulator_init_data *init_data;
47440- static atomic_t regulator_no = ATOMIC_INIT(0);
47441+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
47442 struct regulator_dev *rdev;
47443 struct device *dev;
47444 int ret, i;
47445@@ -3432,7 +3432,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47446 rdev->dev.of_node = config->of_node;
47447 rdev->dev.parent = dev;
47448 dev_set_name(&rdev->dev, "regulator.%d",
47449- atomic_inc_return(&regulator_no) - 1);
47450+ atomic_inc_return_unchecked(&regulator_no) - 1);
47451 ret = device_register(&rdev->dev);
47452 if (ret != 0) {
47453 put_device(&rdev->dev);
47454diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
47455index 8d94d3d..653b623 100644
47456--- a/drivers/regulator/max8660.c
47457+++ b/drivers/regulator/max8660.c
47458@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
47459 max8660->shadow_regs[MAX8660_OVER1] = 5;
47460 } else {
47461 /* Otherwise devices can be toggled via software */
47462- max8660_dcdc_ops.enable = max8660_dcdc_enable;
47463- max8660_dcdc_ops.disable = max8660_dcdc_disable;
47464+ pax_open_kernel();
47465+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
47466+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
47467+ pax_close_kernel();
47468 }
47469
47470 /*
47471diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
47472index 892aa1e..ebd1b9c 100644
47473--- a/drivers/regulator/max8973-regulator.c
47474+++ b/drivers/regulator/max8973-regulator.c
47475@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
47476 if (!pdata || !pdata->enable_ext_control) {
47477 max->desc.enable_reg = MAX8973_VOUT;
47478 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
47479- max->ops.enable = regulator_enable_regmap;
47480- max->ops.disable = regulator_disable_regmap;
47481- max->ops.is_enabled = regulator_is_enabled_regmap;
47482+ pax_open_kernel();
47483+ *(void **)&max->ops.enable = regulator_enable_regmap;
47484+ *(void **)&max->ops.disable = regulator_disable_regmap;
47485+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
47486+ pax_close_kernel();
47487 }
47488
47489 if (pdata) {
47490diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
47491index 96c9f80..90974ca 100644
47492--- a/drivers/regulator/mc13892-regulator.c
47493+++ b/drivers/regulator/mc13892-regulator.c
47494@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
47495 }
47496 mc13xxx_unlock(mc13892);
47497
47498- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47499+ pax_open_kernel();
47500+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47501 = mc13892_vcam_set_mode;
47502- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47503+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47504 = mc13892_vcam_get_mode;
47505+ pax_close_kernel();
47506
47507 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
47508 ARRAY_SIZE(mc13892_regulators));
47509diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
47510index f148762..5a6d1e5 100644
47511--- a/drivers/rtc/rtc-cmos.c
47512+++ b/drivers/rtc/rtc-cmos.c
47513@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
47514 hpet_rtc_timer_init();
47515
47516 /* export at least the first block of NVRAM */
47517- nvram.size = address_space - NVRAM_OFFSET;
47518+ pax_open_kernel();
47519+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
47520+ pax_close_kernel();
47521 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
47522 if (retval < 0) {
47523 dev_dbg(dev, "can't create nvram file? %d\n", retval);
47524diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
47525index d049393..bb20be0 100644
47526--- a/drivers/rtc/rtc-dev.c
47527+++ b/drivers/rtc/rtc-dev.c
47528@@ -16,6 +16,7 @@
47529 #include <linux/module.h>
47530 #include <linux/rtc.h>
47531 #include <linux/sched.h>
47532+#include <linux/grsecurity.h>
47533 #include "rtc-core.h"
47534
47535 static dev_t rtc_devt;
47536@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
47537 if (copy_from_user(&tm, uarg, sizeof(tm)))
47538 return -EFAULT;
47539
47540+ gr_log_timechange();
47541+
47542 return rtc_set_time(rtc, &tm);
47543
47544 case RTC_PIE_ON:
47545diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
47546index 4e75345..09f8663 100644
47547--- a/drivers/rtc/rtc-ds1307.c
47548+++ b/drivers/rtc/rtc-ds1307.c
47549@@ -107,7 +107,7 @@ struct ds1307 {
47550 u8 offset; /* register's offset */
47551 u8 regs[11];
47552 u16 nvram_offset;
47553- struct bin_attribute *nvram;
47554+ bin_attribute_no_const *nvram;
47555 enum ds_type type;
47556 unsigned long flags;
47557 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
47558diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
47559index 11880c1..b823aa4 100644
47560--- a/drivers/rtc/rtc-m48t59.c
47561+++ b/drivers/rtc/rtc-m48t59.c
47562@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
47563 if (IS_ERR(m48t59->rtc))
47564 return PTR_ERR(m48t59->rtc);
47565
47566- m48t59_nvram_attr.size = pdata->offset;
47567+ pax_open_kernel();
47568+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
47569+ pax_close_kernel();
47570
47571 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
47572 if (ret)
47573diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
47574index 14b5f8d..cc9bd26 100644
47575--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
47576+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
47577@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
47578 for (bit = 0; bit < 8; bit++) {
47579
47580 if ((pci_status[i] & (0x1 << bit)) != 0) {
47581- static const char *s;
47582+ const char *s;
47583
47584 s = pci_status_strings[bit];
47585 if (i == 7/*TARG*/ && bit == 3)
47586@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
47587
47588 for (bit = 0; bit < 8; bit++) {
47589
47590- if ((split_status[i] & (0x1 << bit)) != 0) {
47591- static const char *s;
47592-
47593- s = split_status_strings[bit];
47594- printk(s, ahd_name(ahd),
47595+ if ((split_status[i] & (0x1 << bit)) != 0)
47596+ printk(split_status_strings[bit], ahd_name(ahd),
47597 split_status_source[i]);
47598- }
47599
47600 if (i > 1)
47601 continue;
47602
47603- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
47604- static const char *s;
47605-
47606- s = split_status_strings[bit];
47607- printk(s, ahd_name(ahd), "SG");
47608- }
47609+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
47610+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
47611 }
47612 }
47613 /*
47614diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
47615index e693af6..2e525b6 100644
47616--- a/drivers/scsi/bfa/bfa_fcpim.h
47617+++ b/drivers/scsi/bfa/bfa_fcpim.h
47618@@ -36,7 +36,7 @@ struct bfa_iotag_s {
47619
47620 struct bfa_itn_s {
47621 bfa_isr_func_t isr;
47622-};
47623+} __no_const;
47624
47625 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
47626 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
47627diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
47628index a3ab5cc..8143622 100644
47629--- a/drivers/scsi/bfa/bfa_fcs.c
47630+++ b/drivers/scsi/bfa/bfa_fcs.c
47631@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
47632 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
47633
47634 static struct bfa_fcs_mod_s fcs_modules[] = {
47635- { bfa_fcs_port_attach, NULL, NULL },
47636- { bfa_fcs_uf_attach, NULL, NULL },
47637- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
47638- bfa_fcs_fabric_modexit },
47639+ {
47640+ .attach = bfa_fcs_port_attach,
47641+ .modinit = NULL,
47642+ .modexit = NULL
47643+ },
47644+ {
47645+ .attach = bfa_fcs_uf_attach,
47646+ .modinit = NULL,
47647+ .modexit = NULL
47648+ },
47649+ {
47650+ .attach = bfa_fcs_fabric_attach,
47651+ .modinit = bfa_fcs_fabric_modinit,
47652+ .modexit = bfa_fcs_fabric_modexit
47653+ },
47654 };
47655
47656 /*
47657diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
47658index f5e4e61..a0acaf6 100644
47659--- a/drivers/scsi/bfa/bfa_fcs_lport.c
47660+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
47661@@ -89,15 +89,26 @@ static struct {
47662 void (*offline) (struct bfa_fcs_lport_s *port);
47663 } __port_action[] = {
47664 {
47665- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
47666- bfa_fcs_lport_unknown_offline}, {
47667- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
47668- bfa_fcs_lport_fab_offline}, {
47669- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
47670- bfa_fcs_lport_n2n_offline}, {
47671- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
47672- bfa_fcs_lport_loop_offline},
47673- };
47674+ .init = bfa_fcs_lport_unknown_init,
47675+ .online = bfa_fcs_lport_unknown_online,
47676+ .offline = bfa_fcs_lport_unknown_offline
47677+ },
47678+ {
47679+ .init = bfa_fcs_lport_fab_init,
47680+ .online = bfa_fcs_lport_fab_online,
47681+ .offline = bfa_fcs_lport_fab_offline
47682+ },
47683+ {
47684+ .init = bfa_fcs_lport_n2n_init,
47685+ .online = bfa_fcs_lport_n2n_online,
47686+ .offline = bfa_fcs_lport_n2n_offline
47687+ },
47688+ {
47689+ .init = bfa_fcs_lport_loop_init,
47690+ .online = bfa_fcs_lport_loop_online,
47691+ .offline = bfa_fcs_lport_loop_offline
47692+ },
47693+};
47694
47695 /*
47696 * fcs_port_sm FCS logical port state machine
47697diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
47698index 90814fe..4384138 100644
47699--- a/drivers/scsi/bfa/bfa_ioc.h
47700+++ b/drivers/scsi/bfa/bfa_ioc.h
47701@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
47702 bfa_ioc_disable_cbfn_t disable_cbfn;
47703 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
47704 bfa_ioc_reset_cbfn_t reset_cbfn;
47705-};
47706+} __no_const;
47707
47708 /*
47709 * IOC event notification mechanism.
47710@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
47711 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
47712 enum bfi_ioc_state fwstate);
47713 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
47714-};
47715+} __no_const;
47716
47717 /*
47718 * Queue element to wait for room in request queue. FIFO order is
47719diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
47720index a14c784..6de6790 100644
47721--- a/drivers/scsi/bfa/bfa_modules.h
47722+++ b/drivers/scsi/bfa/bfa_modules.h
47723@@ -78,12 +78,12 @@ enum {
47724 \
47725 extern struct bfa_module_s hal_mod_ ## __mod; \
47726 struct bfa_module_s hal_mod_ ## __mod = { \
47727- bfa_ ## __mod ## _meminfo, \
47728- bfa_ ## __mod ## _attach, \
47729- bfa_ ## __mod ## _detach, \
47730- bfa_ ## __mod ## _start, \
47731- bfa_ ## __mod ## _stop, \
47732- bfa_ ## __mod ## _iocdisable, \
47733+ .meminfo = bfa_ ## __mod ## _meminfo, \
47734+ .attach = bfa_ ## __mod ## _attach, \
47735+ .detach = bfa_ ## __mod ## _detach, \
47736+ .start = bfa_ ## __mod ## _start, \
47737+ .stop = bfa_ ## __mod ## _stop, \
47738+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
47739 }
47740
47741 #define BFA_CACHELINE_SZ (256)
47742diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
47743index 045c4e1..13de803 100644
47744--- a/drivers/scsi/fcoe/fcoe_sysfs.c
47745+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
47746@@ -33,8 +33,8 @@
47747 */
47748 #include "libfcoe.h"
47749
47750-static atomic_t ctlr_num;
47751-static atomic_t fcf_num;
47752+static atomic_unchecked_t ctlr_num;
47753+static atomic_unchecked_t fcf_num;
47754
47755 /*
47756 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
47757@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
47758 if (!ctlr)
47759 goto out;
47760
47761- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
47762+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
47763 ctlr->f = f;
47764 ctlr->mode = FIP_CONN_TYPE_FABRIC;
47765 INIT_LIST_HEAD(&ctlr->fcfs);
47766@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
47767 fcf->dev.parent = &ctlr->dev;
47768 fcf->dev.bus = &fcoe_bus_type;
47769 fcf->dev.type = &fcoe_fcf_device_type;
47770- fcf->id = atomic_inc_return(&fcf_num) - 1;
47771+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
47772 fcf->state = FCOE_FCF_STATE_UNKNOWN;
47773
47774 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
47775@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
47776 {
47777 int error;
47778
47779- atomic_set(&ctlr_num, 0);
47780- atomic_set(&fcf_num, 0);
47781+ atomic_set_unchecked(&ctlr_num, 0);
47782+ atomic_set_unchecked(&fcf_num, 0);
47783
47784 error = bus_register(&fcoe_bus_type);
47785 if (error)
47786diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
47787index f2c5005..db36c02 100644
47788--- a/drivers/scsi/hosts.c
47789+++ b/drivers/scsi/hosts.c
47790@@ -42,7 +42,7 @@
47791 #include "scsi_logging.h"
47792
47793
47794-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47795+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47796
47797
47798 static void scsi_host_cls_release(struct device *dev)
47799@@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
47800 * subtract one because we increment first then return, but we need to
47801 * know what the next host number was before increment
47802 */
47803- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
47804+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
47805 shost->dma_channel = 0xff;
47806
47807 /* These three are default values which can be overridden */
47808diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
47809index 20a5e6e..8b23cea 100644
47810--- a/drivers/scsi/hpsa.c
47811+++ b/drivers/scsi/hpsa.c
47812@@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
47813 unsigned long flags;
47814
47815 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
47816- return h->access.command_completed(h, q);
47817+ return h->access->command_completed(h, q);
47818
47819 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
47820 a = rq->head[rq->current_entry];
47821@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
47822 while (!list_empty(&h->reqQ)) {
47823 c = list_entry(h->reqQ.next, struct CommandList, list);
47824 /* can't do anything if fifo is full */
47825- if ((h->access.fifo_full(h))) {
47826+ if ((h->access->fifo_full(h))) {
47827 dev_warn(&h->pdev->dev, "fifo full\n");
47828 break;
47829 }
47830@@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
47831
47832 /* Tell the controller execute command */
47833 spin_unlock_irqrestore(&h->lock, flags);
47834- h->access.submit_command(h, c);
47835+ h->access->submit_command(h, c);
47836 spin_lock_irqsave(&h->lock, flags);
47837 }
47838 spin_unlock_irqrestore(&h->lock, flags);
47839@@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
47840
47841 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
47842 {
47843- return h->access.command_completed(h, q);
47844+ return h->access->command_completed(h, q);
47845 }
47846
47847 static inline bool interrupt_pending(struct ctlr_info *h)
47848 {
47849- return h->access.intr_pending(h);
47850+ return h->access->intr_pending(h);
47851 }
47852
47853 static inline long interrupt_not_for_us(struct ctlr_info *h)
47854 {
47855- return (h->access.intr_pending(h) == 0) ||
47856+ return (h->access->intr_pending(h) == 0) ||
47857 (h->interrupts_enabled == 0);
47858 }
47859
47860@@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
47861 if (prod_index < 0)
47862 return -ENODEV;
47863 h->product_name = products[prod_index].product_name;
47864- h->access = *(products[prod_index].access);
47865+ h->access = products[prod_index].access;
47866
47867 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
47868 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
47869@@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
47870
47871 assert_spin_locked(&lockup_detector_lock);
47872 remove_ctlr_from_lockup_detector_list(h);
47873- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47874+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47875 spin_lock_irqsave(&h->lock, flags);
47876 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
47877 spin_unlock_irqrestore(&h->lock, flags);
47878@@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
47879 }
47880
47881 /* make sure the board interrupts are off */
47882- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47883+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47884
47885 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
47886 goto clean2;
47887@@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
47888 * fake ones to scoop up any residual completions.
47889 */
47890 spin_lock_irqsave(&h->lock, flags);
47891- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47892+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47893 spin_unlock_irqrestore(&h->lock, flags);
47894 free_irqs(h);
47895 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
47896@@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
47897 dev_info(&h->pdev->dev, "Board READY.\n");
47898 dev_info(&h->pdev->dev,
47899 "Waiting for stale completions to drain.\n");
47900- h->access.set_intr_mask(h, HPSA_INTR_ON);
47901+ h->access->set_intr_mask(h, HPSA_INTR_ON);
47902 msleep(10000);
47903- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47904+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47905
47906 rc = controller_reset_failed(h->cfgtable);
47907 if (rc)
47908@@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
47909 }
47910
47911 /* Turn the interrupts on so we can service requests */
47912- h->access.set_intr_mask(h, HPSA_INTR_ON);
47913+ h->access->set_intr_mask(h, HPSA_INTR_ON);
47914
47915 hpsa_hba_inquiry(h);
47916 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
47917@@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
47918 * To write all data in the battery backed cache to disks
47919 */
47920 hpsa_flush_cache(h);
47921- h->access.set_intr_mask(h, HPSA_INTR_OFF);
47922+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
47923 hpsa_free_irqs_and_disable_msix(h);
47924 }
47925
47926@@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
47927 return;
47928 }
47929 /* Change the access methods to the performant access methods */
47930- h->access = SA5_performant_access;
47931+ h->access = &SA5_performant_access;
47932 h->transMethod = CFGTBL_Trans_Performant;
47933 }
47934
47935diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
47936index bc85e72..d463049 100644
47937--- a/drivers/scsi/hpsa.h
47938+++ b/drivers/scsi/hpsa.h
47939@@ -79,7 +79,7 @@ struct ctlr_info {
47940 unsigned int msix_vector;
47941 unsigned int msi_vector;
47942 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
47943- struct access_method access;
47944+ struct access_method *access;
47945
47946 /* queue and queue Info */
47947 struct list_head reqQ;
47948@@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
47949 }
47950
47951 static struct access_method SA5_access = {
47952- SA5_submit_command,
47953- SA5_intr_mask,
47954- SA5_fifo_full,
47955- SA5_intr_pending,
47956- SA5_completed,
47957+ .submit_command = SA5_submit_command,
47958+ .set_intr_mask = SA5_intr_mask,
47959+ .fifo_full = SA5_fifo_full,
47960+ .intr_pending = SA5_intr_pending,
47961+ .command_completed = SA5_completed,
47962 };
47963
47964 static struct access_method SA5_performant_access = {
47965- SA5_submit_command,
47966- SA5_performant_intr_mask,
47967- SA5_fifo_full,
47968- SA5_performant_intr_pending,
47969- SA5_performant_completed,
47970+ .submit_command = SA5_submit_command,
47971+ .set_intr_mask = SA5_performant_intr_mask,
47972+ .fifo_full = SA5_fifo_full,
47973+ .intr_pending = SA5_performant_intr_pending,
47974+ .command_completed = SA5_performant_completed,
47975 };
47976
47977 struct board_type {
47978diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
47979index 1b3a094..068e683 100644
47980--- a/drivers/scsi/libfc/fc_exch.c
47981+++ b/drivers/scsi/libfc/fc_exch.c
47982@@ -101,12 +101,12 @@ struct fc_exch_mgr {
47983 u16 pool_max_index;
47984
47985 struct {
47986- atomic_t no_free_exch;
47987- atomic_t no_free_exch_xid;
47988- atomic_t xid_not_found;
47989- atomic_t xid_busy;
47990- atomic_t seq_not_found;
47991- atomic_t non_bls_resp;
47992+ atomic_unchecked_t no_free_exch;
47993+ atomic_unchecked_t no_free_exch_xid;
47994+ atomic_unchecked_t xid_not_found;
47995+ atomic_unchecked_t xid_busy;
47996+ atomic_unchecked_t seq_not_found;
47997+ atomic_unchecked_t non_bls_resp;
47998 } stats;
47999 };
48000
48001@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48002 /* allocate memory for exchange */
48003 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48004 if (!ep) {
48005- atomic_inc(&mp->stats.no_free_exch);
48006+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48007 goto out;
48008 }
48009 memset(ep, 0, sizeof(*ep));
48010@@ -874,7 +874,7 @@ out:
48011 return ep;
48012 err:
48013 spin_unlock_bh(&pool->lock);
48014- atomic_inc(&mp->stats.no_free_exch_xid);
48015+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48016 mempool_free(ep, mp->ep_pool);
48017 return NULL;
48018 }
48019@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48020 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48021 ep = fc_exch_find(mp, xid);
48022 if (!ep) {
48023- atomic_inc(&mp->stats.xid_not_found);
48024+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48025 reject = FC_RJT_OX_ID;
48026 goto out;
48027 }
48028@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48029 ep = fc_exch_find(mp, xid);
48030 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48031 if (ep) {
48032- atomic_inc(&mp->stats.xid_busy);
48033+ atomic_inc_unchecked(&mp->stats.xid_busy);
48034 reject = FC_RJT_RX_ID;
48035 goto rel;
48036 }
48037@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48038 }
48039 xid = ep->xid; /* get our XID */
48040 } else if (!ep) {
48041- atomic_inc(&mp->stats.xid_not_found);
48042+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48043 reject = FC_RJT_RX_ID; /* XID not found */
48044 goto out;
48045 }
48046@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48047 } else {
48048 sp = &ep->seq;
48049 if (sp->id != fh->fh_seq_id) {
48050- atomic_inc(&mp->stats.seq_not_found);
48051+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48052 if (f_ctl & FC_FC_END_SEQ) {
48053 /*
48054 * Update sequence_id based on incoming last
48055@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48056
48057 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48058 if (!ep) {
48059- atomic_inc(&mp->stats.xid_not_found);
48060+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48061 goto out;
48062 }
48063 if (ep->esb_stat & ESB_ST_COMPLETE) {
48064- atomic_inc(&mp->stats.xid_not_found);
48065+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48066 goto rel;
48067 }
48068 if (ep->rxid == FC_XID_UNKNOWN)
48069 ep->rxid = ntohs(fh->fh_rx_id);
48070 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48071- atomic_inc(&mp->stats.xid_not_found);
48072+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48073 goto rel;
48074 }
48075 if (ep->did != ntoh24(fh->fh_s_id) &&
48076 ep->did != FC_FID_FLOGI) {
48077- atomic_inc(&mp->stats.xid_not_found);
48078+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48079 goto rel;
48080 }
48081 sof = fr_sof(fp);
48082@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48083 sp->ssb_stat |= SSB_ST_RESP;
48084 sp->id = fh->fh_seq_id;
48085 } else if (sp->id != fh->fh_seq_id) {
48086- atomic_inc(&mp->stats.seq_not_found);
48087+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48088 goto rel;
48089 }
48090
48091@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48092 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48093
48094 if (!sp)
48095- atomic_inc(&mp->stats.xid_not_found);
48096+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48097 else
48098- atomic_inc(&mp->stats.non_bls_resp);
48099+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
48100
48101 fc_frame_free(fp);
48102 }
48103@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48104
48105 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48106 mp = ema->mp;
48107- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48108+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48109 st->fc_no_free_exch_xid +=
48110- atomic_read(&mp->stats.no_free_exch_xid);
48111- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48112- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48113- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48114- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48115+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48116+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48117+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48118+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48119+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48120 }
48121 }
48122 EXPORT_SYMBOL(fc_exch_update_stats);
48123diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48124index d289583..b745eec 100644
48125--- a/drivers/scsi/libsas/sas_ata.c
48126+++ b/drivers/scsi/libsas/sas_ata.c
48127@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48128 .postreset = ata_std_postreset,
48129 .error_handler = ata_std_error_handler,
48130 .post_internal_cmd = sas_ata_post_internal,
48131- .qc_defer = ata_std_qc_defer,
48132+ .qc_defer = ata_std_qc_defer,
48133 .qc_prep = ata_noop_qc_prep,
48134 .qc_issue = sas_ata_qc_issue,
48135 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48136diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48137index 4e1b75c..0bbdfa9 100644
48138--- a/drivers/scsi/lpfc/lpfc.h
48139+++ b/drivers/scsi/lpfc/lpfc.h
48140@@ -432,7 +432,7 @@ struct lpfc_vport {
48141 struct dentry *debug_nodelist;
48142 struct dentry *vport_debugfs_root;
48143 struct lpfc_debugfs_trc *disc_trc;
48144- atomic_t disc_trc_cnt;
48145+ atomic_unchecked_t disc_trc_cnt;
48146 #endif
48147 uint8_t stat_data_enabled;
48148 uint8_t stat_data_blocked;
48149@@ -865,8 +865,8 @@ struct lpfc_hba {
48150 struct timer_list fabric_block_timer;
48151 unsigned long bit_flags;
48152 #define FABRIC_COMANDS_BLOCKED 0
48153- atomic_t num_rsrc_err;
48154- atomic_t num_cmd_success;
48155+ atomic_unchecked_t num_rsrc_err;
48156+ atomic_unchecked_t num_cmd_success;
48157 unsigned long last_rsrc_error_time;
48158 unsigned long last_ramp_down_time;
48159 unsigned long last_ramp_up_time;
48160@@ -902,7 +902,7 @@ struct lpfc_hba {
48161
48162 struct dentry *debug_slow_ring_trc;
48163 struct lpfc_debugfs_trc *slow_ring_trc;
48164- atomic_t slow_ring_trc_cnt;
48165+ atomic_unchecked_t slow_ring_trc_cnt;
48166 /* iDiag debugfs sub-directory */
48167 struct dentry *idiag_root;
48168 struct dentry *idiag_pci_cfg;
48169diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48170index 60084e6..0e2e700 100644
48171--- a/drivers/scsi/lpfc/lpfc_debugfs.c
48172+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48173@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48174
48175 #include <linux/debugfs.h>
48176
48177-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48178+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48179 static unsigned long lpfc_debugfs_start_time = 0L;
48180
48181 /* iDiag */
48182@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48183 lpfc_debugfs_enable = 0;
48184
48185 len = 0;
48186- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48187+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48188 (lpfc_debugfs_max_disc_trc - 1);
48189 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48190 dtp = vport->disc_trc + i;
48191@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48192 lpfc_debugfs_enable = 0;
48193
48194 len = 0;
48195- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48196+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48197 (lpfc_debugfs_max_slow_ring_trc - 1);
48198 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48199 dtp = phba->slow_ring_trc + i;
48200@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48201 !vport || !vport->disc_trc)
48202 return;
48203
48204- index = atomic_inc_return(&vport->disc_trc_cnt) &
48205+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48206 (lpfc_debugfs_max_disc_trc - 1);
48207 dtp = vport->disc_trc + index;
48208 dtp->fmt = fmt;
48209 dtp->data1 = data1;
48210 dtp->data2 = data2;
48211 dtp->data3 = data3;
48212- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48213+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48214 dtp->jif = jiffies;
48215 #endif
48216 return;
48217@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48218 !phba || !phba->slow_ring_trc)
48219 return;
48220
48221- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
48222+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
48223 (lpfc_debugfs_max_slow_ring_trc - 1);
48224 dtp = phba->slow_ring_trc + index;
48225 dtp->fmt = fmt;
48226 dtp->data1 = data1;
48227 dtp->data2 = data2;
48228 dtp->data3 = data3;
48229- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48230+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48231 dtp->jif = jiffies;
48232 #endif
48233 return;
48234@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48235 "slow_ring buffer\n");
48236 goto debug_failed;
48237 }
48238- atomic_set(&phba->slow_ring_trc_cnt, 0);
48239+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
48240 memset(phba->slow_ring_trc, 0,
48241 (sizeof(struct lpfc_debugfs_trc) *
48242 lpfc_debugfs_max_slow_ring_trc));
48243@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48244 "buffer\n");
48245 goto debug_failed;
48246 }
48247- atomic_set(&vport->disc_trc_cnt, 0);
48248+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
48249
48250 snprintf(name, sizeof(name), "discovery_trace");
48251 vport->debug_disc_trc =
48252diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
48253index 68c94cc..8c27be5 100644
48254--- a/drivers/scsi/lpfc/lpfc_init.c
48255+++ b/drivers/scsi/lpfc/lpfc_init.c
48256@@ -10949,8 +10949,10 @@ lpfc_init(void)
48257 "misc_register returned with status %d", error);
48258
48259 if (lpfc_enable_npiv) {
48260- lpfc_transport_functions.vport_create = lpfc_vport_create;
48261- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48262+ pax_open_kernel();
48263+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
48264+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48265+ pax_close_kernel();
48266 }
48267 lpfc_transport_template =
48268 fc_attach_transport(&lpfc_transport_functions);
48269diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
48270index b2ede05..aaf482ca 100644
48271--- a/drivers/scsi/lpfc/lpfc_scsi.c
48272+++ b/drivers/scsi/lpfc/lpfc_scsi.c
48273@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
48274 uint32_t evt_posted;
48275
48276 spin_lock_irqsave(&phba->hbalock, flags);
48277- atomic_inc(&phba->num_rsrc_err);
48278+ atomic_inc_unchecked(&phba->num_rsrc_err);
48279 phba->last_rsrc_error_time = jiffies;
48280
48281 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
48282@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
48283 unsigned long flags;
48284 struct lpfc_hba *phba = vport->phba;
48285 uint32_t evt_posted;
48286- atomic_inc(&phba->num_cmd_success);
48287+ atomic_inc_unchecked(&phba->num_cmd_success);
48288
48289 if (vport->cfg_lun_queue_depth <= queue_depth)
48290 return;
48291@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48292 unsigned long num_rsrc_err, num_cmd_success;
48293 int i;
48294
48295- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
48296- num_cmd_success = atomic_read(&phba->num_cmd_success);
48297+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
48298+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
48299
48300 /*
48301 * The error and success command counters are global per
48302@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48303 }
48304 }
48305 lpfc_destroy_vport_work_array(phba, vports);
48306- atomic_set(&phba->num_rsrc_err, 0);
48307- atomic_set(&phba->num_cmd_success, 0);
48308+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
48309+ atomic_set_unchecked(&phba->num_cmd_success, 0);
48310 }
48311
48312 /**
48313@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
48314 }
48315 }
48316 lpfc_destroy_vport_work_array(phba, vports);
48317- atomic_set(&phba->num_rsrc_err, 0);
48318- atomic_set(&phba->num_cmd_success, 0);
48319+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
48320+ atomic_set_unchecked(&phba->num_cmd_success, 0);
48321 }
48322
48323 /**
48324diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48325index 7f0af4f..193ac3e 100644
48326--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48327+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48328@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
48329 {
48330 struct scsi_device *sdev = to_scsi_device(dev);
48331 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48332- static struct _raid_device *raid_device;
48333+ struct _raid_device *raid_device;
48334 unsigned long flags;
48335 Mpi2RaidVolPage0_t vol_pg0;
48336 Mpi2ConfigReply_t mpi_reply;
48337@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
48338 {
48339 struct scsi_device *sdev = to_scsi_device(dev);
48340 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48341- static struct _raid_device *raid_device;
48342+ struct _raid_device *raid_device;
48343 unsigned long flags;
48344 Mpi2RaidVolPage0_t vol_pg0;
48345 Mpi2ConfigReply_t mpi_reply;
48346@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
48347 struct fw_event_work *fw_event)
48348 {
48349 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
48350- static struct _raid_device *raid_device;
48351+ struct _raid_device *raid_device;
48352 unsigned long flags;
48353 u16 handle;
48354
48355@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
48356 u64 sas_address;
48357 struct _sas_device *sas_device;
48358 struct _sas_node *expander_device;
48359- static struct _raid_device *raid_device;
48360+ struct _raid_device *raid_device;
48361 u8 retry_count;
48362 unsigned long flags;
48363
48364diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
48365index be8ce54..94ed33a 100644
48366--- a/drivers/scsi/pmcraid.c
48367+++ b/drivers/scsi/pmcraid.c
48368@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
48369 res->scsi_dev = scsi_dev;
48370 scsi_dev->hostdata = res;
48371 res->change_detected = 0;
48372- atomic_set(&res->read_failures, 0);
48373- atomic_set(&res->write_failures, 0);
48374+ atomic_set_unchecked(&res->read_failures, 0);
48375+ atomic_set_unchecked(&res->write_failures, 0);
48376 rc = 0;
48377 }
48378 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
48379@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
48380
48381 /* If this was a SCSI read/write command keep count of errors */
48382 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
48383- atomic_inc(&res->read_failures);
48384+ atomic_inc_unchecked(&res->read_failures);
48385 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
48386- atomic_inc(&res->write_failures);
48387+ atomic_inc_unchecked(&res->write_failures);
48388
48389 if (!RES_IS_GSCSI(res->cfg_entry) &&
48390 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
48391@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
48392 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48393 * hrrq_id assigned here in queuecommand
48394 */
48395- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48396+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48397 pinstance->num_hrrq;
48398 cmd->cmd_done = pmcraid_io_done;
48399
48400@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
48401 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48402 * hrrq_id assigned here in queuecommand
48403 */
48404- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48405+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48406 pinstance->num_hrrq;
48407
48408 if (request_size) {
48409@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
48410
48411 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
48412 /* add resources only after host is added into system */
48413- if (!atomic_read(&pinstance->expose_resources))
48414+ if (!atomic_read_unchecked(&pinstance->expose_resources))
48415 return;
48416
48417 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
48418@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
48419 init_waitqueue_head(&pinstance->reset_wait_q);
48420
48421 atomic_set(&pinstance->outstanding_cmds, 0);
48422- atomic_set(&pinstance->last_message_id, 0);
48423- atomic_set(&pinstance->expose_resources, 0);
48424+ atomic_set_unchecked(&pinstance->last_message_id, 0);
48425+ atomic_set_unchecked(&pinstance->expose_resources, 0);
48426
48427 INIT_LIST_HEAD(&pinstance->free_res_q);
48428 INIT_LIST_HEAD(&pinstance->used_res_q);
48429@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
48430 /* Schedule worker thread to handle CCN and take care of adding and
48431 * removing devices to OS
48432 */
48433- atomic_set(&pinstance->expose_resources, 1);
48434+ atomic_set_unchecked(&pinstance->expose_resources, 1);
48435 schedule_work(&pinstance->worker_q);
48436 return rc;
48437
48438diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
48439index e1d150f..6c6df44 100644
48440--- a/drivers/scsi/pmcraid.h
48441+++ b/drivers/scsi/pmcraid.h
48442@@ -748,7 +748,7 @@ struct pmcraid_instance {
48443 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
48444
48445 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
48446- atomic_t last_message_id;
48447+ atomic_unchecked_t last_message_id;
48448
48449 /* configuration table */
48450 struct pmcraid_config_table *cfg_table;
48451@@ -777,7 +777,7 @@ struct pmcraid_instance {
48452 atomic_t outstanding_cmds;
48453
48454 /* should add/delete resources to mid-layer now ?*/
48455- atomic_t expose_resources;
48456+ atomic_unchecked_t expose_resources;
48457
48458
48459
48460@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
48461 struct pmcraid_config_table_entry_ext cfg_entry_ext;
48462 };
48463 struct scsi_device *scsi_dev; /* Link scsi_device structure */
48464- atomic_t read_failures; /* count of failed READ commands */
48465- atomic_t write_failures; /* count of failed WRITE commands */
48466+ atomic_unchecked_t read_failures; /* count of failed READ commands */
48467+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
48468
48469 /* To indicate add/delete/modify during CCN */
48470 u8 change_detected;
48471diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
48472index 5f174b8..98d32b0 100644
48473--- a/drivers/scsi/qla2xxx/qla_attr.c
48474+++ b/drivers/scsi/qla2xxx/qla_attr.c
48475@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
48476 return 0;
48477 }
48478
48479-struct fc_function_template qla2xxx_transport_functions = {
48480+fc_function_template_no_const qla2xxx_transport_functions = {
48481
48482 .show_host_node_name = 1,
48483 .show_host_port_name = 1,
48484@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
48485 .bsg_timeout = qla24xx_bsg_timeout,
48486 };
48487
48488-struct fc_function_template qla2xxx_transport_vport_functions = {
48489+fc_function_template_no_const qla2xxx_transport_vport_functions = {
48490
48491 .show_host_node_name = 1,
48492 .show_host_port_name = 1,
48493diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
48494index 4446bf5..9a3574d 100644
48495--- a/drivers/scsi/qla2xxx/qla_gbl.h
48496+++ b/drivers/scsi/qla2xxx/qla_gbl.h
48497@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
48498 struct device_attribute;
48499 extern struct device_attribute *qla2x00_host_attrs[];
48500 struct fc_function_template;
48501-extern struct fc_function_template qla2xxx_transport_functions;
48502-extern struct fc_function_template qla2xxx_transport_vport_functions;
48503+extern fc_function_template_no_const qla2xxx_transport_functions;
48504+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
48505 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
48506 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
48507 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
48508diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
48509index 52be35e..b933907 100644
48510--- a/drivers/scsi/qla2xxx/qla_os.c
48511+++ b/drivers/scsi/qla2xxx/qla_os.c
48512@@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
48513 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
48514 /* Ok, a 64bit DMA mask is applicable. */
48515 ha->flags.enable_64bit_addressing = 1;
48516- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48517- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48518+ pax_open_kernel();
48519+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48520+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48521+ pax_close_kernel();
48522 return;
48523 }
48524 }
48525diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
48526index 084d1fd..9f939eb 100644
48527--- a/drivers/scsi/qla4xxx/ql4_def.h
48528+++ b/drivers/scsi/qla4xxx/ql4_def.h
48529@@ -296,7 +296,7 @@ struct ddb_entry {
48530 * (4000 only) */
48531 atomic_t relogin_timer; /* Max Time to wait for
48532 * relogin to complete */
48533- atomic_t relogin_retry_count; /* Num of times relogin has been
48534+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
48535 * retried */
48536 uint32_t default_time2wait; /* Default Min time between
48537 * relogins (+aens) */
48538diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
48539index a28d5e6..000a8af 100644
48540--- a/drivers/scsi/qla4xxx/ql4_os.c
48541+++ b/drivers/scsi/qla4xxx/ql4_os.c
48542@@ -3308,12 +3308,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
48543 */
48544 if (!iscsi_is_session_online(cls_sess)) {
48545 /* Reset retry relogin timer */
48546- atomic_inc(&ddb_entry->relogin_retry_count);
48547+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
48548 DEBUG2(ql4_printk(KERN_INFO, ha,
48549 "%s: index[%d] relogin timed out-retrying"
48550 " relogin (%d), retry (%d)\n", __func__,
48551 ddb_entry->fw_ddb_index,
48552- atomic_read(&ddb_entry->relogin_retry_count),
48553+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
48554 ddb_entry->default_time2wait + 4));
48555 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
48556 atomic_set(&ddb_entry->retry_relogin_timer,
48557@@ -5455,7 +5455,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
48558
48559 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
48560 atomic_set(&ddb_entry->relogin_timer, 0);
48561- atomic_set(&ddb_entry->relogin_retry_count, 0);
48562+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
48563 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
48564 ddb_entry->default_relogin_timeout =
48565 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
48566diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
48567index fe0bcb1..c9255be 100644
48568--- a/drivers/scsi/scsi.c
48569+++ b/drivers/scsi/scsi.c
48570@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
48571 struct Scsi_Host *host = cmd->device->host;
48572 int rtn = 0;
48573
48574- atomic_inc(&cmd->device->iorequest_cnt);
48575+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48576
48577 /* check if the device is still usable */
48578 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
48579diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
48580index 7bd7f0d..44147bf 100644
48581--- a/drivers/scsi/scsi_lib.c
48582+++ b/drivers/scsi/scsi_lib.c
48583@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
48584 shost = sdev->host;
48585 scsi_init_cmd_errh(cmd);
48586 cmd->result = DID_NO_CONNECT << 16;
48587- atomic_inc(&cmd->device->iorequest_cnt);
48588+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48589
48590 /*
48591 * SCSI request completion path will do scsi_device_unbusy(),
48592@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
48593
48594 INIT_LIST_HEAD(&cmd->eh_entry);
48595
48596- atomic_inc(&cmd->device->iodone_cnt);
48597+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
48598 if (cmd->result)
48599- atomic_inc(&cmd->device->ioerr_cnt);
48600+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
48601
48602 disposition = scsi_decide_disposition(cmd);
48603 if (disposition != SUCCESS &&
48604diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
48605index 8ff62c2..693b6f7 100644
48606--- a/drivers/scsi/scsi_sysfs.c
48607+++ b/drivers/scsi/scsi_sysfs.c
48608@@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
48609 char *buf) \
48610 { \
48611 struct scsi_device *sdev = to_scsi_device(dev); \
48612- unsigned long long count = atomic_read(&sdev->field); \
48613+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
48614 return snprintf(buf, 20, "0x%llx\n", count); \
48615 } \
48616 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
48617diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
48618index 84a1fdf..693b0d6 100644
48619--- a/drivers/scsi/scsi_tgt_lib.c
48620+++ b/drivers/scsi/scsi_tgt_lib.c
48621@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
48622 int err;
48623
48624 dprintk("%lx %u\n", uaddr, len);
48625- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
48626+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
48627 if (err) {
48628 /*
48629 * TODO: need to fixup sg_tablesize, max_segment_size,
48630diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
48631index 4628fd5..a94a1c2 100644
48632--- a/drivers/scsi/scsi_transport_fc.c
48633+++ b/drivers/scsi/scsi_transport_fc.c
48634@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
48635 * Netlink Infrastructure
48636 */
48637
48638-static atomic_t fc_event_seq;
48639+static atomic_unchecked_t fc_event_seq;
48640
48641 /**
48642 * fc_get_event_number - Obtain the next sequential FC event number
48643@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
48644 u32
48645 fc_get_event_number(void)
48646 {
48647- return atomic_add_return(1, &fc_event_seq);
48648+ return atomic_add_return_unchecked(1, &fc_event_seq);
48649 }
48650 EXPORT_SYMBOL(fc_get_event_number);
48651
48652@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
48653 {
48654 int error;
48655
48656- atomic_set(&fc_event_seq, 0);
48657+ atomic_set_unchecked(&fc_event_seq, 0);
48658
48659 error = transport_class_register(&fc_host_class);
48660 if (error)
48661@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
48662 char *cp;
48663
48664 *val = simple_strtoul(buf, &cp, 0);
48665- if ((*cp && (*cp != '\n')) || (*val < 0))
48666+ if (*cp && (*cp != '\n'))
48667 return -EINVAL;
48668 /*
48669 * Check for overflow; dev_loss_tmo is u32
48670diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
48671index 63a6ca4..5d5cadd 100644
48672--- a/drivers/scsi/scsi_transport_iscsi.c
48673+++ b/drivers/scsi/scsi_transport_iscsi.c
48674@@ -79,7 +79,7 @@ struct iscsi_internal {
48675 struct transport_container session_cont;
48676 };
48677
48678-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
48679+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
48680 static struct workqueue_struct *iscsi_eh_timer_workq;
48681
48682 static DEFINE_IDA(iscsi_sess_ida);
48683@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
48684 int err;
48685
48686 ihost = shost->shost_data;
48687- session->sid = atomic_add_return(1, &iscsi_session_nr);
48688+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
48689
48690 if (target_id == ISCSI_MAX_TARGET) {
48691 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
48692@@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
48693 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
48694 ISCSI_TRANSPORT_VERSION);
48695
48696- atomic_set(&iscsi_session_nr, 0);
48697+ atomic_set_unchecked(&iscsi_session_nr, 0);
48698
48699 err = class_register(&iscsi_transport_class);
48700 if (err)
48701diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
48702index 2700a5a..752ec38 100644
48703--- a/drivers/scsi/scsi_transport_srp.c
48704+++ b/drivers/scsi/scsi_transport_srp.c
48705@@ -36,7 +36,7 @@
48706 #include "scsi_transport_srp_internal.h"
48707
48708 struct srp_host_attrs {
48709- atomic_t next_port_id;
48710+ atomic_unchecked_t next_port_id;
48711 };
48712 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
48713
48714@@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
48715 struct Scsi_Host *shost = dev_to_shost(dev);
48716 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
48717
48718- atomic_set(&srp_host->next_port_id, 0);
48719+ atomic_set_unchecked(&srp_host->next_port_id, 0);
48720 return 0;
48721 }
48722
48723@@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
48724 rport_fast_io_fail_timedout);
48725 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
48726
48727- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
48728+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
48729 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
48730
48731 transport_setup_device(&rport->dev);
48732diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
48733index 69725f7..03aaee1 100644
48734--- a/drivers/scsi/sd.c
48735+++ b/drivers/scsi/sd.c
48736@@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
48737 sdkp->disk = gd;
48738 sdkp->index = index;
48739 atomic_set(&sdkp->openers, 0);
48740- atomic_set(&sdkp->device->ioerr_cnt, 0);
48741+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
48742
48743 if (!sdp->request_queue->rq_timeout) {
48744 if (sdp->type != TYPE_MOD)
48745diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
48746index df5e961..df6b97f 100644
48747--- a/drivers/scsi/sg.c
48748+++ b/drivers/scsi/sg.c
48749@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
48750 sdp->disk->disk_name,
48751 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
48752 NULL,
48753- (char *)arg);
48754+ (char __user *)arg);
48755 case BLKTRACESTART:
48756 return blk_trace_startstop(sdp->device->request_queue, 1);
48757 case BLKTRACESTOP:
48758diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
48759index 349ebba..ff2a249 100644
48760--- a/drivers/spi/spi.c
48761+++ b/drivers/spi/spi.c
48762@@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
48763 EXPORT_SYMBOL_GPL(spi_bus_unlock);
48764
48765 /* portable code must never pass more than 32 bytes */
48766-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
48767+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
48768
48769 static u8 *buf;
48770
48771diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
48772index 2c61783..4d49e4e 100644
48773--- a/drivers/staging/android/timed_output.c
48774+++ b/drivers/staging/android/timed_output.c
48775@@ -25,7 +25,7 @@
48776 #include "timed_output.h"
48777
48778 static struct class *timed_output_class;
48779-static atomic_t device_count;
48780+static atomic_unchecked_t device_count;
48781
48782 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
48783 char *buf)
48784@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
48785 timed_output_class = class_create(THIS_MODULE, "timed_output");
48786 if (IS_ERR(timed_output_class))
48787 return PTR_ERR(timed_output_class);
48788- atomic_set(&device_count, 0);
48789+ atomic_set_unchecked(&device_count, 0);
48790 timed_output_class->dev_groups = timed_output_groups;
48791 }
48792
48793@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
48794 if (ret < 0)
48795 return ret;
48796
48797- tdev->index = atomic_inc_return(&device_count);
48798+ tdev->index = atomic_inc_return_unchecked(&device_count);
48799 tdev->dev = device_create(timed_output_class, NULL,
48800 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
48801 if (IS_ERR(tdev->dev))
48802diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
48803index c0f7cd7..5424212 100644
48804--- a/drivers/staging/gdm724x/gdm_tty.c
48805+++ b/drivers/staging/gdm724x/gdm_tty.c
48806@@ -45,7 +45,7 @@
48807 #define gdm_tty_send_control(n, r, v, d, l) (\
48808 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
48809
48810-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
48811+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
48812
48813 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
48814 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
48815diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
48816index b7613c8..c302392 100644
48817--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
48818+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
48819@@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
48820 return 0;
48821 }
48822
48823-sfw_test_client_ops_t brw_test_client;
48824-void brw_init_test_client(void)
48825-{
48826- brw_test_client.tso_init = brw_client_init;
48827- brw_test_client.tso_fini = brw_client_fini;
48828- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
48829- brw_test_client.tso_done_rpc = brw_client_done_rpc;
48830+sfw_test_client_ops_t brw_test_client = {
48831+ .tso_init = brw_client_init,
48832+ .tso_fini = brw_client_fini,
48833+ .tso_prep_rpc = brw_client_prep_rpc,
48834+ .tso_done_rpc = brw_client_done_rpc,
48835 };
48836
48837 srpc_service_t brw_test_service;
48838diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
48839index 483c785..e1a2a7b 100644
48840--- a/drivers/staging/lustre/lnet/selftest/framework.c
48841+++ b/drivers/staging/lustre/lnet/selftest/framework.c
48842@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
48843
48844 extern sfw_test_client_ops_t ping_test_client;
48845 extern srpc_service_t ping_test_service;
48846-extern void ping_init_test_client(void);
48847 extern void ping_init_test_service(void);
48848
48849 extern sfw_test_client_ops_t brw_test_client;
48850 extern srpc_service_t brw_test_service;
48851-extern void brw_init_test_client(void);
48852 extern void brw_init_test_service(void);
48853
48854
48855@@ -1684,12 +1682,10 @@ sfw_startup (void)
48856 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
48857 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
48858
48859- brw_init_test_client();
48860 brw_init_test_service();
48861 rc = sfw_register_test(&brw_test_service, &brw_test_client);
48862 LASSERT (rc == 0);
48863
48864- ping_init_test_client();
48865 ping_init_test_service();
48866 rc = sfw_register_test(&ping_test_service, &ping_test_client);
48867 LASSERT (rc == 0);
48868diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
48869index f0f9194..b589047 100644
48870--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
48871+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
48872@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
48873 return 0;
48874 }
48875
48876-sfw_test_client_ops_t ping_test_client;
48877-void ping_init_test_client(void)
48878-{
48879- ping_test_client.tso_init = ping_client_init;
48880- ping_test_client.tso_fini = ping_client_fini;
48881- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
48882- ping_test_client.tso_done_rpc = ping_client_done_rpc;
48883-}
48884+sfw_test_client_ops_t ping_test_client = {
48885+ .tso_init = ping_client_init,
48886+ .tso_fini = ping_client_fini,
48887+ .tso_prep_rpc = ping_client_prep_rpc,
48888+ .tso_done_rpc = ping_client_done_rpc,
48889+};
48890
48891 srpc_service_t ping_test_service;
48892 void ping_init_test_service(void)
48893diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
48894index bc2b82f..67fd598 100644
48895--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
48896+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
48897@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
48898 ldlm_completion_callback lcs_completion;
48899 ldlm_blocking_callback lcs_blocking;
48900 ldlm_glimpse_callback lcs_glimpse;
48901-};
48902+} __no_const;
48903
48904 /* ldlm_lockd.c */
48905 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
48906diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
48907index d0aea15..7af68e1 100644
48908--- a/drivers/staging/lustre/lustre/include/obd.h
48909+++ b/drivers/staging/lustre/lustre/include/obd.h
48910@@ -1417,7 +1417,7 @@ struct md_ops {
48911 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
48912 * wrapper function in include/linux/obd_class.h.
48913 */
48914-};
48915+} __no_const;
48916
48917 struct lsm_operations {
48918 void (*lsm_free)(struct lov_stripe_md *);
48919diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48920index 39fcdac..222780f 100644
48921--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48922+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48923@@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
48924 int added = (mode == LCK_NL);
48925 int overlaps = 0;
48926 int splitted = 0;
48927- const struct ldlm_callback_suite null_cbs = { NULL };
48928+ const struct ldlm_callback_suite null_cbs = { };
48929 int rc;
48930
48931 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
48932diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48933index fc6c977..df1f956 100644
48934--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48935+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48936@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
48937 int LL_PROC_PROTO(proc_console_max_delay_cs)
48938 {
48939 int rc, max_delay_cs;
48940- ctl_table_t dummy = *table;
48941+ ctl_table_no_const dummy = *table;
48942 cfs_duration_t d;
48943
48944 dummy.data = &max_delay_cs;
48945@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
48946 int LL_PROC_PROTO(proc_console_min_delay_cs)
48947 {
48948 int rc, min_delay_cs;
48949- ctl_table_t dummy = *table;
48950+ ctl_table_no_const dummy = *table;
48951 cfs_duration_t d;
48952
48953 dummy.data = &min_delay_cs;
48954@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
48955 int LL_PROC_PROTO(proc_console_backoff)
48956 {
48957 int rc, backoff;
48958- ctl_table_t dummy = *table;
48959+ ctl_table_no_const dummy = *table;
48960
48961 dummy.data = &backoff;
48962 dummy.proc_handler = &proc_dointvec;
48963diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
48964index f3108c7..cd4f9da 100644
48965--- a/drivers/staging/lustre/lustre/libcfs/module.c
48966+++ b/drivers/staging/lustre/lustre/libcfs/module.c
48967@@ -348,11 +348,11 @@ out:
48968
48969
48970 struct cfs_psdev_ops libcfs_psdev_ops = {
48971- libcfs_psdev_open,
48972- libcfs_psdev_release,
48973- NULL,
48974- NULL,
48975- libcfs_ioctl
48976+ .p_open = libcfs_psdev_open,
48977+ .p_close = libcfs_psdev_release,
48978+ .p_read = NULL,
48979+ .p_write = NULL,
48980+ .p_ioctl = libcfs_ioctl
48981 };
48982
48983 extern int insert_proc(void);
48984diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
48985index 3675020..e80d92c 100644
48986--- a/drivers/staging/media/solo6x10/solo6x10-core.c
48987+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
48988@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
48989
48990 static int solo_sysfs_init(struct solo_dev *solo_dev)
48991 {
48992- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
48993+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
48994 struct device *dev = &solo_dev->dev;
48995 const char *driver;
48996 int i;
48997diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
48998index 1db18c7..35e6afc 100644
48999--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49000+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49001@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49002
49003 int solo_g723_init(struct solo_dev *solo_dev)
49004 {
49005- static struct snd_device_ops ops = { NULL };
49006+ static struct snd_device_ops ops = { };
49007 struct snd_card *card;
49008 struct snd_kcontrol_new kctl;
49009 char name[32];
49010diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49011index 7f2f247..d999137 100644
49012--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49013+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49014@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49015
49016 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49017 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49018- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49019+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49020 if (p2m_id < 0)
49021 p2m_id = -p2m_id;
49022 }
49023diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49024index f1bbb8c..a73eaba 100644
49025--- a/drivers/staging/media/solo6x10/solo6x10.h
49026+++ b/drivers/staging/media/solo6x10/solo6x10.h
49027@@ -237,7 +237,7 @@ struct solo_dev {
49028
49029 /* P2M DMA Engine */
49030 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49031- atomic_t p2m_count;
49032+ atomic_unchecked_t p2m_count;
49033 int p2m_jiffies;
49034 unsigned int p2m_timeouts;
49035
49036diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49037index 0315f60..2ecae10 100644
49038--- a/drivers/staging/octeon/ethernet-rx.c
49039+++ b/drivers/staging/octeon/ethernet-rx.c
49040@@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49041 /* Increment RX stats for virtual ports */
49042 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49043 #ifdef CONFIG_64BIT
49044- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49045- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49046+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49047+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49048 #else
49049- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49050- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49051+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49052+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49053 #endif
49054 }
49055 netif_receive_skb(skb);
49056@@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49057 dev->name);
49058 */
49059 #ifdef CONFIG_64BIT
49060- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49061+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49062 #else
49063- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49064+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49065 #endif
49066 dev_kfree_skb_irq(skb);
49067 }
49068diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49069index bd6ca71..8f0961e 100644
49070--- a/drivers/staging/octeon/ethernet.c
49071+++ b/drivers/staging/octeon/ethernet.c
49072@@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49073 * since the RX tasklet also increments it.
49074 */
49075 #ifdef CONFIG_64BIT
49076- atomic64_add(rx_status.dropped_packets,
49077- (atomic64_t *)&priv->stats.rx_dropped);
49078+ atomic64_add_unchecked(rx_status.dropped_packets,
49079+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49080 #else
49081- atomic_add(rx_status.dropped_packets,
49082- (atomic_t *)&priv->stats.rx_dropped);
49083+ atomic_add_unchecked(rx_status.dropped_packets,
49084+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
49085 #endif
49086 }
49087
49088diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49089index 439c3c9..2d74293 100644
49090--- a/drivers/staging/rtl8188eu/include/hal_intf.h
49091+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49092@@ -271,7 +271,7 @@ struct hal_ops {
49093 s32 (*c2h_handler)(struct adapter *padapter,
49094 struct c2h_evt_hdr *c2h_evt);
49095 c2h_id_filter c2h_id_filter_ccx;
49096-};
49097+} __no_const;
49098
49099 enum rt_eeprom_type {
49100 EEPROM_93C46,
49101diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49102index eb6f0e5..e6a0958 100644
49103--- a/drivers/staging/rtl8188eu/include/rtw_io.h
49104+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49105@@ -126,7 +126,7 @@ struct _io_ops {
49106 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49107 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49108 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49109-};
49110+} __no_const;
49111
49112 struct io_req {
49113 struct list_head list;
49114diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49115index dc23395..cf7e9b1 100644
49116--- a/drivers/staging/rtl8712/rtl871x_io.h
49117+++ b/drivers/staging/rtl8712/rtl871x_io.h
49118@@ -108,7 +108,7 @@ struct _io_ops {
49119 u8 *pmem);
49120 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49121 u8 *pmem);
49122-};
49123+} __no_const;
49124
49125 struct io_req {
49126 struct list_head list;
49127diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49128index 1f5088b..0e59820 100644
49129--- a/drivers/staging/sbe-2t3e3/netdev.c
49130+++ b/drivers/staging/sbe-2t3e3/netdev.c
49131@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49132 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49133
49134 if (rlen)
49135- if (copy_to_user(data, &resp, rlen))
49136+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49137 return -EFAULT;
49138
49139 return 0;
49140diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49141index a863a98..d272795 100644
49142--- a/drivers/staging/usbip/vhci.h
49143+++ b/drivers/staging/usbip/vhci.h
49144@@ -83,7 +83,7 @@ struct vhci_hcd {
49145 unsigned resuming:1;
49146 unsigned long re_timeout;
49147
49148- atomic_t seqnum;
49149+ atomic_unchecked_t seqnum;
49150
49151 /*
49152 * NOTE:
49153diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49154index e810ad5..931336f 100644
49155--- a/drivers/staging/usbip/vhci_hcd.c
49156+++ b/drivers/staging/usbip/vhci_hcd.c
49157@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49158
49159 spin_lock(&vdev->priv_lock);
49160
49161- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49162+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49163 if (priv->seqnum == 0xffff)
49164 dev_info(&urb->dev->dev, "seqnum max\n");
49165
49166@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49167 return -ENOMEM;
49168 }
49169
49170- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49171+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49172 if (unlink->seqnum == 0xffff)
49173 pr_info("seqnum max\n");
49174
49175@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
49176 vdev->rhport = rhport;
49177 }
49178
49179- atomic_set(&vhci->seqnum, 0);
49180+ atomic_set_unchecked(&vhci->seqnum, 0);
49181 spin_lock_init(&vhci->lock);
49182
49183 hcd->power_budget = 0; /* no limit */
49184diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
49185index d07fcb5..358e1e1 100644
49186--- a/drivers/staging/usbip/vhci_rx.c
49187+++ b/drivers/staging/usbip/vhci_rx.c
49188@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
49189 if (!urb) {
49190 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
49191 pr_info("max seqnum %d\n",
49192- atomic_read(&the_controller->seqnum));
49193+ atomic_read_unchecked(&the_controller->seqnum));
49194 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
49195 return;
49196 }
49197diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
49198index ab8b2ba..99184aa 100644
49199--- a/drivers/staging/vt6655/hostap.c
49200+++ b/drivers/staging/vt6655/hostap.c
49201@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
49202 *
49203 */
49204
49205+static net_device_ops_no_const apdev_netdev_ops;
49206+
49207 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49208 {
49209 PSDevice apdev_priv;
49210 struct net_device *dev = pDevice->dev;
49211 int ret;
49212- const struct net_device_ops apdev_netdev_ops = {
49213- .ndo_start_xmit = pDevice->tx_80211,
49214- };
49215
49216 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49217
49218@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49219 *apdev_priv = *pDevice;
49220 eth_hw_addr_inherit(pDevice->apdev, dev);
49221
49222+ /* only half broken now */
49223+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49224 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49225
49226 pDevice->apdev->type = ARPHRD_IEEE80211;
49227diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
49228index 67ba48b..24e602f 100644
49229--- a/drivers/staging/vt6656/hostap.c
49230+++ b/drivers/staging/vt6656/hostap.c
49231@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
49232 *
49233 */
49234
49235+static net_device_ops_no_const apdev_netdev_ops;
49236+
49237 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49238 {
49239 struct vnt_private *apdev_priv;
49240 struct net_device *dev = pDevice->dev;
49241 int ret;
49242- const struct net_device_ops apdev_netdev_ops = {
49243- .ndo_start_xmit = pDevice->tx_80211,
49244- };
49245
49246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49247
49248@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49249 *apdev_priv = *pDevice;
49250 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
49251
49252+ /* only half broken now */
49253+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49254 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49255
49256 pDevice->apdev->type = ARPHRD_IEEE80211;
49257diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
49258index 24884ca..26c8220 100644
49259--- a/drivers/target/sbp/sbp_target.c
49260+++ b/drivers/target/sbp/sbp_target.c
49261@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
49262
49263 #define SESSION_MAINTENANCE_INTERVAL HZ
49264
49265-static atomic_t login_id = ATOMIC_INIT(0);
49266+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
49267
49268 static void session_maintenance_work(struct work_struct *);
49269 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
49270@@ -444,7 +444,7 @@ static void sbp_management_request_login(
49271 login->lun = se_lun;
49272 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
49273 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
49274- login->login_id = atomic_inc_return(&login_id);
49275+ login->login_id = atomic_inc_return_unchecked(&login_id);
49276
49277 login->tgt_agt = sbp_target_agent_register(login);
49278 if (IS_ERR(login->tgt_agt)) {
49279diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
49280index d06de84..fd38c9b 100644
49281--- a/drivers/target/target_core_device.c
49282+++ b/drivers/target/target_core_device.c
49283@@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
49284 spin_lock_init(&dev->se_tmr_lock);
49285 spin_lock_init(&dev->qf_cmd_lock);
49286 sema_init(&dev->caw_sem, 1);
49287- atomic_set(&dev->dev_ordered_id, 0);
49288+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
49289 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
49290 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
49291 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
49292diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
49293index 91953da..a842b90 100644
49294--- a/drivers/target/target_core_transport.c
49295+++ b/drivers/target/target_core_transport.c
49296@@ -1112,7 +1112,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
49297 * Used to determine when ORDERED commands should go from
49298 * Dormant to Active status.
49299 */
49300- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
49301+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
49302 smp_mb__after_atomic_inc();
49303 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
49304 cmd->se_ordered_id, cmd->sam_task_attr,
49305diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
49306index 33f83fe..d80f8e1 100644
49307--- a/drivers/tty/cyclades.c
49308+++ b/drivers/tty/cyclades.c
49309@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
49310 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
49311 info->port.count);
49312 #endif
49313- info->port.count++;
49314+ atomic_inc(&info->port.count);
49315 #ifdef CY_DEBUG_COUNT
49316 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
49317- current->pid, info->port.count);
49318+ current->pid, atomic_read(&info->port.count));
49319 #endif
49320
49321 /*
49322@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
49323 for (j = 0; j < cy_card[i].nports; j++) {
49324 info = &cy_card[i].ports[j];
49325
49326- if (info->port.count) {
49327+ if (atomic_read(&info->port.count)) {
49328 /* XXX is the ldisc num worth this? */
49329 struct tty_struct *tty;
49330 struct tty_ldisc *ld;
49331diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
49332index 9eba119..5070303 100644
49333--- a/drivers/tty/hvc/hvc_console.c
49334+++ b/drivers/tty/hvc/hvc_console.c
49335@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
49336
49337 spin_lock_irqsave(&hp->port.lock, flags);
49338 /* Check and then increment for fast path open. */
49339- if (hp->port.count++ > 0) {
49340+ if (atomic_inc_return(&hp->port.count) > 1) {
49341 spin_unlock_irqrestore(&hp->port.lock, flags);
49342 hvc_kick();
49343 return 0;
49344@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49345
49346 spin_lock_irqsave(&hp->port.lock, flags);
49347
49348- if (--hp->port.count == 0) {
49349+ if (atomic_dec_return(&hp->port.count) == 0) {
49350 spin_unlock_irqrestore(&hp->port.lock, flags);
49351 /* We are done with the tty pointer now. */
49352 tty_port_tty_set(&hp->port, NULL);
49353@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49354 */
49355 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
49356 } else {
49357- if (hp->port.count < 0)
49358+ if (atomic_read(&hp->port.count) < 0)
49359 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
49360- hp->vtermno, hp->port.count);
49361+ hp->vtermno, atomic_read(&hp->port.count));
49362 spin_unlock_irqrestore(&hp->port.lock, flags);
49363 }
49364 }
49365@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
49366 * open->hangup case this can be called after the final close so prevent
49367 * that from happening for now.
49368 */
49369- if (hp->port.count <= 0) {
49370+ if (atomic_read(&hp->port.count) <= 0) {
49371 spin_unlock_irqrestore(&hp->port.lock, flags);
49372 return;
49373 }
49374
49375- hp->port.count = 0;
49376+ atomic_set(&hp->port.count, 0);
49377 spin_unlock_irqrestore(&hp->port.lock, flags);
49378 tty_port_tty_set(&hp->port, NULL);
49379
49380@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
49381 return -EPIPE;
49382
49383 /* FIXME what's this (unprotected) check for? */
49384- if (hp->port.count <= 0)
49385+ if (atomic_read(&hp->port.count) <= 0)
49386 return -EIO;
49387
49388 spin_lock_irqsave(&hp->lock, flags);
49389diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
49390index 81e939e..95ead10 100644
49391--- a/drivers/tty/hvc/hvcs.c
49392+++ b/drivers/tty/hvc/hvcs.c
49393@@ -83,6 +83,7 @@
49394 #include <asm/hvcserver.h>
49395 #include <asm/uaccess.h>
49396 #include <asm/vio.h>
49397+#include <asm/local.h>
49398
49399 /*
49400 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
49401@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
49402
49403 spin_lock_irqsave(&hvcsd->lock, flags);
49404
49405- if (hvcsd->port.count > 0) {
49406+ if (atomic_read(&hvcsd->port.count) > 0) {
49407 spin_unlock_irqrestore(&hvcsd->lock, flags);
49408 printk(KERN_INFO "HVCS: vterm state unchanged. "
49409 "The hvcs device node is still in use.\n");
49410@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
49411 }
49412 }
49413
49414- hvcsd->port.count = 0;
49415+ atomic_set(&hvcsd->port.count, 0);
49416 hvcsd->port.tty = tty;
49417 tty->driver_data = hvcsd;
49418
49419@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
49420 unsigned long flags;
49421
49422 spin_lock_irqsave(&hvcsd->lock, flags);
49423- hvcsd->port.count++;
49424+ atomic_inc(&hvcsd->port.count);
49425 hvcsd->todo_mask |= HVCS_SCHED_READ;
49426 spin_unlock_irqrestore(&hvcsd->lock, flags);
49427
49428@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49429 hvcsd = tty->driver_data;
49430
49431 spin_lock_irqsave(&hvcsd->lock, flags);
49432- if (--hvcsd->port.count == 0) {
49433+ if (atomic_dec_and_test(&hvcsd->port.count)) {
49434
49435 vio_disable_interrupts(hvcsd->vdev);
49436
49437@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49438
49439 free_irq(irq, hvcsd);
49440 return;
49441- } else if (hvcsd->port.count < 0) {
49442+ } else if (atomic_read(&hvcsd->port.count) < 0) {
49443 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
49444 " is missmanaged.\n",
49445- hvcsd->vdev->unit_address, hvcsd->port.count);
49446+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
49447 }
49448
49449 spin_unlock_irqrestore(&hvcsd->lock, flags);
49450@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49451
49452 spin_lock_irqsave(&hvcsd->lock, flags);
49453 /* Preserve this so that we know how many kref refs to put */
49454- temp_open_count = hvcsd->port.count;
49455+ temp_open_count = atomic_read(&hvcsd->port.count);
49456
49457 /*
49458 * Don't kref put inside the spinlock because the destruction
49459@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49460 tty->driver_data = NULL;
49461 hvcsd->port.tty = NULL;
49462
49463- hvcsd->port.count = 0;
49464+ atomic_set(&hvcsd->port.count, 0);
49465
49466 /* This will drop any buffered data on the floor which is OK in a hangup
49467 * scenario. */
49468@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
49469 * the middle of a write operation? This is a crummy place to do this
49470 * but we want to keep it all in the spinlock.
49471 */
49472- if (hvcsd->port.count <= 0) {
49473+ if (atomic_read(&hvcsd->port.count) <= 0) {
49474 spin_unlock_irqrestore(&hvcsd->lock, flags);
49475 return -ENODEV;
49476 }
49477@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
49478 {
49479 struct hvcs_struct *hvcsd = tty->driver_data;
49480
49481- if (!hvcsd || hvcsd->port.count <= 0)
49482+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
49483 return 0;
49484
49485 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
49486diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
49487index 4190199..48f2920 100644
49488--- a/drivers/tty/hvc/hvsi.c
49489+++ b/drivers/tty/hvc/hvsi.c
49490@@ -85,7 +85,7 @@ struct hvsi_struct {
49491 int n_outbuf;
49492 uint32_t vtermno;
49493 uint32_t virq;
49494- atomic_t seqno; /* HVSI packet sequence number */
49495+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
49496 uint16_t mctrl;
49497 uint8_t state; /* HVSI protocol state */
49498 uint8_t flags;
49499@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
49500
49501 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
49502 packet.hdr.len = sizeof(struct hvsi_query_response);
49503- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49504+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49505 packet.verb = VSV_SEND_VERSION_NUMBER;
49506 packet.u.version = HVSI_VERSION;
49507 packet.query_seqno = query_seqno+1;
49508@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
49509
49510 packet.hdr.type = VS_QUERY_PACKET_HEADER;
49511 packet.hdr.len = sizeof(struct hvsi_query);
49512- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49513+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49514 packet.verb = verb;
49515
49516 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
49517@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
49518 int wrote;
49519
49520 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
49521- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49522+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49523 packet.hdr.len = sizeof(struct hvsi_control);
49524 packet.verb = VSV_SET_MODEM_CTL;
49525 packet.mask = HVSI_TSDTR;
49526@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
49527 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
49528
49529 packet.hdr.type = VS_DATA_PACKET_HEADER;
49530- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49531+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49532 packet.hdr.len = count + sizeof(struct hvsi_header);
49533 memcpy(&packet.data, buf, count);
49534
49535@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
49536 struct hvsi_control packet __ALIGNED__;
49537
49538 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
49539- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49540+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49541 packet.hdr.len = 6;
49542 packet.verb = VSV_CLOSE_PROTOCOL;
49543
49544diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
49545index 347050e..14f8fbf 100644
49546--- a/drivers/tty/hvc/hvsi_lib.c
49547+++ b/drivers/tty/hvc/hvsi_lib.c
49548@@ -9,7 +9,7 @@
49549
49550 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
49551 {
49552- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
49553+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
49554
49555 /* Assumes that always succeeds, works in practice */
49556 return pv->put_chars(pv->termno, (char *)packet, packet->len);
49557@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
49558
49559 /* Reset state */
49560 pv->established = 0;
49561- atomic_set(&pv->seqno, 0);
49562+ atomic_set_unchecked(&pv->seqno, 0);
49563
49564 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
49565
49566diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
49567index 8fd72ff..34a0bed 100644
49568--- a/drivers/tty/ipwireless/tty.c
49569+++ b/drivers/tty/ipwireless/tty.c
49570@@ -29,6 +29,7 @@
49571 #include <linux/tty_driver.h>
49572 #include <linux/tty_flip.h>
49573 #include <linux/uaccess.h>
49574+#include <asm/local.h>
49575
49576 #include "tty.h"
49577 #include "network.h"
49578@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49579 mutex_unlock(&tty->ipw_tty_mutex);
49580 return -ENODEV;
49581 }
49582- if (tty->port.count == 0)
49583+ if (atomic_read(&tty->port.count) == 0)
49584 tty->tx_bytes_queued = 0;
49585
49586- tty->port.count++;
49587+ atomic_inc(&tty->port.count);
49588
49589 tty->port.tty = linux_tty;
49590 linux_tty->driver_data = tty;
49591@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49592
49593 static void do_ipw_close(struct ipw_tty *tty)
49594 {
49595- tty->port.count--;
49596-
49597- if (tty->port.count == 0) {
49598+ if (atomic_dec_return(&tty->port.count) == 0) {
49599 struct tty_struct *linux_tty = tty->port.tty;
49600
49601 if (linux_tty != NULL) {
49602@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
49603 return;
49604
49605 mutex_lock(&tty->ipw_tty_mutex);
49606- if (tty->port.count == 0) {
49607+ if (atomic_read(&tty->port.count) == 0) {
49608 mutex_unlock(&tty->ipw_tty_mutex);
49609 return;
49610 }
49611@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
49612
49613 mutex_lock(&tty->ipw_tty_mutex);
49614
49615- if (!tty->port.count) {
49616+ if (!atomic_read(&tty->port.count)) {
49617 mutex_unlock(&tty->ipw_tty_mutex);
49618 return;
49619 }
49620@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
49621 return -ENODEV;
49622
49623 mutex_lock(&tty->ipw_tty_mutex);
49624- if (!tty->port.count) {
49625+ if (!atomic_read(&tty->port.count)) {
49626 mutex_unlock(&tty->ipw_tty_mutex);
49627 return -EINVAL;
49628 }
49629@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
49630 if (!tty)
49631 return -ENODEV;
49632
49633- if (!tty->port.count)
49634+ if (!atomic_read(&tty->port.count))
49635 return -EINVAL;
49636
49637 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
49638@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
49639 if (!tty)
49640 return 0;
49641
49642- if (!tty->port.count)
49643+ if (!atomic_read(&tty->port.count))
49644 return 0;
49645
49646 return tty->tx_bytes_queued;
49647@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
49648 if (!tty)
49649 return -ENODEV;
49650
49651- if (!tty->port.count)
49652+ if (!atomic_read(&tty->port.count))
49653 return -EINVAL;
49654
49655 return get_control_lines(tty);
49656@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
49657 if (!tty)
49658 return -ENODEV;
49659
49660- if (!tty->port.count)
49661+ if (!atomic_read(&tty->port.count))
49662 return -EINVAL;
49663
49664 return set_control_lines(tty, set, clear);
49665@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
49666 if (!tty)
49667 return -ENODEV;
49668
49669- if (!tty->port.count)
49670+ if (!atomic_read(&tty->port.count))
49671 return -EINVAL;
49672
49673 /* FIXME: Exactly how is the tty object locked here .. */
49674@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
49675 * are gone */
49676 mutex_lock(&ttyj->ipw_tty_mutex);
49677 }
49678- while (ttyj->port.count)
49679+ while (atomic_read(&ttyj->port.count))
49680 do_ipw_close(ttyj);
49681 ipwireless_disassociate_network_ttys(network,
49682 ttyj->channel_idx);
49683diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
49684index 1deaca4..c8582d4 100644
49685--- a/drivers/tty/moxa.c
49686+++ b/drivers/tty/moxa.c
49687@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
49688 }
49689
49690 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
49691- ch->port.count++;
49692+ atomic_inc(&ch->port.count);
49693 tty->driver_data = ch;
49694 tty_port_tty_set(&ch->port, tty);
49695 mutex_lock(&ch->port.mutex);
49696diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
49697index c0f76da..d974c32 100644
49698--- a/drivers/tty/n_gsm.c
49699+++ b/drivers/tty/n_gsm.c
49700@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
49701 spin_lock_init(&dlci->lock);
49702 mutex_init(&dlci->mutex);
49703 dlci->fifo = &dlci->_fifo;
49704- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
49705+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
49706 kfree(dlci);
49707 return NULL;
49708 }
49709@@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
49710 struct gsm_dlci *dlci = tty->driver_data;
49711 struct tty_port *port = &dlci->port;
49712
49713- port->count++;
49714+ atomic_inc(&port->count);
49715 dlci_get(dlci);
49716 dlci_get(dlci->gsm->dlci[0]);
49717 mux_get(dlci->gsm);
49718diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
49719index 34aacaa..dad073b 100644
49720--- a/drivers/tty/n_tty.c
49721+++ b/drivers/tty/n_tty.c
49722@@ -114,7 +114,7 @@ struct n_tty_data {
49723 int minimum_to_wake;
49724
49725 /* consumer-published */
49726- size_t read_tail;
49727+ size_t read_tail __intentional_overflow(-1);
49728 size_t line_start;
49729
49730 /* protected by output lock */
49731@@ -2502,6 +2502,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
49732 {
49733 *ops = tty_ldisc_N_TTY;
49734 ops->owner = NULL;
49735- ops->refcount = ops->flags = 0;
49736+ atomic_set(&ops->refcount, 0);
49737+ ops->flags = 0;
49738 }
49739 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
49740diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
49741index 25c9bc7..24077b7 100644
49742--- a/drivers/tty/pty.c
49743+++ b/drivers/tty/pty.c
49744@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
49745 panic("Couldn't register Unix98 pts driver");
49746
49747 /* Now create the /dev/ptmx special device */
49748+ pax_open_kernel();
49749 tty_default_fops(&ptmx_fops);
49750- ptmx_fops.open = ptmx_open;
49751+ *(void **)&ptmx_fops.open = ptmx_open;
49752+ pax_close_kernel();
49753
49754 cdev_init(&ptmx_cdev, &ptmx_fops);
49755 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
49756diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
49757index 354564e..fe50d9a 100644
49758--- a/drivers/tty/rocket.c
49759+++ b/drivers/tty/rocket.c
49760@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49761 tty->driver_data = info;
49762 tty_port_tty_set(port, tty);
49763
49764- if (port->count++ == 0) {
49765+ if (atomic_inc_return(&port->count) == 1) {
49766 atomic_inc(&rp_num_ports_open);
49767
49768 #ifdef ROCKET_DEBUG_OPEN
49769@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49770 #endif
49771 }
49772 #ifdef ROCKET_DEBUG_OPEN
49773- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
49774+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
49775 #endif
49776
49777 /*
49778@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
49779 spin_unlock_irqrestore(&info->port.lock, flags);
49780 return;
49781 }
49782- if (info->port.count)
49783+ if (atomic_read(&info->port.count))
49784 atomic_dec(&rp_num_ports_open);
49785 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
49786 spin_unlock_irqrestore(&info->port.lock, flags);
49787diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
49788index 1274499..f541382 100644
49789--- a/drivers/tty/serial/ioc4_serial.c
49790+++ b/drivers/tty/serial/ioc4_serial.c
49791@@ -437,7 +437,7 @@ struct ioc4_soft {
49792 } is_intr_info[MAX_IOC4_INTR_ENTS];
49793
49794 /* Number of entries active in the above array */
49795- atomic_t is_num_intrs;
49796+ atomic_unchecked_t is_num_intrs;
49797 } is_intr_type[IOC4_NUM_INTR_TYPES];
49798
49799 /* is_ir_lock must be held while
49800@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
49801 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
49802 || (type == IOC4_OTHER_INTR_TYPE)));
49803
49804- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
49805+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
49806 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
49807
49808 /* Save off the lower level interrupt handler */
49809@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
49810
49811 soft = arg;
49812 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
49813- num_intrs = (int)atomic_read(
49814+ num_intrs = (int)atomic_read_unchecked(
49815 &soft->is_intr_type[intr_type].is_num_intrs);
49816
49817 this_mir = this_ir = pending_intrs(soft, intr_type);
49818diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
49819index a260cde..6b2b5ce 100644
49820--- a/drivers/tty/serial/kgdboc.c
49821+++ b/drivers/tty/serial/kgdboc.c
49822@@ -24,8 +24,9 @@
49823 #define MAX_CONFIG_LEN 40
49824
49825 static struct kgdb_io kgdboc_io_ops;
49826+static struct kgdb_io kgdboc_io_ops_console;
49827
49828-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
49829+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
49830 static int configured = -1;
49831
49832 static char config[MAX_CONFIG_LEN];
49833@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
49834 kgdboc_unregister_kbd();
49835 if (configured == 1)
49836 kgdb_unregister_io_module(&kgdboc_io_ops);
49837+ else if (configured == 2)
49838+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
49839 }
49840
49841 static int configure_kgdboc(void)
49842@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
49843 int err;
49844 char *cptr = config;
49845 struct console *cons;
49846+ int is_console = 0;
49847
49848 err = kgdboc_option_setup(config);
49849 if (err || !strlen(config) || isspace(config[0]))
49850 goto noconfig;
49851
49852 err = -ENODEV;
49853- kgdboc_io_ops.is_console = 0;
49854 kgdb_tty_driver = NULL;
49855
49856 kgdboc_use_kms = 0;
49857@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
49858 int idx;
49859 if (cons->device && cons->device(cons, &idx) == p &&
49860 idx == tty_line) {
49861- kgdboc_io_ops.is_console = 1;
49862+ is_console = 1;
49863 break;
49864 }
49865 cons = cons->next;
49866@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
49867 kgdb_tty_line = tty_line;
49868
49869 do_register:
49870- err = kgdb_register_io_module(&kgdboc_io_ops);
49871+ if (is_console) {
49872+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
49873+ configured = 2;
49874+ } else {
49875+ err = kgdb_register_io_module(&kgdboc_io_ops);
49876+ configured = 1;
49877+ }
49878 if (err)
49879 goto noconfig;
49880
49881@@ -205,8 +214,6 @@ do_register:
49882 if (err)
49883 goto nmi_con_failed;
49884
49885- configured = 1;
49886-
49887 return 0;
49888
49889 nmi_con_failed:
49890@@ -223,7 +230,7 @@ noconfig:
49891 static int __init init_kgdboc(void)
49892 {
49893 /* Already configured? */
49894- if (configured == 1)
49895+ if (configured >= 1)
49896 return 0;
49897
49898 return configure_kgdboc();
49899@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
49900 if (config[len - 1] == '\n')
49901 config[len - 1] = '\0';
49902
49903- if (configured == 1)
49904+ if (configured >= 1)
49905 cleanup_kgdboc();
49906
49907 /* Go and configure with the new params. */
49908@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
49909 .post_exception = kgdboc_post_exp_handler,
49910 };
49911
49912+static struct kgdb_io kgdboc_io_ops_console = {
49913+ .name = "kgdboc",
49914+ .read_char = kgdboc_get_char,
49915+ .write_char = kgdboc_put_char,
49916+ .pre_exception = kgdboc_pre_exp_handler,
49917+ .post_exception = kgdboc_post_exp_handler,
49918+ .is_console = 1
49919+};
49920+
49921 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
49922 /* This is only available if kgdboc is a built in for early debugging */
49923 static int __init kgdboc_early_init(char *opt)
49924diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
49925index b5d779c..3622cfe 100644
49926--- a/drivers/tty/serial/msm_serial.c
49927+++ b/drivers/tty/serial/msm_serial.c
49928@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
49929 .cons = MSM_CONSOLE,
49930 };
49931
49932-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
49933+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
49934
49935 static const struct of_device_id msm_uartdm_table[] = {
49936 { .compatible = "qcom,msm-uartdm" },
49937@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
49938 int irq;
49939
49940 if (pdev->id == -1)
49941- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
49942+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
49943
49944 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
49945 return -ENXIO;
49946diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
49947index c1af04d..0815c8a 100644
49948--- a/drivers/tty/serial/samsung.c
49949+++ b/drivers/tty/serial/samsung.c
49950@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
49951 }
49952 }
49953
49954+static int s3c64xx_serial_startup(struct uart_port *port);
49955 static int s3c24xx_serial_startup(struct uart_port *port)
49956 {
49957 struct s3c24xx_uart_port *ourport = to_ourport(port);
49958 int ret;
49959
49960+ /* Startup sequence is different for s3c64xx and higher SoC's */
49961+ if (s3c24xx_serial_has_interrupt_mask(port))
49962+ return s3c64xx_serial_startup(port);
49963+
49964 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
49965 port->mapbase, port->membase);
49966
49967@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
49968 /* setup info for port */
49969 port->dev = &platdev->dev;
49970
49971- /* Startup sequence is different for s3c64xx and higher SoC's */
49972- if (s3c24xx_serial_has_interrupt_mask(port))
49973- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
49974-
49975 port->uartclk = 1;
49976
49977 if (cfg->uart_flags & UPF_CONS_FLOW) {
49978diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
49979index 0f02351..07c59c5 100644
49980--- a/drivers/tty/serial/serial_core.c
49981+++ b/drivers/tty/serial/serial_core.c
49982@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
49983 uart_flush_buffer(tty);
49984 uart_shutdown(tty, state);
49985 spin_lock_irqsave(&port->lock, flags);
49986- port->count = 0;
49987+ atomic_set(&port->count, 0);
49988 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
49989 spin_unlock_irqrestore(&port->lock, flags);
49990 tty_port_tty_set(port, NULL);
49991@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
49992 goto end;
49993 }
49994
49995- port->count++;
49996+ atomic_inc(&port->count);
49997 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
49998 retval = -ENXIO;
49999 goto err_dec_count;
50000@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50001 /*
50002 * Make sure the device is in D0 state.
50003 */
50004- if (port->count == 1)
50005+ if (atomic_read(&port->count) == 1)
50006 uart_change_pm(state, UART_PM_STATE_ON);
50007
50008 /*
50009@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50010 end:
50011 return retval;
50012 err_dec_count:
50013- port->count--;
50014+ atomic_inc(&port->count);
50015 mutex_unlock(&port->mutex);
50016 goto end;
50017 }
50018diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50019index e1ce141..6d4ed80 100644
50020--- a/drivers/tty/synclink.c
50021+++ b/drivers/tty/synclink.c
50022@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50023
50024 if (debug_level >= DEBUG_LEVEL_INFO)
50025 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50026- __FILE__,__LINE__, info->device_name, info->port.count);
50027+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50028
50029 if (tty_port_close_start(&info->port, tty, filp) == 0)
50030 goto cleanup;
50031@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50032 cleanup:
50033 if (debug_level >= DEBUG_LEVEL_INFO)
50034 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50035- tty->driver->name, info->port.count);
50036+ tty->driver->name, atomic_read(&info->port.count));
50037
50038 } /* end of mgsl_close() */
50039
50040@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50041
50042 mgsl_flush_buffer(tty);
50043 shutdown(info);
50044-
50045- info->port.count = 0;
50046+
50047+ atomic_set(&info->port.count, 0);
50048 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50049 info->port.tty = NULL;
50050
50051@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50052
50053 if (debug_level >= DEBUG_LEVEL_INFO)
50054 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50055- __FILE__,__LINE__, tty->driver->name, port->count );
50056+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50057
50058 spin_lock_irqsave(&info->irq_spinlock, flags);
50059 if (!tty_hung_up_p(filp)) {
50060 extra_count = true;
50061- port->count--;
50062+ atomic_dec(&port->count);
50063 }
50064 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50065 port->blocked_open++;
50066@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50067
50068 if (debug_level >= DEBUG_LEVEL_INFO)
50069 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50070- __FILE__,__LINE__, tty->driver->name, port->count );
50071+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50072
50073 tty_unlock(tty);
50074 schedule();
50075@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50076
50077 /* FIXME: Racy on hangup during close wait */
50078 if (extra_count)
50079- port->count++;
50080+ atomic_inc(&port->count);
50081 port->blocked_open--;
50082
50083 if (debug_level >= DEBUG_LEVEL_INFO)
50084 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50085- __FILE__,__LINE__, tty->driver->name, port->count );
50086+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50087
50088 if (!retval)
50089 port->flags |= ASYNC_NORMAL_ACTIVE;
50090@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50091
50092 if (debug_level >= DEBUG_LEVEL_INFO)
50093 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50094- __FILE__,__LINE__,tty->driver->name, info->port.count);
50095+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50096
50097 /* If port is closing, signal caller to try again */
50098 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50099@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50100 spin_unlock_irqrestore(&info->netlock, flags);
50101 goto cleanup;
50102 }
50103- info->port.count++;
50104+ atomic_inc(&info->port.count);
50105 spin_unlock_irqrestore(&info->netlock, flags);
50106
50107- if (info->port.count == 1) {
50108+ if (atomic_read(&info->port.count) == 1) {
50109 /* 1st open on this device, init hardware */
50110 retval = startup(info);
50111 if (retval < 0)
50112@@ -3446,8 +3446,8 @@ cleanup:
50113 if (retval) {
50114 if (tty->count == 1)
50115 info->port.tty = NULL; /* tty layer will release tty struct */
50116- if(info->port.count)
50117- info->port.count--;
50118+ if (atomic_read(&info->port.count))
50119+ atomic_dec(&info->port.count);
50120 }
50121
50122 return retval;
50123@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50124 unsigned short new_crctype;
50125
50126 /* return error if TTY interface open */
50127- if (info->port.count)
50128+ if (atomic_read(&info->port.count))
50129 return -EBUSY;
50130
50131 switch (encoding)
50132@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50133
50134 /* arbitrate between network and tty opens */
50135 spin_lock_irqsave(&info->netlock, flags);
50136- if (info->port.count != 0 || info->netcount != 0) {
50137+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50138 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50139 spin_unlock_irqrestore(&info->netlock, flags);
50140 return -EBUSY;
50141@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50142 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50143
50144 /* return error if TTY interface open */
50145- if (info->port.count)
50146+ if (atomic_read(&info->port.count))
50147 return -EBUSY;
50148
50149 if (cmd != SIOCWANDEV)
50150diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
50151index 1abf946..1ee34fc 100644
50152--- a/drivers/tty/synclink_gt.c
50153+++ b/drivers/tty/synclink_gt.c
50154@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50155 tty->driver_data = info;
50156 info->port.tty = tty;
50157
50158- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
50159+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
50160
50161 /* If port is closing, signal caller to try again */
50162 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50163@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50164 mutex_unlock(&info->port.mutex);
50165 goto cleanup;
50166 }
50167- info->port.count++;
50168+ atomic_inc(&info->port.count);
50169 spin_unlock_irqrestore(&info->netlock, flags);
50170
50171- if (info->port.count == 1) {
50172+ if (atomic_read(&info->port.count) == 1) {
50173 /* 1st open on this device, init hardware */
50174 retval = startup(info);
50175 if (retval < 0) {
50176@@ -715,8 +715,8 @@ cleanup:
50177 if (retval) {
50178 if (tty->count == 1)
50179 info->port.tty = NULL; /* tty layer will release tty struct */
50180- if(info->port.count)
50181- info->port.count--;
50182+ if(atomic_read(&info->port.count))
50183+ atomic_dec(&info->port.count);
50184 }
50185
50186 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
50187@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50188
50189 if (sanity_check(info, tty->name, "close"))
50190 return;
50191- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
50192+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
50193
50194 if (tty_port_close_start(&info->port, tty, filp) == 0)
50195 goto cleanup;
50196@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50197 tty_port_close_end(&info->port, tty);
50198 info->port.tty = NULL;
50199 cleanup:
50200- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
50201+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
50202 }
50203
50204 static void hangup(struct tty_struct *tty)
50205@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
50206 shutdown(info);
50207
50208 spin_lock_irqsave(&info->port.lock, flags);
50209- info->port.count = 0;
50210+ atomic_set(&info->port.count, 0);
50211 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50212 info->port.tty = NULL;
50213 spin_unlock_irqrestore(&info->port.lock, flags);
50214@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50215 unsigned short new_crctype;
50216
50217 /* return error if TTY interface open */
50218- if (info->port.count)
50219+ if (atomic_read(&info->port.count))
50220 return -EBUSY;
50221
50222 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
50223@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
50224
50225 /* arbitrate between network and tty opens */
50226 spin_lock_irqsave(&info->netlock, flags);
50227- if (info->port.count != 0 || info->netcount != 0) {
50228+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50229 DBGINFO(("%s hdlc_open busy\n", dev->name));
50230 spin_unlock_irqrestore(&info->netlock, flags);
50231 return -EBUSY;
50232@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50233 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
50234
50235 /* return error if TTY interface open */
50236- if (info->port.count)
50237+ if (atomic_read(&info->port.count))
50238 return -EBUSY;
50239
50240 if (cmd != SIOCWANDEV)
50241@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
50242 if (port == NULL)
50243 continue;
50244 spin_lock(&port->lock);
50245- if ((port->port.count || port->netcount) &&
50246+ if ((atomic_read(&port->port.count) || port->netcount) &&
50247 port->pending_bh && !port->bh_running &&
50248 !port->bh_requested) {
50249 DBGISR(("%s bh queued\n", port->device_name));
50250@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50251 spin_lock_irqsave(&info->lock, flags);
50252 if (!tty_hung_up_p(filp)) {
50253 extra_count = true;
50254- port->count--;
50255+ atomic_dec(&port->count);
50256 }
50257 spin_unlock_irqrestore(&info->lock, flags);
50258 port->blocked_open++;
50259@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50260 remove_wait_queue(&port->open_wait, &wait);
50261
50262 if (extra_count)
50263- port->count++;
50264+ atomic_inc(&port->count);
50265 port->blocked_open--;
50266
50267 if (!retval)
50268diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
50269index dc6e969..5dc8786 100644
50270--- a/drivers/tty/synclinkmp.c
50271+++ b/drivers/tty/synclinkmp.c
50272@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50273
50274 if (debug_level >= DEBUG_LEVEL_INFO)
50275 printk("%s(%d):%s open(), old ref count = %d\n",
50276- __FILE__,__LINE__,tty->driver->name, info->port.count);
50277+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50278
50279 /* If port is closing, signal caller to try again */
50280 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50281@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50282 spin_unlock_irqrestore(&info->netlock, flags);
50283 goto cleanup;
50284 }
50285- info->port.count++;
50286+ atomic_inc(&info->port.count);
50287 spin_unlock_irqrestore(&info->netlock, flags);
50288
50289- if (info->port.count == 1) {
50290+ if (atomic_read(&info->port.count) == 1) {
50291 /* 1st open on this device, init hardware */
50292 retval = startup(info);
50293 if (retval < 0)
50294@@ -796,8 +796,8 @@ cleanup:
50295 if (retval) {
50296 if (tty->count == 1)
50297 info->port.tty = NULL; /* tty layer will release tty struct */
50298- if(info->port.count)
50299- info->port.count--;
50300+ if(atomic_read(&info->port.count))
50301+ atomic_dec(&info->port.count);
50302 }
50303
50304 return retval;
50305@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50306
50307 if (debug_level >= DEBUG_LEVEL_INFO)
50308 printk("%s(%d):%s close() entry, count=%d\n",
50309- __FILE__,__LINE__, info->device_name, info->port.count);
50310+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50311
50312 if (tty_port_close_start(&info->port, tty, filp) == 0)
50313 goto cleanup;
50314@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50315 cleanup:
50316 if (debug_level >= DEBUG_LEVEL_INFO)
50317 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
50318- tty->driver->name, info->port.count);
50319+ tty->driver->name, atomic_read(&info->port.count));
50320 }
50321
50322 /* Called by tty_hangup() when a hangup is signaled.
50323@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
50324 shutdown(info);
50325
50326 spin_lock_irqsave(&info->port.lock, flags);
50327- info->port.count = 0;
50328+ atomic_set(&info->port.count, 0);
50329 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50330 info->port.tty = NULL;
50331 spin_unlock_irqrestore(&info->port.lock, flags);
50332@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50333 unsigned short new_crctype;
50334
50335 /* return error if TTY interface open */
50336- if (info->port.count)
50337+ if (atomic_read(&info->port.count))
50338 return -EBUSY;
50339
50340 switch (encoding)
50341@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
50342
50343 /* arbitrate between network and tty opens */
50344 spin_lock_irqsave(&info->netlock, flags);
50345- if (info->port.count != 0 || info->netcount != 0) {
50346+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50347 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50348 spin_unlock_irqrestore(&info->netlock, flags);
50349 return -EBUSY;
50350@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50351 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50352
50353 /* return error if TTY interface open */
50354- if (info->port.count)
50355+ if (atomic_read(&info->port.count))
50356 return -EBUSY;
50357
50358 if (cmd != SIOCWANDEV)
50359@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
50360 * do not request bottom half processing if the
50361 * device is not open in a normal mode.
50362 */
50363- if ( port && (port->port.count || port->netcount) &&
50364+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
50365 port->pending_bh && !port->bh_running &&
50366 !port->bh_requested ) {
50367 if ( debug_level >= DEBUG_LEVEL_ISR )
50368@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50369
50370 if (debug_level >= DEBUG_LEVEL_INFO)
50371 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
50372- __FILE__,__LINE__, tty->driver->name, port->count );
50373+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50374
50375 spin_lock_irqsave(&info->lock, flags);
50376 if (!tty_hung_up_p(filp)) {
50377 extra_count = true;
50378- port->count--;
50379+ atomic_dec(&port->count);
50380 }
50381 spin_unlock_irqrestore(&info->lock, flags);
50382 port->blocked_open++;
50383@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50384
50385 if (debug_level >= DEBUG_LEVEL_INFO)
50386 printk("%s(%d):%s block_til_ready() count=%d\n",
50387- __FILE__,__LINE__, tty->driver->name, port->count );
50388+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50389
50390 tty_unlock(tty);
50391 schedule();
50392@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50393 remove_wait_queue(&port->open_wait, &wait);
50394
50395 if (extra_count)
50396- port->count++;
50397+ atomic_inc(&port->count);
50398 port->blocked_open--;
50399
50400 if (debug_level >= DEBUG_LEVEL_INFO)
50401 printk("%s(%d):%s block_til_ready() after, count=%d\n",
50402- __FILE__,__LINE__, tty->driver->name, port->count );
50403+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50404
50405 if (!retval)
50406 port->flags |= ASYNC_NORMAL_ACTIVE;
50407diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
50408index ce396ec..04a37be 100644
50409--- a/drivers/tty/sysrq.c
50410+++ b/drivers/tty/sysrq.c
50411@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
50412 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
50413 size_t count, loff_t *ppos)
50414 {
50415- if (count) {
50416+ if (count && capable(CAP_SYS_ADMIN)) {
50417 char c;
50418
50419 if (get_user(c, buf))
50420diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
50421index c74a00a..02cf211a 100644
50422--- a/drivers/tty/tty_io.c
50423+++ b/drivers/tty/tty_io.c
50424@@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
50425
50426 void tty_default_fops(struct file_operations *fops)
50427 {
50428- *fops = tty_fops;
50429+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
50430 }
50431
50432 /*
50433diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
50434index 6458e11..6cfc218 100644
50435--- a/drivers/tty/tty_ldisc.c
50436+++ b/drivers/tty/tty_ldisc.c
50437@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
50438 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50439 tty_ldiscs[disc] = new_ldisc;
50440 new_ldisc->num = disc;
50441- new_ldisc->refcount = 0;
50442+ atomic_set(&new_ldisc->refcount, 0);
50443 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50444
50445 return ret;
50446@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
50447 return -EINVAL;
50448
50449 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50450- if (tty_ldiscs[disc]->refcount)
50451+ if (atomic_read(&tty_ldiscs[disc]->refcount))
50452 ret = -EBUSY;
50453 else
50454 tty_ldiscs[disc] = NULL;
50455@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
50456 if (ldops) {
50457 ret = ERR_PTR(-EAGAIN);
50458 if (try_module_get(ldops->owner)) {
50459- ldops->refcount++;
50460+ atomic_inc(&ldops->refcount);
50461 ret = ldops;
50462 }
50463 }
50464@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
50465 unsigned long flags;
50466
50467 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50468- ldops->refcount--;
50469+ atomic_dec(&ldops->refcount);
50470 module_put(ldops->owner);
50471 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50472 }
50473diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
50474index c94d234..8210f2d 100644
50475--- a/drivers/tty/tty_port.c
50476+++ b/drivers/tty/tty_port.c
50477@@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
50478 unsigned long flags;
50479
50480 spin_lock_irqsave(&port->lock, flags);
50481- port->count = 0;
50482+ atomic_set(&port->count, 0);
50483 port->flags &= ~ASYNC_NORMAL_ACTIVE;
50484 tty = port->tty;
50485 if (tty)
50486@@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50487 /* The port lock protects the port counts */
50488 spin_lock_irqsave(&port->lock, flags);
50489 if (!tty_hung_up_p(filp))
50490- port->count--;
50491+ atomic_dec(&port->count);
50492 port->blocked_open++;
50493 spin_unlock_irqrestore(&port->lock, flags);
50494
50495@@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50496 we must not mess that up further */
50497 spin_lock_irqsave(&port->lock, flags);
50498 if (!tty_hung_up_p(filp))
50499- port->count++;
50500+ atomic_inc(&port->count);
50501 port->blocked_open--;
50502 if (retval == 0)
50503 port->flags |= ASYNC_NORMAL_ACTIVE;
50504@@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
50505 return 0;
50506 }
50507
50508- if (tty->count == 1 && port->count != 1) {
50509+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
50510 printk(KERN_WARNING
50511 "tty_port_close_start: tty->count = 1 port count = %d.\n",
50512- port->count);
50513- port->count = 1;
50514+ atomic_read(&port->count));
50515+ atomic_set(&port->count, 1);
50516 }
50517- if (--port->count < 0) {
50518+ if (atomic_dec_return(&port->count) < 0) {
50519 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
50520- port->count);
50521- port->count = 0;
50522+ atomic_read(&port->count));
50523+ atomic_set(&port->count, 0);
50524 }
50525
50526- if (port->count) {
50527+ if (atomic_read(&port->count)) {
50528 spin_unlock_irqrestore(&port->lock, flags);
50529 return 0;
50530 }
50531@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
50532 {
50533 spin_lock_irq(&port->lock);
50534 if (!tty_hung_up_p(filp))
50535- ++port->count;
50536+ atomic_inc(&port->count);
50537 spin_unlock_irq(&port->lock);
50538 tty_port_tty_set(port, tty);
50539
50540diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
50541index d0e3a44..5f8b754 100644
50542--- a/drivers/tty/vt/keyboard.c
50543+++ b/drivers/tty/vt/keyboard.c
50544@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
50545 kbd->kbdmode == VC_OFF) &&
50546 value != KVAL(K_SAK))
50547 return; /* SAK is allowed even in raw mode */
50548+
50549+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50550+ {
50551+ void *func = fn_handler[value];
50552+ if (func == fn_show_state || func == fn_show_ptregs ||
50553+ func == fn_show_mem)
50554+ return;
50555+ }
50556+#endif
50557+
50558 fn_handler[value](vc);
50559 }
50560
50561@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50562 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
50563 return -EFAULT;
50564
50565- if (!capable(CAP_SYS_TTY_CONFIG))
50566- perm = 0;
50567-
50568 switch (cmd) {
50569 case KDGKBENT:
50570 /* Ensure another thread doesn't free it under us */
50571@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50572 spin_unlock_irqrestore(&kbd_event_lock, flags);
50573 return put_user(val, &user_kbe->kb_value);
50574 case KDSKBENT:
50575+ if (!capable(CAP_SYS_TTY_CONFIG))
50576+ perm = 0;
50577+
50578 if (!perm)
50579 return -EPERM;
50580 if (!i && v == K_NOSUCHMAP) {
50581@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50582 int i, j, k;
50583 int ret;
50584
50585- if (!capable(CAP_SYS_TTY_CONFIG))
50586- perm = 0;
50587-
50588 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
50589 if (!kbs) {
50590 ret = -ENOMEM;
50591@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50592 kfree(kbs);
50593 return ((p && *p) ? -EOVERFLOW : 0);
50594 case KDSKBSENT:
50595+ if (!capable(CAP_SYS_TTY_CONFIG))
50596+ perm = 0;
50597+
50598 if (!perm) {
50599 ret = -EPERM;
50600 goto reterr;
50601diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
50602index f7beb6e..8c0bbd0 100644
50603--- a/drivers/uio/uio.c
50604+++ b/drivers/uio/uio.c
50605@@ -25,6 +25,7 @@
50606 #include <linux/kobject.h>
50607 #include <linux/cdev.h>
50608 #include <linux/uio_driver.h>
50609+#include <asm/local.h>
50610
50611 #define UIO_MAX_DEVICES (1U << MINORBITS)
50612
50613@@ -32,7 +33,7 @@ struct uio_device {
50614 struct module *owner;
50615 struct device *dev;
50616 int minor;
50617- atomic_t event;
50618+ atomic_unchecked_t event;
50619 struct fasync_struct *async_queue;
50620 wait_queue_head_t wait;
50621 struct uio_info *info;
50622@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
50623 struct device_attribute *attr, char *buf)
50624 {
50625 struct uio_device *idev = dev_get_drvdata(dev);
50626- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
50627+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
50628 }
50629 static DEVICE_ATTR_RO(event);
50630
50631@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
50632 {
50633 struct uio_device *idev = info->uio_dev;
50634
50635- atomic_inc(&idev->event);
50636+ atomic_inc_unchecked(&idev->event);
50637 wake_up_interruptible(&idev->wait);
50638 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
50639 }
50640@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
50641 }
50642
50643 listener->dev = idev;
50644- listener->event_count = atomic_read(&idev->event);
50645+ listener->event_count = atomic_read_unchecked(&idev->event);
50646 filep->private_data = listener;
50647
50648 if (idev->info->open) {
50649@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
50650 return -EIO;
50651
50652 poll_wait(filep, &idev->wait, wait);
50653- if (listener->event_count != atomic_read(&idev->event))
50654+ if (listener->event_count != atomic_read_unchecked(&idev->event))
50655 return POLLIN | POLLRDNORM;
50656 return 0;
50657 }
50658@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
50659 do {
50660 set_current_state(TASK_INTERRUPTIBLE);
50661
50662- event_count = atomic_read(&idev->event);
50663+ event_count = atomic_read_unchecked(&idev->event);
50664 if (event_count != listener->event_count) {
50665 if (copy_to_user(buf, &event_count, count))
50666 retval = -EFAULT;
50667@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
50668 static int uio_find_mem_index(struct vm_area_struct *vma)
50669 {
50670 struct uio_device *idev = vma->vm_private_data;
50671+ unsigned long size;
50672
50673 if (vma->vm_pgoff < MAX_UIO_MAPS) {
50674- if (idev->info->mem[vma->vm_pgoff].size == 0)
50675+ size = idev->info->mem[vma->vm_pgoff].size;
50676+ if (size == 0)
50677+ return -1;
50678+ if (vma->vm_end - vma->vm_start > size)
50679 return -1;
50680 return (int)vma->vm_pgoff;
50681 }
50682@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
50683 idev->owner = owner;
50684 idev->info = info;
50685 init_waitqueue_head(&idev->wait);
50686- atomic_set(&idev->event, 0);
50687+ atomic_set_unchecked(&idev->event, 0);
50688
50689 ret = uio_get_minor(idev);
50690 if (ret)
50691diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
50692index 8a7eb77..c00402f 100644
50693--- a/drivers/usb/atm/cxacru.c
50694+++ b/drivers/usb/atm/cxacru.c
50695@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
50696 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
50697 if (ret < 2)
50698 return -EINVAL;
50699- if (index < 0 || index > 0x7f)
50700+ if (index > 0x7f)
50701 return -EINVAL;
50702 pos += tmp;
50703
50704diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
50705index 25a7bfc..57f3cf5 100644
50706--- a/drivers/usb/atm/usbatm.c
50707+++ b/drivers/usb/atm/usbatm.c
50708@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50709 if (printk_ratelimit())
50710 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
50711 __func__, vpi, vci);
50712- atomic_inc(&vcc->stats->rx_err);
50713+ atomic_inc_unchecked(&vcc->stats->rx_err);
50714 return;
50715 }
50716
50717@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50718 if (length > ATM_MAX_AAL5_PDU) {
50719 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
50720 __func__, length, vcc);
50721- atomic_inc(&vcc->stats->rx_err);
50722+ atomic_inc_unchecked(&vcc->stats->rx_err);
50723 goto out;
50724 }
50725
50726@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50727 if (sarb->len < pdu_length) {
50728 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
50729 __func__, pdu_length, sarb->len, vcc);
50730- atomic_inc(&vcc->stats->rx_err);
50731+ atomic_inc_unchecked(&vcc->stats->rx_err);
50732 goto out;
50733 }
50734
50735 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
50736 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
50737 __func__, vcc);
50738- atomic_inc(&vcc->stats->rx_err);
50739+ atomic_inc_unchecked(&vcc->stats->rx_err);
50740 goto out;
50741 }
50742
50743@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50744 if (printk_ratelimit())
50745 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
50746 __func__, length);
50747- atomic_inc(&vcc->stats->rx_drop);
50748+ atomic_inc_unchecked(&vcc->stats->rx_drop);
50749 goto out;
50750 }
50751
50752@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50753
50754 vcc->push(vcc, skb);
50755
50756- atomic_inc(&vcc->stats->rx);
50757+ atomic_inc_unchecked(&vcc->stats->rx);
50758 out:
50759 skb_trim(sarb, 0);
50760 }
50761@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
50762 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
50763
50764 usbatm_pop(vcc, skb);
50765- atomic_inc(&vcc->stats->tx);
50766+ atomic_inc_unchecked(&vcc->stats->tx);
50767
50768 skb = skb_dequeue(&instance->sndqueue);
50769 }
50770@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
50771 if (!left--)
50772 return sprintf(page,
50773 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
50774- atomic_read(&atm_dev->stats.aal5.tx),
50775- atomic_read(&atm_dev->stats.aal5.tx_err),
50776- atomic_read(&atm_dev->stats.aal5.rx),
50777- atomic_read(&atm_dev->stats.aal5.rx_err),
50778- atomic_read(&atm_dev->stats.aal5.rx_drop));
50779+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
50780+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
50781+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
50782+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
50783+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
50784
50785 if (!left--) {
50786 if (instance->disconnected)
50787diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
50788index 2a3bbdf..91d72cf 100644
50789--- a/drivers/usb/core/devices.c
50790+++ b/drivers/usb/core/devices.c
50791@@ -126,7 +126,7 @@ static const char format_endpt[] =
50792 * time it gets called.
50793 */
50794 static struct device_connect_event {
50795- atomic_t count;
50796+ atomic_unchecked_t count;
50797 wait_queue_head_t wait;
50798 } device_event = {
50799 .count = ATOMIC_INIT(1),
50800@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
50801
50802 void usbfs_conn_disc_event(void)
50803 {
50804- atomic_add(2, &device_event.count);
50805+ atomic_add_unchecked(2, &device_event.count);
50806 wake_up(&device_event.wait);
50807 }
50808
50809@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
50810
50811 poll_wait(file, &device_event.wait, wait);
50812
50813- event_count = atomic_read(&device_event.count);
50814+ event_count = atomic_read_unchecked(&device_event.count);
50815 if (file->f_version != event_count) {
50816 file->f_version = event_count;
50817 return POLLIN | POLLRDNORM;
50818diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
50819index 967152a..16fa2e5 100644
50820--- a/drivers/usb/core/devio.c
50821+++ b/drivers/usb/core/devio.c
50822@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50823 struct dev_state *ps = file->private_data;
50824 struct usb_device *dev = ps->dev;
50825 ssize_t ret = 0;
50826- unsigned len;
50827+ size_t len;
50828 loff_t pos;
50829 int i;
50830
50831@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50832 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
50833 struct usb_config_descriptor *config =
50834 (struct usb_config_descriptor *)dev->rawdescriptors[i];
50835- unsigned int length = le16_to_cpu(config->wTotalLength);
50836+ size_t length = le16_to_cpu(config->wTotalLength);
50837
50838 if (*ppos < pos + length) {
50839
50840 /* The descriptor may claim to be longer than it
50841 * really is. Here is the actual allocated length. */
50842- unsigned alloclen =
50843+ size_t alloclen =
50844 le16_to_cpu(dev->config[i].desc.wTotalLength);
50845
50846- len = length - (*ppos - pos);
50847+ len = length + pos - *ppos;
50848 if (len > nbytes)
50849 len = nbytes;
50850
50851 /* Simply don't write (skip over) unallocated parts */
50852 if (alloclen > (*ppos - pos)) {
50853- alloclen -= (*ppos - pos);
50854+ alloclen = alloclen + pos - *ppos;
50855 if (copy_to_user(buf,
50856 dev->rawdescriptors[i] + (*ppos - pos),
50857 min(len, alloclen))) {
50858diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
50859index 6bffb8c..b404e8b 100644
50860--- a/drivers/usb/core/hcd.c
50861+++ b/drivers/usb/core/hcd.c
50862@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
50863 */
50864 usb_get_urb(urb);
50865 atomic_inc(&urb->use_count);
50866- atomic_inc(&urb->dev->urbnum);
50867+ atomic_inc_unchecked(&urb->dev->urbnum);
50868 usbmon_urb_submit(&hcd->self, urb);
50869
50870 /* NOTE requirements on root-hub callers (usbfs and the hub
50871@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
50872 urb->hcpriv = NULL;
50873 INIT_LIST_HEAD(&urb->urb_list);
50874 atomic_dec(&urb->use_count);
50875- atomic_dec(&urb->dev->urbnum);
50876+ atomic_dec_unchecked(&urb->dev->urbnum);
50877 if (atomic_read(&urb->reject))
50878 wake_up(&usb_kill_urb_queue);
50879 usb_put_urb(urb);
50880diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
50881index bd9dc35..c04ae2f 100644
50882--- a/drivers/usb/core/hub.c
50883+++ b/drivers/usb/core/hub.c
50884@@ -27,6 +27,7 @@
50885 #include <linux/freezer.h>
50886 #include <linux/random.h>
50887 #include <linux/pm_qos.h>
50888+#include <linux/grsecurity.h>
50889
50890 #include <asm/uaccess.h>
50891 #include <asm/byteorder.h>
50892@@ -4463,6 +4464,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
50893 goto done;
50894 return;
50895 }
50896+
50897+ if (gr_handle_new_usb())
50898+ goto done;
50899+
50900 if (hub_is_superspeed(hub->hdev))
50901 unit_load = 150;
50902 else
50903diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
50904index bb31597..6c5ef8b 100644
50905--- a/drivers/usb/core/message.c
50906+++ b/drivers/usb/core/message.c
50907@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
50908 * Return: If successful, the number of bytes transferred. Otherwise, a negative
50909 * error number.
50910 */
50911-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
50912+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
50913 __u8 requesttype, __u16 value, __u16 index, void *data,
50914 __u16 size, int timeout)
50915 {
50916@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
50917 * If successful, 0. Otherwise a negative error number. The number of actual
50918 * bytes transferred will be stored in the @actual_length paramater.
50919 */
50920-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
50921+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
50922 void *data, int len, int *actual_length, int timeout)
50923 {
50924 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
50925@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
50926 * bytes transferred will be stored in the @actual_length paramater.
50927 *
50928 */
50929-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
50930+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
50931 void *data, int len, int *actual_length, int timeout)
50932 {
50933 struct urb *urb;
50934diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
50935index 52a97ad..e73330f 100644
50936--- a/drivers/usb/core/sysfs.c
50937+++ b/drivers/usb/core/sysfs.c
50938@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
50939 struct usb_device *udev;
50940
50941 udev = to_usb_device(dev);
50942- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
50943+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
50944 }
50945 static DEVICE_ATTR_RO(urbnum);
50946
50947diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
50948index 4d11449..f4ccabf 100644
50949--- a/drivers/usb/core/usb.c
50950+++ b/drivers/usb/core/usb.c
50951@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
50952 set_dev_node(&dev->dev, dev_to_node(bus->controller));
50953 dev->state = USB_STATE_ATTACHED;
50954 dev->lpm_disable_count = 1;
50955- atomic_set(&dev->urbnum, 0);
50956+ atomic_set_unchecked(&dev->urbnum, 0);
50957
50958 INIT_LIST_HEAD(&dev->ep0.urb_list);
50959 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
50960diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
50961index 02e44fc..3c4fe64 100644
50962--- a/drivers/usb/dwc3/gadget.c
50963+++ b/drivers/usb/dwc3/gadget.c
50964@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
50965 if (!usb_endpoint_xfer_isoc(desc))
50966 return 0;
50967
50968- memset(&trb_link, 0, sizeof(trb_link));
50969-
50970 /* Link TRB for ISOC. The HWO bit is never reset */
50971 trb_st_hw = &dep->trb_pool[0];
50972
50973diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
50974index 8cfc319..4868255 100644
50975--- a/drivers/usb/early/ehci-dbgp.c
50976+++ b/drivers/usb/early/ehci-dbgp.c
50977@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
50978
50979 #ifdef CONFIG_KGDB
50980 static struct kgdb_io kgdbdbgp_io_ops;
50981-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
50982+static struct kgdb_io kgdbdbgp_io_ops_console;
50983+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
50984 #else
50985 #define dbgp_kgdb_mode (0)
50986 #endif
50987@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
50988 .write_char = kgdbdbgp_write_char,
50989 };
50990
50991+static struct kgdb_io kgdbdbgp_io_ops_console = {
50992+ .name = "kgdbdbgp",
50993+ .read_char = kgdbdbgp_read_char,
50994+ .write_char = kgdbdbgp_write_char,
50995+ .is_console = 1
50996+};
50997+
50998 static int kgdbdbgp_wait_time;
50999
51000 static int __init kgdbdbgp_parse_config(char *str)
51001@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51002 ptr++;
51003 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51004 }
51005- kgdb_register_io_module(&kgdbdbgp_io_ops);
51006- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51007+ if (early_dbgp_console.index != -1)
51008+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51009+ else
51010+ kgdb_register_io_module(&kgdbdbgp_io_ops);
51011
51012 return 0;
51013 }
51014diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51015index b369292..9f3ba40 100644
51016--- a/drivers/usb/gadget/u_serial.c
51017+++ b/drivers/usb/gadget/u_serial.c
51018@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51019 spin_lock_irq(&port->port_lock);
51020
51021 /* already open? Great. */
51022- if (port->port.count) {
51023+ if (atomic_read(&port->port.count)) {
51024 status = 0;
51025- port->port.count++;
51026+ atomic_inc(&port->port.count);
51027
51028 /* currently opening/closing? wait ... */
51029 } else if (port->openclose) {
51030@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51031 tty->driver_data = port;
51032 port->port.tty = tty;
51033
51034- port->port.count = 1;
51035+ atomic_set(&port->port.count, 1);
51036 port->openclose = false;
51037
51038 /* if connected, start the I/O stream */
51039@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51040
51041 spin_lock_irq(&port->port_lock);
51042
51043- if (port->port.count != 1) {
51044- if (port->port.count == 0)
51045+ if (atomic_read(&port->port.count) != 1) {
51046+ if (atomic_read(&port->port.count) == 0)
51047 WARN_ON(1);
51048 else
51049- --port->port.count;
51050+ atomic_dec(&port->port.count);
51051 goto exit;
51052 }
51053
51054@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51055 * and sleep if necessary
51056 */
51057 port->openclose = true;
51058- port->port.count = 0;
51059+ atomic_set(&port->port.count, 0);
51060
51061 gser = port->port_usb;
51062 if (gser && gser->disconnect)
51063@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51064 int cond;
51065
51066 spin_lock_irq(&port->port_lock);
51067- cond = (port->port.count == 0) && !port->openclose;
51068+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51069 spin_unlock_irq(&port->port_lock);
51070 return cond;
51071 }
51072@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51073 /* if it's already open, start I/O ... and notify the serial
51074 * protocol about open/close status (connect/disconnect).
51075 */
51076- if (port->port.count) {
51077+ if (atomic_read(&port->port.count)) {
51078 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51079 gs_start_io(port);
51080 if (gser->connect)
51081@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51082
51083 port->port_usb = NULL;
51084 gser->ioport = NULL;
51085- if (port->port.count > 0 || port->openclose) {
51086+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
51087 wake_up_interruptible(&port->drain_wait);
51088 if (port->port.tty)
51089 tty_hangup(port->port.tty);
51090@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51091
51092 /* finally, free any unused/unusable I/O buffers */
51093 spin_lock_irqsave(&port->port_lock, flags);
51094- if (port->port.count == 0 && !port->openclose)
51095+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
51096 gs_buf_free(&port->port_write_buf);
51097 gs_free_requests(gser->out, &port->read_pool, NULL);
51098 gs_free_requests(gser->out, &port->read_queue, NULL);
51099diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51100index 835fc08..f8b22bf 100644
51101--- a/drivers/usb/host/ehci-hub.c
51102+++ b/drivers/usb/host/ehci-hub.c
51103@@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
51104 urb->transfer_flags = URB_DIR_IN;
51105 usb_get_urb(urb);
51106 atomic_inc(&urb->use_count);
51107- atomic_inc(&urb->dev->urbnum);
51108+ atomic_inc_unchecked(&urb->dev->urbnum);
51109 urb->setup_dma = dma_map_single(
51110 hcd->self.controller,
51111 urb->setup_packet,
51112@@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51113 urb->status = -EINPROGRESS;
51114 usb_get_urb(urb);
51115 atomic_inc(&urb->use_count);
51116- atomic_inc(&urb->dev->urbnum);
51117+ atomic_inc_unchecked(&urb->dev->urbnum);
51118 retval = submit_single_step_set_feature(hcd, urb, 0);
51119 if (!retval && !wait_for_completion_timeout(&done,
51120 msecs_to_jiffies(2000))) {
51121diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51122index ba6a5d6..f88f7f3 100644
51123--- a/drivers/usb/misc/appledisplay.c
51124+++ b/drivers/usb/misc/appledisplay.c
51125@@ -83,7 +83,7 @@ struct appledisplay {
51126 spinlock_t lock;
51127 };
51128
51129-static atomic_t count_displays = ATOMIC_INIT(0);
51130+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51131 static struct workqueue_struct *wq;
51132
51133 static void appledisplay_complete(struct urb *urb)
51134@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51135
51136 /* Register backlight device */
51137 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
51138- atomic_inc_return(&count_displays) - 1);
51139+ atomic_inc_return_unchecked(&count_displays) - 1);
51140 memset(&props, 0, sizeof(struct backlight_properties));
51141 props.type = BACKLIGHT_RAW;
51142 props.max_brightness = 0xff;
51143diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
51144index c69bb50..215ef37 100644
51145--- a/drivers/usb/serial/console.c
51146+++ b/drivers/usb/serial/console.c
51147@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
51148
51149 info->port = port;
51150
51151- ++port->port.count;
51152+ atomic_inc(&port->port.count);
51153 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
51154 if (serial->type->set_termios) {
51155 /*
51156@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
51157 }
51158 /* Now that any required fake tty operations are completed restore
51159 * the tty port count */
51160- --port->port.count;
51161+ atomic_dec(&port->port.count);
51162 /* The console is special in terms of closing the device so
51163 * indicate this port is now acting as a system console. */
51164 port->port.console = 1;
51165@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
51166 free_tty:
51167 kfree(tty);
51168 reset_open_count:
51169- port->port.count = 0;
51170+ atomic_set(&port->port.count, 0);
51171 usb_autopm_put_interface(serial->interface);
51172 error_get_interface:
51173 usb_serial_put(serial);
51174@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
51175 static void usb_console_write(struct console *co,
51176 const char *buf, unsigned count)
51177 {
51178- static struct usbcons_info *info = &usbcons_info;
51179+ struct usbcons_info *info = &usbcons_info;
51180 struct usb_serial_port *port = info->port;
51181 struct usb_serial *serial;
51182 int retval = -ENODEV;
51183diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
51184index 75f70f0..d467e1a 100644
51185--- a/drivers/usb/storage/usb.h
51186+++ b/drivers/usb/storage/usb.h
51187@@ -63,7 +63,7 @@ struct us_unusual_dev {
51188 __u8 useProtocol;
51189 __u8 useTransport;
51190 int (*initFunction)(struct us_data *);
51191-};
51192+} __do_const;
51193
51194
51195 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
51196diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
51197index e614f02..3fd60e2 100644
51198--- a/drivers/usb/wusbcore/wa-hc.h
51199+++ b/drivers/usb/wusbcore/wa-hc.h
51200@@ -225,7 +225,7 @@ struct wahc {
51201 spinlock_t xfer_list_lock;
51202 struct work_struct xfer_enqueue_work;
51203 struct work_struct xfer_error_work;
51204- atomic_t xfer_id_count;
51205+ atomic_unchecked_t xfer_id_count;
51206
51207 kernel_ulong_t quirks;
51208 };
51209@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
51210 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
51211 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
51212 wa->dto_in_use = 0;
51213- atomic_set(&wa->xfer_id_count, 1);
51214+ atomic_set_unchecked(&wa->xfer_id_count, 1);
51215 }
51216
51217 /**
51218diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
51219index ed5abe8..7036400 100644
51220--- a/drivers/usb/wusbcore/wa-xfer.c
51221+++ b/drivers/usb/wusbcore/wa-xfer.c
51222@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
51223 */
51224 static void wa_xfer_id_init(struct wa_xfer *xfer)
51225 {
51226- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
51227+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
51228 }
51229
51230 /* Return the xfer's ID. */
51231diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
51232index 1eab4ac..e21efc9 100644
51233--- a/drivers/vfio/vfio.c
51234+++ b/drivers/vfio/vfio.c
51235@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
51236 return 0;
51237
51238 /* TODO Prevent device auto probing */
51239- WARN("Device %s added to live group %d!\n", dev_name(dev),
51240+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
51241 iommu_group_id(group->iommu_group));
51242
51243 return 0;
51244diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
51245index 5174eba..451e6bc 100644
51246--- a/drivers/vhost/vringh.c
51247+++ b/drivers/vhost/vringh.c
51248@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
51249 /* Userspace access helpers: in this case, addresses are really userspace. */
51250 static inline int getu16_user(u16 *val, const u16 *p)
51251 {
51252- return get_user(*val, (__force u16 __user *)p);
51253+ return get_user(*val, (u16 __force_user *)p);
51254 }
51255
51256 static inline int putu16_user(u16 *p, u16 val)
51257 {
51258- return put_user(val, (__force u16 __user *)p);
51259+ return put_user(val, (u16 __force_user *)p);
51260 }
51261
51262 static inline int copydesc_user(void *dst, const void *src, size_t len)
51263 {
51264- return copy_from_user(dst, (__force void __user *)src, len) ?
51265+ return copy_from_user(dst, (void __force_user *)src, len) ?
51266 -EFAULT : 0;
51267 }
51268
51269@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
51270 const struct vring_used_elem *src,
51271 unsigned int num)
51272 {
51273- return copy_to_user((__force void __user *)dst, src,
51274+ return copy_to_user((void __force_user *)dst, src,
51275 sizeof(*dst) * num) ? -EFAULT : 0;
51276 }
51277
51278 static inline int xfer_from_user(void *src, void *dst, size_t len)
51279 {
51280- return copy_from_user(dst, (__force void __user *)src, len) ?
51281+ return copy_from_user(dst, (void __force_user *)src, len) ?
51282 -EFAULT : 0;
51283 }
51284
51285 static inline int xfer_to_user(void *dst, void *src, size_t len)
51286 {
51287- return copy_to_user((__force void __user *)dst, src, len) ?
51288+ return copy_to_user((void __force_user *)dst, src, len) ?
51289 -EFAULT : 0;
51290 }
51291
51292@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
51293 vrh->last_used_idx = 0;
51294 vrh->vring.num = num;
51295 /* vring expects kernel addresses, but only used via accessors. */
51296- vrh->vring.desc = (__force struct vring_desc *)desc;
51297- vrh->vring.avail = (__force struct vring_avail *)avail;
51298- vrh->vring.used = (__force struct vring_used *)used;
51299+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
51300+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
51301+ vrh->vring.used = (__force_kernel struct vring_used *)used;
51302 return 0;
51303 }
51304 EXPORT_SYMBOL(vringh_init_user);
51305@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
51306
51307 static inline int putu16_kern(u16 *p, u16 val)
51308 {
51309- ACCESS_ONCE(*p) = val;
51310+ ACCESS_ONCE_RW(*p) = val;
51311 return 0;
51312 }
51313
51314diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
51315index 1b0b233..6f34c2c 100644
51316--- a/drivers/video/arcfb.c
51317+++ b/drivers/video/arcfb.c
51318@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
51319 return -ENOSPC;
51320
51321 err = 0;
51322- if ((count + p) > fbmemlength) {
51323+ if (count > (fbmemlength - p)) {
51324 count = fbmemlength - p;
51325 err = -ENOSPC;
51326 }
51327diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
51328index 12ca031..84a8a74 100644
51329--- a/drivers/video/aty/aty128fb.c
51330+++ b/drivers/video/aty/aty128fb.c
51331@@ -149,7 +149,7 @@ enum {
51332 };
51333
51334 /* Must match above enum */
51335-static char * const r128_family[] = {
51336+static const char * const r128_family[] = {
51337 "AGP",
51338 "PCI",
51339 "PRO AGP",
51340diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
51341index 28fafbf..ae91651 100644
51342--- a/drivers/video/aty/atyfb_base.c
51343+++ b/drivers/video/aty/atyfb_base.c
51344@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
51345 par->accel_flags = var->accel_flags; /* hack */
51346
51347 if (var->accel_flags) {
51348- info->fbops->fb_sync = atyfb_sync;
51349+ pax_open_kernel();
51350+ *(void **)&info->fbops->fb_sync = atyfb_sync;
51351+ pax_close_kernel();
51352 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51353 } else {
51354- info->fbops->fb_sync = NULL;
51355+ pax_open_kernel();
51356+ *(void **)&info->fbops->fb_sync = NULL;
51357+ pax_close_kernel();
51358 info->flags |= FBINFO_HWACCEL_DISABLED;
51359 }
51360
51361diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
51362index 95ec042..e6affdd 100644
51363--- a/drivers/video/aty/mach64_cursor.c
51364+++ b/drivers/video/aty/mach64_cursor.c
51365@@ -7,6 +7,7 @@
51366 #include <linux/string.h>
51367
51368 #include <asm/io.h>
51369+#include <asm/pgtable.h>
51370
51371 #ifdef __sparc__
51372 #include <asm/fbio.h>
51373@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
51374 info->sprite.buf_align = 16; /* and 64 lines tall. */
51375 info->sprite.flags = FB_PIXMAP_IO;
51376
51377- info->fbops->fb_cursor = atyfb_cursor;
51378+ pax_open_kernel();
51379+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
51380+ pax_close_kernel();
51381
51382 return 0;
51383 }
51384diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
51385index 7592cc2..92feb56 100644
51386--- a/drivers/video/backlight/kb3886_bl.c
51387+++ b/drivers/video/backlight/kb3886_bl.c
51388@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
51389 static unsigned long kb3886bl_flags;
51390 #define KB3886BL_SUSPENDED 0x01
51391
51392-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
51393+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
51394 {
51395 .ident = "Sahara Touch-iT",
51396 .matches = {
51397diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
51398index 900aa4e..6d49418 100644
51399--- a/drivers/video/fb_defio.c
51400+++ b/drivers/video/fb_defio.c
51401@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
51402
51403 BUG_ON(!fbdefio);
51404 mutex_init(&fbdefio->lock);
51405- info->fbops->fb_mmap = fb_deferred_io_mmap;
51406+ pax_open_kernel();
51407+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
51408+ pax_close_kernel();
51409 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
51410 INIT_LIST_HEAD(&fbdefio->pagelist);
51411 if (fbdefio->delay == 0) /* set a default of 1 s */
51412@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
51413 page->mapping = NULL;
51414 }
51415
51416- info->fbops->fb_mmap = NULL;
51417+ *(void **)&info->fbops->fb_mmap = NULL;
51418 mutex_destroy(&fbdefio->lock);
51419 }
51420 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
51421diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
51422index 010d191..7b8235a 100644
51423--- a/drivers/video/fbmem.c
51424+++ b/drivers/video/fbmem.c
51425@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51426 image->dx += image->width + 8;
51427 }
51428 } else if (rotate == FB_ROTATE_UD) {
51429- for (x = 0; x < num && image->dx >= 0; x++) {
51430+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
51431 info->fbops->fb_imageblit(info, image);
51432 image->dx -= image->width + 8;
51433 }
51434@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51435 image->dy += image->height + 8;
51436 }
51437 } else if (rotate == FB_ROTATE_CCW) {
51438- for (x = 0; x < num && image->dy >= 0; x++) {
51439+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
51440 info->fbops->fb_imageblit(info, image);
51441 image->dy -= image->height + 8;
51442 }
51443@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
51444 return -EFAULT;
51445 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
51446 return -EINVAL;
51447- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
51448+ if (con2fb.framebuffer >= FB_MAX)
51449 return -EINVAL;
51450 if (!registered_fb[con2fb.framebuffer])
51451 request_module("fb%d", con2fb.framebuffer);
51452@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
51453 __u32 data;
51454 int err;
51455
51456- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
51457+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
51458
51459 data = (__u32) (unsigned long) fix->smem_start;
51460 err |= put_user(data, &fix32->smem_start);
51461diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
51462index 130708f..cdac1a9 100644
51463--- a/drivers/video/hyperv_fb.c
51464+++ b/drivers/video/hyperv_fb.c
51465@@ -233,7 +233,7 @@ static uint screen_fb_size;
51466 static inline int synthvid_send(struct hv_device *hdev,
51467 struct synthvid_msg *msg)
51468 {
51469- static atomic64_t request_id = ATOMIC64_INIT(0);
51470+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
51471 int ret;
51472
51473 msg->pipe_hdr.type = PIPE_MSG_DATA;
51474@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
51475
51476 ret = vmbus_sendpacket(hdev->channel, msg,
51477 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
51478- atomic64_inc_return(&request_id),
51479+ atomic64_inc_return_unchecked(&request_id),
51480 VM_PKT_DATA_INBAND, 0);
51481
51482 if (ret)
51483diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
51484index 7672d2e..b56437f 100644
51485--- a/drivers/video/i810/i810_accel.c
51486+++ b/drivers/video/i810/i810_accel.c
51487@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
51488 }
51489 }
51490 printk("ringbuffer lockup!!!\n");
51491+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
51492 i810_report_error(mmio);
51493 par->dev_flags |= LOCKUP;
51494 info->pixmap.scan_align = 1;
51495diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
51496index 3c14e43..2630570 100644
51497--- a/drivers/video/logo/logo_linux_clut224.ppm
51498+++ b/drivers/video/logo/logo_linux_clut224.ppm
51499@@ -2,1603 +2,1123 @@ P3
51500 # Standard 224-color Linux logo
51501 80 80
51502 255
51503- 0 0 0 0 0 0 0 0 0 0 0 0
51504- 0 0 0 0 0 0 0 0 0 0 0 0
51505- 0 0 0 0 0 0 0 0 0 0 0 0
51506- 0 0 0 0 0 0 0 0 0 0 0 0
51507- 0 0 0 0 0 0 0 0 0 0 0 0
51508- 0 0 0 0 0 0 0 0 0 0 0 0
51509- 0 0 0 0 0 0 0 0 0 0 0 0
51510- 0 0 0 0 0 0 0 0 0 0 0 0
51511- 0 0 0 0 0 0 0 0 0 0 0 0
51512- 6 6 6 6 6 6 10 10 10 10 10 10
51513- 10 10 10 6 6 6 6 6 6 6 6 6
51514- 0 0 0 0 0 0 0 0 0 0 0 0
51515- 0 0 0 0 0 0 0 0 0 0 0 0
51516- 0 0 0 0 0 0 0 0 0 0 0 0
51517- 0 0 0 0 0 0 0 0 0 0 0 0
51518- 0 0 0 0 0 0 0 0 0 0 0 0
51519- 0 0 0 0 0 0 0 0 0 0 0 0
51520- 0 0 0 0 0 0 0 0 0 0 0 0
51521- 0 0 0 0 0 0 0 0 0 0 0 0
51522- 0 0 0 0 0 0 0 0 0 0 0 0
51523- 0 0 0 0 0 0 0 0 0 0 0 0
51524- 0 0 0 0 0 0 0 0 0 0 0 0
51525- 0 0 0 0 0 0 0 0 0 0 0 0
51526- 0 0 0 0 0 0 0 0 0 0 0 0
51527- 0 0 0 0 0 0 0 0 0 0 0 0
51528- 0 0 0 0 0 0 0 0 0 0 0 0
51529- 0 0 0 0 0 0 0 0 0 0 0 0
51530- 0 0 0 0 0 0 0 0 0 0 0 0
51531- 0 0 0 6 6 6 10 10 10 14 14 14
51532- 22 22 22 26 26 26 30 30 30 34 34 34
51533- 30 30 30 30 30 30 26 26 26 18 18 18
51534- 14 14 14 10 10 10 6 6 6 0 0 0
51535- 0 0 0 0 0 0 0 0 0 0 0 0
51536- 0 0 0 0 0 0 0 0 0 0 0 0
51537- 0 0 0 0 0 0 0 0 0 0 0 0
51538- 0 0 0 0 0 0 0 0 0 0 0 0
51539- 0 0 0 0 0 0 0 0 0 0 0 0
51540- 0 0 0 0 0 0 0 0 0 0 0 0
51541- 0 0 0 0 0 0 0 0 0 0 0 0
51542- 0 0 0 0 0 0 0 0 0 0 0 0
51543- 0 0 0 0 0 0 0 0 0 0 0 0
51544- 0 0 0 0 0 1 0 0 1 0 0 0
51545- 0 0 0 0 0 0 0 0 0 0 0 0
51546- 0 0 0 0 0 0 0 0 0 0 0 0
51547- 0 0 0 0 0 0 0 0 0 0 0 0
51548- 0 0 0 0 0 0 0 0 0 0 0 0
51549- 0 0 0 0 0 0 0 0 0 0 0 0
51550- 0 0 0 0 0 0 0 0 0 0 0 0
51551- 6 6 6 14 14 14 26 26 26 42 42 42
51552- 54 54 54 66 66 66 78 78 78 78 78 78
51553- 78 78 78 74 74 74 66 66 66 54 54 54
51554- 42 42 42 26 26 26 18 18 18 10 10 10
51555- 6 6 6 0 0 0 0 0 0 0 0 0
51556- 0 0 0 0 0 0 0 0 0 0 0 0
51557- 0 0 0 0 0 0 0 0 0 0 0 0
51558- 0 0 0 0 0 0 0 0 0 0 0 0
51559- 0 0 0 0 0 0 0 0 0 0 0 0
51560- 0 0 0 0 0 0 0 0 0 0 0 0
51561- 0 0 0 0 0 0 0 0 0 0 0 0
51562- 0 0 0 0 0 0 0 0 0 0 0 0
51563- 0 0 0 0 0 0 0 0 0 0 0 0
51564- 0 0 1 0 0 0 0 0 0 0 0 0
51565- 0 0 0 0 0 0 0 0 0 0 0 0
51566- 0 0 0 0 0 0 0 0 0 0 0 0
51567- 0 0 0 0 0 0 0 0 0 0 0 0
51568- 0 0 0 0 0 0 0 0 0 0 0 0
51569- 0 0 0 0 0 0 0 0 0 0 0 0
51570- 0 0 0 0 0 0 0 0 0 10 10 10
51571- 22 22 22 42 42 42 66 66 66 86 86 86
51572- 66 66 66 38 38 38 38 38 38 22 22 22
51573- 26 26 26 34 34 34 54 54 54 66 66 66
51574- 86 86 86 70 70 70 46 46 46 26 26 26
51575- 14 14 14 6 6 6 0 0 0 0 0 0
51576- 0 0 0 0 0 0 0 0 0 0 0 0
51577- 0 0 0 0 0 0 0 0 0 0 0 0
51578- 0 0 0 0 0 0 0 0 0 0 0 0
51579- 0 0 0 0 0 0 0 0 0 0 0 0
51580- 0 0 0 0 0 0 0 0 0 0 0 0
51581- 0 0 0 0 0 0 0 0 0 0 0 0
51582- 0 0 0 0 0 0 0 0 0 0 0 0
51583- 0 0 0 0 0 0 0 0 0 0 0 0
51584- 0 0 1 0 0 1 0 0 1 0 0 0
51585- 0 0 0 0 0 0 0 0 0 0 0 0
51586- 0 0 0 0 0 0 0 0 0 0 0 0
51587- 0 0 0 0 0 0 0 0 0 0 0 0
51588- 0 0 0 0 0 0 0 0 0 0 0 0
51589- 0 0 0 0 0 0 0 0 0 0 0 0
51590- 0 0 0 0 0 0 10 10 10 26 26 26
51591- 50 50 50 82 82 82 58 58 58 6 6 6
51592- 2 2 6 2 2 6 2 2 6 2 2 6
51593- 2 2 6 2 2 6 2 2 6 2 2 6
51594- 6 6 6 54 54 54 86 86 86 66 66 66
51595- 38 38 38 18 18 18 6 6 6 0 0 0
51596- 0 0 0 0 0 0 0 0 0 0 0 0
51597- 0 0 0 0 0 0 0 0 0 0 0 0
51598- 0 0 0 0 0 0 0 0 0 0 0 0
51599- 0 0 0 0 0 0 0 0 0 0 0 0
51600- 0 0 0 0 0 0 0 0 0 0 0 0
51601- 0 0 0 0 0 0 0 0 0 0 0 0
51602- 0 0 0 0 0 0 0 0 0 0 0 0
51603- 0 0 0 0 0 0 0 0 0 0 0 0
51604- 0 0 0 0 0 0 0 0 0 0 0 0
51605- 0 0 0 0 0 0 0 0 0 0 0 0
51606- 0 0 0 0 0 0 0 0 0 0 0 0
51607- 0 0 0 0 0 0 0 0 0 0 0 0
51608- 0 0 0 0 0 0 0 0 0 0 0 0
51609- 0 0 0 0 0 0 0 0 0 0 0 0
51610- 0 0 0 6 6 6 22 22 22 50 50 50
51611- 78 78 78 34 34 34 2 2 6 2 2 6
51612- 2 2 6 2 2 6 2 2 6 2 2 6
51613- 2 2 6 2 2 6 2 2 6 2 2 6
51614- 2 2 6 2 2 6 6 6 6 70 70 70
51615- 78 78 78 46 46 46 22 22 22 6 6 6
51616- 0 0 0 0 0 0 0 0 0 0 0 0
51617- 0 0 0 0 0 0 0 0 0 0 0 0
51618- 0 0 0 0 0 0 0 0 0 0 0 0
51619- 0 0 0 0 0 0 0 0 0 0 0 0
51620- 0 0 0 0 0 0 0 0 0 0 0 0
51621- 0 0 0 0 0 0 0 0 0 0 0 0
51622- 0 0 0 0 0 0 0 0 0 0 0 0
51623- 0 0 0 0 0 0 0 0 0 0 0 0
51624- 0 0 1 0 0 1 0 0 1 0 0 0
51625- 0 0 0 0 0 0 0 0 0 0 0 0
51626- 0 0 0 0 0 0 0 0 0 0 0 0
51627- 0 0 0 0 0 0 0 0 0 0 0 0
51628- 0 0 0 0 0 0 0 0 0 0 0 0
51629- 0 0 0 0 0 0 0 0 0 0 0 0
51630- 6 6 6 18 18 18 42 42 42 82 82 82
51631- 26 26 26 2 2 6 2 2 6 2 2 6
51632- 2 2 6 2 2 6 2 2 6 2 2 6
51633- 2 2 6 2 2 6 2 2 6 14 14 14
51634- 46 46 46 34 34 34 6 6 6 2 2 6
51635- 42 42 42 78 78 78 42 42 42 18 18 18
51636- 6 6 6 0 0 0 0 0 0 0 0 0
51637- 0 0 0 0 0 0 0 0 0 0 0 0
51638- 0 0 0 0 0 0 0 0 0 0 0 0
51639- 0 0 0 0 0 0 0 0 0 0 0 0
51640- 0 0 0 0 0 0 0 0 0 0 0 0
51641- 0 0 0 0 0 0 0 0 0 0 0 0
51642- 0 0 0 0 0 0 0 0 0 0 0 0
51643- 0 0 0 0 0 0 0 0 0 0 0 0
51644- 0 0 1 0 0 0 0 0 1 0 0 0
51645- 0 0 0 0 0 0 0 0 0 0 0 0
51646- 0 0 0 0 0 0 0 0 0 0 0 0
51647- 0 0 0 0 0 0 0 0 0 0 0 0
51648- 0 0 0 0 0 0 0 0 0 0 0 0
51649- 0 0 0 0 0 0 0 0 0 0 0 0
51650- 10 10 10 30 30 30 66 66 66 58 58 58
51651- 2 2 6 2 2 6 2 2 6 2 2 6
51652- 2 2 6 2 2 6 2 2 6 2 2 6
51653- 2 2 6 2 2 6 2 2 6 26 26 26
51654- 86 86 86 101 101 101 46 46 46 10 10 10
51655- 2 2 6 58 58 58 70 70 70 34 34 34
51656- 10 10 10 0 0 0 0 0 0 0 0 0
51657- 0 0 0 0 0 0 0 0 0 0 0 0
51658- 0 0 0 0 0 0 0 0 0 0 0 0
51659- 0 0 0 0 0 0 0 0 0 0 0 0
51660- 0 0 0 0 0 0 0 0 0 0 0 0
51661- 0 0 0 0 0 0 0 0 0 0 0 0
51662- 0 0 0 0 0 0 0 0 0 0 0 0
51663- 0 0 0 0 0 0 0 0 0 0 0 0
51664- 0 0 1 0 0 1 0 0 1 0 0 0
51665- 0 0 0 0 0 0 0 0 0 0 0 0
51666- 0 0 0 0 0 0 0 0 0 0 0 0
51667- 0 0 0 0 0 0 0 0 0 0 0 0
51668- 0 0 0 0 0 0 0 0 0 0 0 0
51669- 0 0 0 0 0 0 0 0 0 0 0 0
51670- 14 14 14 42 42 42 86 86 86 10 10 10
51671- 2 2 6 2 2 6 2 2 6 2 2 6
51672- 2 2 6 2 2 6 2 2 6 2 2 6
51673- 2 2 6 2 2 6 2 2 6 30 30 30
51674- 94 94 94 94 94 94 58 58 58 26 26 26
51675- 2 2 6 6 6 6 78 78 78 54 54 54
51676- 22 22 22 6 6 6 0 0 0 0 0 0
51677- 0 0 0 0 0 0 0 0 0 0 0 0
51678- 0 0 0 0 0 0 0 0 0 0 0 0
51679- 0 0 0 0 0 0 0 0 0 0 0 0
51680- 0 0 0 0 0 0 0 0 0 0 0 0
51681- 0 0 0 0 0 0 0 0 0 0 0 0
51682- 0 0 0 0 0 0 0 0 0 0 0 0
51683- 0 0 0 0 0 0 0 0 0 0 0 0
51684- 0 0 0 0 0 0 0 0 0 0 0 0
51685- 0 0 0 0 0 0 0 0 0 0 0 0
51686- 0 0 0 0 0 0 0 0 0 0 0 0
51687- 0 0 0 0 0 0 0 0 0 0 0 0
51688- 0 0 0 0 0 0 0 0 0 0 0 0
51689- 0 0 0 0 0 0 0 0 0 6 6 6
51690- 22 22 22 62 62 62 62 62 62 2 2 6
51691- 2 2 6 2 2 6 2 2 6 2 2 6
51692- 2 2 6 2 2 6 2 2 6 2 2 6
51693- 2 2 6 2 2 6 2 2 6 26 26 26
51694- 54 54 54 38 38 38 18 18 18 10 10 10
51695- 2 2 6 2 2 6 34 34 34 82 82 82
51696- 38 38 38 14 14 14 0 0 0 0 0 0
51697- 0 0 0 0 0 0 0 0 0 0 0 0
51698- 0 0 0 0 0 0 0 0 0 0 0 0
51699- 0 0 0 0 0 0 0 0 0 0 0 0
51700- 0 0 0 0 0 0 0 0 0 0 0 0
51701- 0 0 0 0 0 0 0 0 0 0 0 0
51702- 0 0 0 0 0 0 0 0 0 0 0 0
51703- 0 0 0 0 0 0 0 0 0 0 0 0
51704- 0 0 0 0 0 1 0 0 1 0 0 0
51705- 0 0 0 0 0 0 0 0 0 0 0 0
51706- 0 0 0 0 0 0 0 0 0 0 0 0
51707- 0 0 0 0 0 0 0 0 0 0 0 0
51708- 0 0 0 0 0 0 0 0 0 0 0 0
51709- 0 0 0 0 0 0 0 0 0 6 6 6
51710- 30 30 30 78 78 78 30 30 30 2 2 6
51711- 2 2 6 2 2 6 2 2 6 2 2 6
51712- 2 2 6 2 2 6 2 2 6 2 2 6
51713- 2 2 6 2 2 6 2 2 6 10 10 10
51714- 10 10 10 2 2 6 2 2 6 2 2 6
51715- 2 2 6 2 2 6 2 2 6 78 78 78
51716- 50 50 50 18 18 18 6 6 6 0 0 0
51717- 0 0 0 0 0 0 0 0 0 0 0 0
51718- 0 0 0 0 0 0 0 0 0 0 0 0
51719- 0 0 0 0 0 0 0 0 0 0 0 0
51720- 0 0 0 0 0 0 0 0 0 0 0 0
51721- 0 0 0 0 0 0 0 0 0 0 0 0
51722- 0 0 0 0 0 0 0 0 0 0 0 0
51723- 0 0 0 0 0 0 0 0 0 0 0 0
51724- 0 0 1 0 0 0 0 0 0 0 0 0
51725- 0 0 0 0 0 0 0 0 0 0 0 0
51726- 0 0 0 0 0 0 0 0 0 0 0 0
51727- 0 0 0 0 0 0 0 0 0 0 0 0
51728- 0 0 0 0 0 0 0 0 0 0 0 0
51729- 0 0 0 0 0 0 0 0 0 10 10 10
51730- 38 38 38 86 86 86 14 14 14 2 2 6
51731- 2 2 6 2 2 6 2 2 6 2 2 6
51732- 2 2 6 2 2 6 2 2 6 2 2 6
51733- 2 2 6 2 2 6 2 2 6 2 2 6
51734- 2 2 6 2 2 6 2 2 6 2 2 6
51735- 2 2 6 2 2 6 2 2 6 54 54 54
51736- 66 66 66 26 26 26 6 6 6 0 0 0
51737- 0 0 0 0 0 0 0 0 0 0 0 0
51738- 0 0 0 0 0 0 0 0 0 0 0 0
51739- 0 0 0 0 0 0 0 0 0 0 0 0
51740- 0 0 0 0 0 0 0 0 0 0 0 0
51741- 0 0 0 0 0 0 0 0 0 0 0 0
51742- 0 0 0 0 0 0 0 0 0 0 0 0
51743- 0 0 0 0 0 0 0 0 0 0 0 0
51744- 0 0 0 0 0 1 0 0 1 0 0 0
51745- 0 0 0 0 0 0 0 0 0 0 0 0
51746- 0 0 0 0 0 0 0 0 0 0 0 0
51747- 0 0 0 0 0 0 0 0 0 0 0 0
51748- 0 0 0 0 0 0 0 0 0 0 0 0
51749- 0 0 0 0 0 0 0 0 0 14 14 14
51750- 42 42 42 82 82 82 2 2 6 2 2 6
51751- 2 2 6 6 6 6 10 10 10 2 2 6
51752- 2 2 6 2 2 6 2 2 6 2 2 6
51753- 2 2 6 2 2 6 2 2 6 6 6 6
51754- 14 14 14 10 10 10 2 2 6 2 2 6
51755- 2 2 6 2 2 6 2 2 6 18 18 18
51756- 82 82 82 34 34 34 10 10 10 0 0 0
51757- 0 0 0 0 0 0 0 0 0 0 0 0
51758- 0 0 0 0 0 0 0 0 0 0 0 0
51759- 0 0 0 0 0 0 0 0 0 0 0 0
51760- 0 0 0 0 0 0 0 0 0 0 0 0
51761- 0 0 0 0 0 0 0 0 0 0 0 0
51762- 0 0 0 0 0 0 0 0 0 0 0 0
51763- 0 0 0 0 0 0 0 0 0 0 0 0
51764- 0 0 1 0 0 0 0 0 0 0 0 0
51765- 0 0 0 0 0 0 0 0 0 0 0 0
51766- 0 0 0 0 0 0 0 0 0 0 0 0
51767- 0 0 0 0 0 0 0 0 0 0 0 0
51768- 0 0 0 0 0 0 0 0 0 0 0 0
51769- 0 0 0 0 0 0 0 0 0 14 14 14
51770- 46 46 46 86 86 86 2 2 6 2 2 6
51771- 6 6 6 6 6 6 22 22 22 34 34 34
51772- 6 6 6 2 2 6 2 2 6 2 2 6
51773- 2 2 6 2 2 6 18 18 18 34 34 34
51774- 10 10 10 50 50 50 22 22 22 2 2 6
51775- 2 2 6 2 2 6 2 2 6 10 10 10
51776- 86 86 86 42 42 42 14 14 14 0 0 0
51777- 0 0 0 0 0 0 0 0 0 0 0 0
51778- 0 0 0 0 0 0 0 0 0 0 0 0
51779- 0 0 0 0 0 0 0 0 0 0 0 0
51780- 0 0 0 0 0 0 0 0 0 0 0 0
51781- 0 0 0 0 0 0 0 0 0 0 0 0
51782- 0 0 0 0 0 0 0 0 0 0 0 0
51783- 0 0 0 0 0 0 0 0 0 0 0 0
51784- 0 0 1 0 0 1 0 0 1 0 0 0
51785- 0 0 0 0 0 0 0 0 0 0 0 0
51786- 0 0 0 0 0 0 0 0 0 0 0 0
51787- 0 0 0 0 0 0 0 0 0 0 0 0
51788- 0 0 0 0 0 0 0 0 0 0 0 0
51789- 0 0 0 0 0 0 0 0 0 14 14 14
51790- 46 46 46 86 86 86 2 2 6 2 2 6
51791- 38 38 38 116 116 116 94 94 94 22 22 22
51792- 22 22 22 2 2 6 2 2 6 2 2 6
51793- 14 14 14 86 86 86 138 138 138 162 162 162
51794-154 154 154 38 38 38 26 26 26 6 6 6
51795- 2 2 6 2 2 6 2 2 6 2 2 6
51796- 86 86 86 46 46 46 14 14 14 0 0 0
51797- 0 0 0 0 0 0 0 0 0 0 0 0
51798- 0 0 0 0 0 0 0 0 0 0 0 0
51799- 0 0 0 0 0 0 0 0 0 0 0 0
51800- 0 0 0 0 0 0 0 0 0 0 0 0
51801- 0 0 0 0 0 0 0 0 0 0 0 0
51802- 0 0 0 0 0 0 0 0 0 0 0 0
51803- 0 0 0 0 0 0 0 0 0 0 0 0
51804- 0 0 0 0 0 0 0 0 0 0 0 0
51805- 0 0 0 0 0 0 0 0 0 0 0 0
51806- 0 0 0 0 0 0 0 0 0 0 0 0
51807- 0 0 0 0 0 0 0 0 0 0 0 0
51808- 0 0 0 0 0 0 0 0 0 0 0 0
51809- 0 0 0 0 0 0 0 0 0 14 14 14
51810- 46 46 46 86 86 86 2 2 6 14 14 14
51811-134 134 134 198 198 198 195 195 195 116 116 116
51812- 10 10 10 2 2 6 2 2 6 6 6 6
51813-101 98 89 187 187 187 210 210 210 218 218 218
51814-214 214 214 134 134 134 14 14 14 6 6 6
51815- 2 2 6 2 2 6 2 2 6 2 2 6
51816- 86 86 86 50 50 50 18 18 18 6 6 6
51817- 0 0 0 0 0 0 0 0 0 0 0 0
51818- 0 0 0 0 0 0 0 0 0 0 0 0
51819- 0 0 0 0 0 0 0 0 0 0 0 0
51820- 0 0 0 0 0 0 0 0 0 0 0 0
51821- 0 0 0 0 0 0 0 0 0 0 0 0
51822- 0 0 0 0 0 0 0 0 0 0 0 0
51823- 0 0 0 0 0 0 0 0 1 0 0 0
51824- 0 0 1 0 0 1 0 0 1 0 0 0
51825- 0 0 0 0 0 0 0 0 0 0 0 0
51826- 0 0 0 0 0 0 0 0 0 0 0 0
51827- 0 0 0 0 0 0 0 0 0 0 0 0
51828- 0 0 0 0 0 0 0 0 0 0 0 0
51829- 0 0 0 0 0 0 0 0 0 14 14 14
51830- 46 46 46 86 86 86 2 2 6 54 54 54
51831-218 218 218 195 195 195 226 226 226 246 246 246
51832- 58 58 58 2 2 6 2 2 6 30 30 30
51833-210 210 210 253 253 253 174 174 174 123 123 123
51834-221 221 221 234 234 234 74 74 74 2 2 6
51835- 2 2 6 2 2 6 2 2 6 2 2 6
51836- 70 70 70 58 58 58 22 22 22 6 6 6
51837- 0 0 0 0 0 0 0 0 0 0 0 0
51838- 0 0 0 0 0 0 0 0 0 0 0 0
51839- 0 0 0 0 0 0 0 0 0 0 0 0
51840- 0 0 0 0 0 0 0 0 0 0 0 0
51841- 0 0 0 0 0 0 0 0 0 0 0 0
51842- 0 0 0 0 0 0 0 0 0 0 0 0
51843- 0 0 0 0 0 0 0 0 0 0 0 0
51844- 0 0 0 0 0 0 0 0 0 0 0 0
51845- 0 0 0 0 0 0 0 0 0 0 0 0
51846- 0 0 0 0 0 0 0 0 0 0 0 0
51847- 0 0 0 0 0 0 0 0 0 0 0 0
51848- 0 0 0 0 0 0 0 0 0 0 0 0
51849- 0 0 0 0 0 0 0 0 0 14 14 14
51850- 46 46 46 82 82 82 2 2 6 106 106 106
51851-170 170 170 26 26 26 86 86 86 226 226 226
51852-123 123 123 10 10 10 14 14 14 46 46 46
51853-231 231 231 190 190 190 6 6 6 70 70 70
51854- 90 90 90 238 238 238 158 158 158 2 2 6
51855- 2 2 6 2 2 6 2 2 6 2 2 6
51856- 70 70 70 58 58 58 22 22 22 6 6 6
51857- 0 0 0 0 0 0 0 0 0 0 0 0
51858- 0 0 0 0 0 0 0 0 0 0 0 0
51859- 0 0 0 0 0 0 0 0 0 0 0 0
51860- 0 0 0 0 0 0 0 0 0 0 0 0
51861- 0 0 0 0 0 0 0 0 0 0 0 0
51862- 0 0 0 0 0 0 0 0 0 0 0 0
51863- 0 0 0 0 0 0 0 0 1 0 0 0
51864- 0 0 1 0 0 1 0 0 1 0 0 0
51865- 0 0 0 0 0 0 0 0 0 0 0 0
51866- 0 0 0 0 0 0 0 0 0 0 0 0
51867- 0 0 0 0 0 0 0 0 0 0 0 0
51868- 0 0 0 0 0 0 0 0 0 0 0 0
51869- 0 0 0 0 0 0 0 0 0 14 14 14
51870- 42 42 42 86 86 86 6 6 6 116 116 116
51871-106 106 106 6 6 6 70 70 70 149 149 149
51872-128 128 128 18 18 18 38 38 38 54 54 54
51873-221 221 221 106 106 106 2 2 6 14 14 14
51874- 46 46 46 190 190 190 198 198 198 2 2 6
51875- 2 2 6 2 2 6 2 2 6 2 2 6
51876- 74 74 74 62 62 62 22 22 22 6 6 6
51877- 0 0 0 0 0 0 0 0 0 0 0 0
51878- 0 0 0 0 0 0 0 0 0 0 0 0
51879- 0 0 0 0 0 0 0 0 0 0 0 0
51880- 0 0 0 0 0 0 0 0 0 0 0 0
51881- 0 0 0 0 0 0 0 0 0 0 0 0
51882- 0 0 0 0 0 0 0 0 0 0 0 0
51883- 0 0 0 0 0 0 0 0 1 0 0 0
51884- 0 0 1 0 0 0 0 0 1 0 0 0
51885- 0 0 0 0 0 0 0 0 0 0 0 0
51886- 0 0 0 0 0 0 0 0 0 0 0 0
51887- 0 0 0 0 0 0 0 0 0 0 0 0
51888- 0 0 0 0 0 0 0 0 0 0 0 0
51889- 0 0 0 0 0 0 0 0 0 14 14 14
51890- 42 42 42 94 94 94 14 14 14 101 101 101
51891-128 128 128 2 2 6 18 18 18 116 116 116
51892-118 98 46 121 92 8 121 92 8 98 78 10
51893-162 162 162 106 106 106 2 2 6 2 2 6
51894- 2 2 6 195 195 195 195 195 195 6 6 6
51895- 2 2 6 2 2 6 2 2 6 2 2 6
51896- 74 74 74 62 62 62 22 22 22 6 6 6
51897- 0 0 0 0 0 0 0 0 0 0 0 0
51898- 0 0 0 0 0 0 0 0 0 0 0 0
51899- 0 0 0 0 0 0 0 0 0 0 0 0
51900- 0 0 0 0 0 0 0 0 0 0 0 0
51901- 0 0 0 0 0 0 0 0 0 0 0 0
51902- 0 0 0 0 0 0 0 0 0 0 0 0
51903- 0 0 0 0 0 0 0 0 1 0 0 1
51904- 0 0 1 0 0 0 0 0 1 0 0 0
51905- 0 0 0 0 0 0 0 0 0 0 0 0
51906- 0 0 0 0 0 0 0 0 0 0 0 0
51907- 0 0 0 0 0 0 0 0 0 0 0 0
51908- 0 0 0 0 0 0 0 0 0 0 0 0
51909- 0 0 0 0 0 0 0 0 0 10 10 10
51910- 38 38 38 90 90 90 14 14 14 58 58 58
51911-210 210 210 26 26 26 54 38 6 154 114 10
51912-226 170 11 236 186 11 225 175 15 184 144 12
51913-215 174 15 175 146 61 37 26 9 2 2 6
51914- 70 70 70 246 246 246 138 138 138 2 2 6
51915- 2 2 6 2 2 6 2 2 6 2 2 6
51916- 70 70 70 66 66 66 26 26 26 6 6 6
51917- 0 0 0 0 0 0 0 0 0 0 0 0
51918- 0 0 0 0 0 0 0 0 0 0 0 0
51919- 0 0 0 0 0 0 0 0 0 0 0 0
51920- 0 0 0 0 0 0 0 0 0 0 0 0
51921- 0 0 0 0 0 0 0 0 0 0 0 0
51922- 0 0 0 0 0 0 0 0 0 0 0 0
51923- 0 0 0 0 0 0 0 0 0 0 0 0
51924- 0 0 0 0 0 0 0 0 0 0 0 0
51925- 0 0 0 0 0 0 0 0 0 0 0 0
51926- 0 0 0 0 0 0 0 0 0 0 0 0
51927- 0 0 0 0 0 0 0 0 0 0 0 0
51928- 0 0 0 0 0 0 0 0 0 0 0 0
51929- 0 0 0 0 0 0 0 0 0 10 10 10
51930- 38 38 38 86 86 86 14 14 14 10 10 10
51931-195 195 195 188 164 115 192 133 9 225 175 15
51932-239 182 13 234 190 10 232 195 16 232 200 30
51933-245 207 45 241 208 19 232 195 16 184 144 12
51934-218 194 134 211 206 186 42 42 42 2 2 6
51935- 2 2 6 2 2 6 2 2 6 2 2 6
51936- 50 50 50 74 74 74 30 30 30 6 6 6
51937- 0 0 0 0 0 0 0 0 0 0 0 0
51938- 0 0 0 0 0 0 0 0 0 0 0 0
51939- 0 0 0 0 0 0 0 0 0 0 0 0
51940- 0 0 0 0 0 0 0 0 0 0 0 0
51941- 0 0 0 0 0 0 0 0 0 0 0 0
51942- 0 0 0 0 0 0 0 0 0 0 0 0
51943- 0 0 0 0 0 0 0 0 0 0 0 0
51944- 0 0 0 0 0 0 0 0 0 0 0 0
51945- 0 0 0 0 0 0 0 0 0 0 0 0
51946- 0 0 0 0 0 0 0 0 0 0 0 0
51947- 0 0 0 0 0 0 0 0 0 0 0 0
51948- 0 0 0 0 0 0 0 0 0 0 0 0
51949- 0 0 0 0 0 0 0 0 0 10 10 10
51950- 34 34 34 86 86 86 14 14 14 2 2 6
51951-121 87 25 192 133 9 219 162 10 239 182 13
51952-236 186 11 232 195 16 241 208 19 244 214 54
51953-246 218 60 246 218 38 246 215 20 241 208 19
51954-241 208 19 226 184 13 121 87 25 2 2 6
51955- 2 2 6 2 2 6 2 2 6 2 2 6
51956- 50 50 50 82 82 82 34 34 34 10 10 10
51957- 0 0 0 0 0 0 0 0 0 0 0 0
51958- 0 0 0 0 0 0 0 0 0 0 0 0
51959- 0 0 0 0 0 0 0 0 0 0 0 0
51960- 0 0 0 0 0 0 0 0 0 0 0 0
51961- 0 0 0 0 0 0 0 0 0 0 0 0
51962- 0 0 0 0 0 0 0 0 0 0 0 0
51963- 0 0 0 0 0 0 0 0 0 0 0 0
51964- 0 0 0 0 0 0 0 0 0 0 0 0
51965- 0 0 0 0 0 0 0 0 0 0 0 0
51966- 0 0 0 0 0 0 0 0 0 0 0 0
51967- 0 0 0 0 0 0 0 0 0 0 0 0
51968- 0 0 0 0 0 0 0 0 0 0 0 0
51969- 0 0 0 0 0 0 0 0 0 10 10 10
51970- 34 34 34 82 82 82 30 30 30 61 42 6
51971-180 123 7 206 145 10 230 174 11 239 182 13
51972-234 190 10 238 202 15 241 208 19 246 218 74
51973-246 218 38 246 215 20 246 215 20 246 215 20
51974-226 184 13 215 174 15 184 144 12 6 6 6
51975- 2 2 6 2 2 6 2 2 6 2 2 6
51976- 26 26 26 94 94 94 42 42 42 14 14 14
51977- 0 0 0 0 0 0 0 0 0 0 0 0
51978- 0 0 0 0 0 0 0 0 0 0 0 0
51979- 0 0 0 0 0 0 0 0 0 0 0 0
51980- 0 0 0 0 0 0 0 0 0 0 0 0
51981- 0 0 0 0 0 0 0 0 0 0 0 0
51982- 0 0 0 0 0 0 0 0 0 0 0 0
51983- 0 0 0 0 0 0 0 0 0 0 0 0
51984- 0 0 0 0 0 0 0 0 0 0 0 0
51985- 0 0 0 0 0 0 0 0 0 0 0 0
51986- 0 0 0 0 0 0 0 0 0 0 0 0
51987- 0 0 0 0 0 0 0 0 0 0 0 0
51988- 0 0 0 0 0 0 0 0 0 0 0 0
51989- 0 0 0 0 0 0 0 0 0 10 10 10
51990- 30 30 30 78 78 78 50 50 50 104 69 6
51991-192 133 9 216 158 10 236 178 12 236 186 11
51992-232 195 16 241 208 19 244 214 54 245 215 43
51993-246 215 20 246 215 20 241 208 19 198 155 10
51994-200 144 11 216 158 10 156 118 10 2 2 6
51995- 2 2 6 2 2 6 2 2 6 2 2 6
51996- 6 6 6 90 90 90 54 54 54 18 18 18
51997- 6 6 6 0 0 0 0 0 0 0 0 0
51998- 0 0 0 0 0 0 0 0 0 0 0 0
51999- 0 0 0 0 0 0 0 0 0 0 0 0
52000- 0 0 0 0 0 0 0 0 0 0 0 0
52001- 0 0 0 0 0 0 0 0 0 0 0 0
52002- 0 0 0 0 0 0 0 0 0 0 0 0
52003- 0 0 0 0 0 0 0 0 0 0 0 0
52004- 0 0 0 0 0 0 0 0 0 0 0 0
52005- 0 0 0 0 0 0 0 0 0 0 0 0
52006- 0 0 0 0 0 0 0 0 0 0 0 0
52007- 0 0 0 0 0 0 0 0 0 0 0 0
52008- 0 0 0 0 0 0 0 0 0 0 0 0
52009- 0 0 0 0 0 0 0 0 0 10 10 10
52010- 30 30 30 78 78 78 46 46 46 22 22 22
52011-137 92 6 210 162 10 239 182 13 238 190 10
52012-238 202 15 241 208 19 246 215 20 246 215 20
52013-241 208 19 203 166 17 185 133 11 210 150 10
52014-216 158 10 210 150 10 102 78 10 2 2 6
52015- 6 6 6 54 54 54 14 14 14 2 2 6
52016- 2 2 6 62 62 62 74 74 74 30 30 30
52017- 10 10 10 0 0 0 0 0 0 0 0 0
52018- 0 0 0 0 0 0 0 0 0 0 0 0
52019- 0 0 0 0 0 0 0 0 0 0 0 0
52020- 0 0 0 0 0 0 0 0 0 0 0 0
52021- 0 0 0 0 0 0 0 0 0 0 0 0
52022- 0 0 0 0 0 0 0 0 0 0 0 0
52023- 0 0 0 0 0 0 0 0 0 0 0 0
52024- 0 0 0 0 0 0 0 0 0 0 0 0
52025- 0 0 0 0 0 0 0 0 0 0 0 0
52026- 0 0 0 0 0 0 0 0 0 0 0 0
52027- 0 0 0 0 0 0 0 0 0 0 0 0
52028- 0 0 0 0 0 0 0 0 0 0 0 0
52029- 0 0 0 0 0 0 0 0 0 10 10 10
52030- 34 34 34 78 78 78 50 50 50 6 6 6
52031- 94 70 30 139 102 15 190 146 13 226 184 13
52032-232 200 30 232 195 16 215 174 15 190 146 13
52033-168 122 10 192 133 9 210 150 10 213 154 11
52034-202 150 34 182 157 106 101 98 89 2 2 6
52035- 2 2 6 78 78 78 116 116 116 58 58 58
52036- 2 2 6 22 22 22 90 90 90 46 46 46
52037- 18 18 18 6 6 6 0 0 0 0 0 0
52038- 0 0 0 0 0 0 0 0 0 0 0 0
52039- 0 0 0 0 0 0 0 0 0 0 0 0
52040- 0 0 0 0 0 0 0 0 0 0 0 0
52041- 0 0 0 0 0 0 0 0 0 0 0 0
52042- 0 0 0 0 0 0 0 0 0 0 0 0
52043- 0 0 0 0 0 0 0 0 0 0 0 0
52044- 0 0 0 0 0 0 0 0 0 0 0 0
52045- 0 0 0 0 0 0 0 0 0 0 0 0
52046- 0 0 0 0 0 0 0 0 0 0 0 0
52047- 0 0 0 0 0 0 0 0 0 0 0 0
52048- 0 0 0 0 0 0 0 0 0 0 0 0
52049- 0 0 0 0 0 0 0 0 0 10 10 10
52050- 38 38 38 86 86 86 50 50 50 6 6 6
52051-128 128 128 174 154 114 156 107 11 168 122 10
52052-198 155 10 184 144 12 197 138 11 200 144 11
52053-206 145 10 206 145 10 197 138 11 188 164 115
52054-195 195 195 198 198 198 174 174 174 14 14 14
52055- 2 2 6 22 22 22 116 116 116 116 116 116
52056- 22 22 22 2 2 6 74 74 74 70 70 70
52057- 30 30 30 10 10 10 0 0 0 0 0 0
52058- 0 0 0 0 0 0 0 0 0 0 0 0
52059- 0 0 0 0 0 0 0 0 0 0 0 0
52060- 0 0 0 0 0 0 0 0 0 0 0 0
52061- 0 0 0 0 0 0 0 0 0 0 0 0
52062- 0 0 0 0 0 0 0 0 0 0 0 0
52063- 0 0 0 0 0 0 0 0 0 0 0 0
52064- 0 0 0 0 0 0 0 0 0 0 0 0
52065- 0 0 0 0 0 0 0 0 0 0 0 0
52066- 0 0 0 0 0 0 0 0 0 0 0 0
52067- 0 0 0 0 0 0 0 0 0 0 0 0
52068- 0 0 0 0 0 0 0 0 0 0 0 0
52069- 0 0 0 0 0 0 6 6 6 18 18 18
52070- 50 50 50 101 101 101 26 26 26 10 10 10
52071-138 138 138 190 190 190 174 154 114 156 107 11
52072-197 138 11 200 144 11 197 138 11 192 133 9
52073-180 123 7 190 142 34 190 178 144 187 187 187
52074-202 202 202 221 221 221 214 214 214 66 66 66
52075- 2 2 6 2 2 6 50 50 50 62 62 62
52076- 6 6 6 2 2 6 10 10 10 90 90 90
52077- 50 50 50 18 18 18 6 6 6 0 0 0
52078- 0 0 0 0 0 0 0 0 0 0 0 0
52079- 0 0 0 0 0 0 0 0 0 0 0 0
52080- 0 0 0 0 0 0 0 0 0 0 0 0
52081- 0 0 0 0 0 0 0 0 0 0 0 0
52082- 0 0 0 0 0 0 0 0 0 0 0 0
52083- 0 0 0 0 0 0 0 0 0 0 0 0
52084- 0 0 0 0 0 0 0 0 0 0 0 0
52085- 0 0 0 0 0 0 0 0 0 0 0 0
52086- 0 0 0 0 0 0 0 0 0 0 0 0
52087- 0 0 0 0 0 0 0 0 0 0 0 0
52088- 0 0 0 0 0 0 0 0 0 0 0 0
52089- 0 0 0 0 0 0 10 10 10 34 34 34
52090- 74 74 74 74 74 74 2 2 6 6 6 6
52091-144 144 144 198 198 198 190 190 190 178 166 146
52092-154 121 60 156 107 11 156 107 11 168 124 44
52093-174 154 114 187 187 187 190 190 190 210 210 210
52094-246 246 246 253 253 253 253 253 253 182 182 182
52095- 6 6 6 2 2 6 2 2 6 2 2 6
52096- 2 2 6 2 2 6 2 2 6 62 62 62
52097- 74 74 74 34 34 34 14 14 14 0 0 0
52098- 0 0 0 0 0 0 0 0 0 0 0 0
52099- 0 0 0 0 0 0 0 0 0 0 0 0
52100- 0 0 0 0 0 0 0 0 0 0 0 0
52101- 0 0 0 0 0 0 0 0 0 0 0 0
52102- 0 0 0 0 0 0 0 0 0 0 0 0
52103- 0 0 0 0 0 0 0 0 0 0 0 0
52104- 0 0 0 0 0 0 0 0 0 0 0 0
52105- 0 0 0 0 0 0 0 0 0 0 0 0
52106- 0 0 0 0 0 0 0 0 0 0 0 0
52107- 0 0 0 0 0 0 0 0 0 0 0 0
52108- 0 0 0 0 0 0 0 0 0 0 0 0
52109- 0 0 0 10 10 10 22 22 22 54 54 54
52110- 94 94 94 18 18 18 2 2 6 46 46 46
52111-234 234 234 221 221 221 190 190 190 190 190 190
52112-190 190 190 187 187 187 187 187 187 190 190 190
52113-190 190 190 195 195 195 214 214 214 242 242 242
52114-253 253 253 253 253 253 253 253 253 253 253 253
52115- 82 82 82 2 2 6 2 2 6 2 2 6
52116- 2 2 6 2 2 6 2 2 6 14 14 14
52117- 86 86 86 54 54 54 22 22 22 6 6 6
52118- 0 0 0 0 0 0 0 0 0 0 0 0
52119- 0 0 0 0 0 0 0 0 0 0 0 0
52120- 0 0 0 0 0 0 0 0 0 0 0 0
52121- 0 0 0 0 0 0 0 0 0 0 0 0
52122- 0 0 0 0 0 0 0 0 0 0 0 0
52123- 0 0 0 0 0 0 0 0 0 0 0 0
52124- 0 0 0 0 0 0 0 0 0 0 0 0
52125- 0 0 0 0 0 0 0 0 0 0 0 0
52126- 0 0 0 0 0 0 0 0 0 0 0 0
52127- 0 0 0 0 0 0 0 0 0 0 0 0
52128- 0 0 0 0 0 0 0 0 0 0 0 0
52129- 6 6 6 18 18 18 46 46 46 90 90 90
52130- 46 46 46 18 18 18 6 6 6 182 182 182
52131-253 253 253 246 246 246 206 206 206 190 190 190
52132-190 190 190 190 190 190 190 190 190 190 190 190
52133-206 206 206 231 231 231 250 250 250 253 253 253
52134-253 253 253 253 253 253 253 253 253 253 253 253
52135-202 202 202 14 14 14 2 2 6 2 2 6
52136- 2 2 6 2 2 6 2 2 6 2 2 6
52137- 42 42 42 86 86 86 42 42 42 18 18 18
52138- 6 6 6 0 0 0 0 0 0 0 0 0
52139- 0 0 0 0 0 0 0 0 0 0 0 0
52140- 0 0 0 0 0 0 0 0 0 0 0 0
52141- 0 0 0 0 0 0 0 0 0 0 0 0
52142- 0 0 0 0 0 0 0 0 0 0 0 0
52143- 0 0 0 0 0 0 0 0 0 0 0 0
52144- 0 0 0 0 0 0 0 0 0 0 0 0
52145- 0 0 0 0 0 0 0 0 0 0 0 0
52146- 0 0 0 0 0 0 0 0 0 0 0 0
52147- 0 0 0 0 0 0 0 0 0 0 0 0
52148- 0 0 0 0 0 0 0 0 0 6 6 6
52149- 14 14 14 38 38 38 74 74 74 66 66 66
52150- 2 2 6 6 6 6 90 90 90 250 250 250
52151-253 253 253 253 253 253 238 238 238 198 198 198
52152-190 190 190 190 190 190 195 195 195 221 221 221
52153-246 246 246 253 253 253 253 253 253 253 253 253
52154-253 253 253 253 253 253 253 253 253 253 253 253
52155-253 253 253 82 82 82 2 2 6 2 2 6
52156- 2 2 6 2 2 6 2 2 6 2 2 6
52157- 2 2 6 78 78 78 70 70 70 34 34 34
52158- 14 14 14 6 6 6 0 0 0 0 0 0
52159- 0 0 0 0 0 0 0 0 0 0 0 0
52160- 0 0 0 0 0 0 0 0 0 0 0 0
52161- 0 0 0 0 0 0 0 0 0 0 0 0
52162- 0 0 0 0 0 0 0 0 0 0 0 0
52163- 0 0 0 0 0 0 0 0 0 0 0 0
52164- 0 0 0 0 0 0 0 0 0 0 0 0
52165- 0 0 0 0 0 0 0 0 0 0 0 0
52166- 0 0 0 0 0 0 0 0 0 0 0 0
52167- 0 0 0 0 0 0 0 0 0 0 0 0
52168- 0 0 0 0 0 0 0 0 0 14 14 14
52169- 34 34 34 66 66 66 78 78 78 6 6 6
52170- 2 2 6 18 18 18 218 218 218 253 253 253
52171-253 253 253 253 253 253 253 253 253 246 246 246
52172-226 226 226 231 231 231 246 246 246 253 253 253
52173-253 253 253 253 253 253 253 253 253 253 253 253
52174-253 253 253 253 253 253 253 253 253 253 253 253
52175-253 253 253 178 178 178 2 2 6 2 2 6
52176- 2 2 6 2 2 6 2 2 6 2 2 6
52177- 2 2 6 18 18 18 90 90 90 62 62 62
52178- 30 30 30 10 10 10 0 0 0 0 0 0
52179- 0 0 0 0 0 0 0 0 0 0 0 0
52180- 0 0 0 0 0 0 0 0 0 0 0 0
52181- 0 0 0 0 0 0 0 0 0 0 0 0
52182- 0 0 0 0 0 0 0 0 0 0 0 0
52183- 0 0 0 0 0 0 0 0 0 0 0 0
52184- 0 0 0 0 0 0 0 0 0 0 0 0
52185- 0 0 0 0 0 0 0 0 0 0 0 0
52186- 0 0 0 0 0 0 0 0 0 0 0 0
52187- 0 0 0 0 0 0 0 0 0 0 0 0
52188- 0 0 0 0 0 0 10 10 10 26 26 26
52189- 58 58 58 90 90 90 18 18 18 2 2 6
52190- 2 2 6 110 110 110 253 253 253 253 253 253
52191-253 253 253 253 253 253 253 253 253 253 253 253
52192-250 250 250 253 253 253 253 253 253 253 253 253
52193-253 253 253 253 253 253 253 253 253 253 253 253
52194-253 253 253 253 253 253 253 253 253 253 253 253
52195-253 253 253 231 231 231 18 18 18 2 2 6
52196- 2 2 6 2 2 6 2 2 6 2 2 6
52197- 2 2 6 2 2 6 18 18 18 94 94 94
52198- 54 54 54 26 26 26 10 10 10 0 0 0
52199- 0 0 0 0 0 0 0 0 0 0 0 0
52200- 0 0 0 0 0 0 0 0 0 0 0 0
52201- 0 0 0 0 0 0 0 0 0 0 0 0
52202- 0 0 0 0 0 0 0 0 0 0 0 0
52203- 0 0 0 0 0 0 0 0 0 0 0 0
52204- 0 0 0 0 0 0 0 0 0 0 0 0
52205- 0 0 0 0 0 0 0 0 0 0 0 0
52206- 0 0 0 0 0 0 0 0 0 0 0 0
52207- 0 0 0 0 0 0 0 0 0 0 0 0
52208- 0 0 0 6 6 6 22 22 22 50 50 50
52209- 90 90 90 26 26 26 2 2 6 2 2 6
52210- 14 14 14 195 195 195 250 250 250 253 253 253
52211-253 253 253 253 253 253 253 253 253 253 253 253
52212-253 253 253 253 253 253 253 253 253 253 253 253
52213-253 253 253 253 253 253 253 253 253 253 253 253
52214-253 253 253 253 253 253 253 253 253 253 253 253
52215-250 250 250 242 242 242 54 54 54 2 2 6
52216- 2 2 6 2 2 6 2 2 6 2 2 6
52217- 2 2 6 2 2 6 2 2 6 38 38 38
52218- 86 86 86 50 50 50 22 22 22 6 6 6
52219- 0 0 0 0 0 0 0 0 0 0 0 0
52220- 0 0 0 0 0 0 0 0 0 0 0 0
52221- 0 0 0 0 0 0 0 0 0 0 0 0
52222- 0 0 0 0 0 0 0 0 0 0 0 0
52223- 0 0 0 0 0 0 0 0 0 0 0 0
52224- 0 0 0 0 0 0 0 0 0 0 0 0
52225- 0 0 0 0 0 0 0 0 0 0 0 0
52226- 0 0 0 0 0 0 0 0 0 0 0 0
52227- 0 0 0 0 0 0 0 0 0 0 0 0
52228- 6 6 6 14 14 14 38 38 38 82 82 82
52229- 34 34 34 2 2 6 2 2 6 2 2 6
52230- 42 42 42 195 195 195 246 246 246 253 253 253
52231-253 253 253 253 253 253 253 253 253 250 250 250
52232-242 242 242 242 242 242 250 250 250 253 253 253
52233-253 253 253 253 253 253 253 253 253 253 253 253
52234-253 253 253 250 250 250 246 246 246 238 238 238
52235-226 226 226 231 231 231 101 101 101 6 6 6
52236- 2 2 6 2 2 6 2 2 6 2 2 6
52237- 2 2 6 2 2 6 2 2 6 2 2 6
52238- 38 38 38 82 82 82 42 42 42 14 14 14
52239- 6 6 6 0 0 0 0 0 0 0 0 0
52240- 0 0 0 0 0 0 0 0 0 0 0 0
52241- 0 0 0 0 0 0 0 0 0 0 0 0
52242- 0 0 0 0 0 0 0 0 0 0 0 0
52243- 0 0 0 0 0 0 0 0 0 0 0 0
52244- 0 0 0 0 0 0 0 0 0 0 0 0
52245- 0 0 0 0 0 0 0 0 0 0 0 0
52246- 0 0 0 0 0 0 0 0 0 0 0 0
52247- 0 0 0 0 0 0 0 0 0 0 0 0
52248- 10 10 10 26 26 26 62 62 62 66 66 66
52249- 2 2 6 2 2 6 2 2 6 6 6 6
52250- 70 70 70 170 170 170 206 206 206 234 234 234
52251-246 246 246 250 250 250 250 250 250 238 238 238
52252-226 226 226 231 231 231 238 238 238 250 250 250
52253-250 250 250 250 250 250 246 246 246 231 231 231
52254-214 214 214 206 206 206 202 202 202 202 202 202
52255-198 198 198 202 202 202 182 182 182 18 18 18
52256- 2 2 6 2 2 6 2 2 6 2 2 6
52257- 2 2 6 2 2 6 2 2 6 2 2 6
52258- 2 2 6 62 62 62 66 66 66 30 30 30
52259- 10 10 10 0 0 0 0 0 0 0 0 0
52260- 0 0 0 0 0 0 0 0 0 0 0 0
52261- 0 0 0 0 0 0 0 0 0 0 0 0
52262- 0 0 0 0 0 0 0 0 0 0 0 0
52263- 0 0 0 0 0 0 0 0 0 0 0 0
52264- 0 0 0 0 0 0 0 0 0 0 0 0
52265- 0 0 0 0 0 0 0 0 0 0 0 0
52266- 0 0 0 0 0 0 0 0 0 0 0 0
52267- 0 0 0 0 0 0 0 0 0 0 0 0
52268- 14 14 14 42 42 42 82 82 82 18 18 18
52269- 2 2 6 2 2 6 2 2 6 10 10 10
52270- 94 94 94 182 182 182 218 218 218 242 242 242
52271-250 250 250 253 253 253 253 253 253 250 250 250
52272-234 234 234 253 253 253 253 253 253 253 253 253
52273-253 253 253 253 253 253 253 253 253 246 246 246
52274-238 238 238 226 226 226 210 210 210 202 202 202
52275-195 195 195 195 195 195 210 210 210 158 158 158
52276- 6 6 6 14 14 14 50 50 50 14 14 14
52277- 2 2 6 2 2 6 2 2 6 2 2 6
52278- 2 2 6 6 6 6 86 86 86 46 46 46
52279- 18 18 18 6 6 6 0 0 0 0 0 0
52280- 0 0 0 0 0 0 0 0 0 0 0 0
52281- 0 0 0 0 0 0 0 0 0 0 0 0
52282- 0 0 0 0 0 0 0 0 0 0 0 0
52283- 0 0 0 0 0 0 0 0 0 0 0 0
52284- 0 0 0 0 0 0 0 0 0 0 0 0
52285- 0 0 0 0 0 0 0 0 0 0 0 0
52286- 0 0 0 0 0 0 0 0 0 0 0 0
52287- 0 0 0 0 0 0 0 0 0 6 6 6
52288- 22 22 22 54 54 54 70 70 70 2 2 6
52289- 2 2 6 10 10 10 2 2 6 22 22 22
52290-166 166 166 231 231 231 250 250 250 253 253 253
52291-253 253 253 253 253 253 253 253 253 250 250 250
52292-242 242 242 253 253 253 253 253 253 253 253 253
52293-253 253 253 253 253 253 253 253 253 253 253 253
52294-253 253 253 253 253 253 253 253 253 246 246 246
52295-231 231 231 206 206 206 198 198 198 226 226 226
52296- 94 94 94 2 2 6 6 6 6 38 38 38
52297- 30 30 30 2 2 6 2 2 6 2 2 6
52298- 2 2 6 2 2 6 62 62 62 66 66 66
52299- 26 26 26 10 10 10 0 0 0 0 0 0
52300- 0 0 0 0 0 0 0 0 0 0 0 0
52301- 0 0 0 0 0 0 0 0 0 0 0 0
52302- 0 0 0 0 0 0 0 0 0 0 0 0
52303- 0 0 0 0 0 0 0 0 0 0 0 0
52304- 0 0 0 0 0 0 0 0 0 0 0 0
52305- 0 0 0 0 0 0 0 0 0 0 0 0
52306- 0 0 0 0 0 0 0 0 0 0 0 0
52307- 0 0 0 0 0 0 0 0 0 10 10 10
52308- 30 30 30 74 74 74 50 50 50 2 2 6
52309- 26 26 26 26 26 26 2 2 6 106 106 106
52310-238 238 238 253 253 253 253 253 253 253 253 253
52311-253 253 253 253 253 253 253 253 253 253 253 253
52312-253 253 253 253 253 253 253 253 253 253 253 253
52313-253 253 253 253 253 253 253 253 253 253 253 253
52314-253 253 253 253 253 253 253 253 253 253 253 253
52315-253 253 253 246 246 246 218 218 218 202 202 202
52316-210 210 210 14 14 14 2 2 6 2 2 6
52317- 30 30 30 22 22 22 2 2 6 2 2 6
52318- 2 2 6 2 2 6 18 18 18 86 86 86
52319- 42 42 42 14 14 14 0 0 0 0 0 0
52320- 0 0 0 0 0 0 0 0 0 0 0 0
52321- 0 0 0 0 0 0 0 0 0 0 0 0
52322- 0 0 0 0 0 0 0 0 0 0 0 0
52323- 0 0 0 0 0 0 0 0 0 0 0 0
52324- 0 0 0 0 0 0 0 0 0 0 0 0
52325- 0 0 0 0 0 0 0 0 0 0 0 0
52326- 0 0 0 0 0 0 0 0 0 0 0 0
52327- 0 0 0 0 0 0 0 0 0 14 14 14
52328- 42 42 42 90 90 90 22 22 22 2 2 6
52329- 42 42 42 2 2 6 18 18 18 218 218 218
52330-253 253 253 253 253 253 253 253 253 253 253 253
52331-253 253 253 253 253 253 253 253 253 253 253 253
52332-253 253 253 253 253 253 253 253 253 253 253 253
52333-253 253 253 253 253 253 253 253 253 253 253 253
52334-253 253 253 253 253 253 253 253 253 253 253 253
52335-253 253 253 253 253 253 250 250 250 221 221 221
52336-218 218 218 101 101 101 2 2 6 14 14 14
52337- 18 18 18 38 38 38 10 10 10 2 2 6
52338- 2 2 6 2 2 6 2 2 6 78 78 78
52339- 58 58 58 22 22 22 6 6 6 0 0 0
52340- 0 0 0 0 0 0 0 0 0 0 0 0
52341- 0 0 0 0 0 0 0 0 0 0 0 0
52342- 0 0 0 0 0 0 0 0 0 0 0 0
52343- 0 0 0 0 0 0 0 0 0 0 0 0
52344- 0 0 0 0 0 0 0 0 0 0 0 0
52345- 0 0 0 0 0 0 0 0 0 0 0 0
52346- 0 0 0 0 0 0 0 0 0 0 0 0
52347- 0 0 0 0 0 0 6 6 6 18 18 18
52348- 54 54 54 82 82 82 2 2 6 26 26 26
52349- 22 22 22 2 2 6 123 123 123 253 253 253
52350-253 253 253 253 253 253 253 253 253 253 253 253
52351-253 253 253 253 253 253 253 253 253 253 253 253
52352-253 253 253 253 253 253 253 253 253 253 253 253
52353-253 253 253 253 253 253 253 253 253 253 253 253
52354-253 253 253 253 253 253 253 253 253 253 253 253
52355-253 253 253 253 253 253 253 253 253 250 250 250
52356-238 238 238 198 198 198 6 6 6 38 38 38
52357- 58 58 58 26 26 26 38 38 38 2 2 6
52358- 2 2 6 2 2 6 2 2 6 46 46 46
52359- 78 78 78 30 30 30 10 10 10 0 0 0
52360- 0 0 0 0 0 0 0 0 0 0 0 0
52361- 0 0 0 0 0 0 0 0 0 0 0 0
52362- 0 0 0 0 0 0 0 0 0 0 0 0
52363- 0 0 0 0 0 0 0 0 0 0 0 0
52364- 0 0 0 0 0 0 0 0 0 0 0 0
52365- 0 0 0 0 0 0 0 0 0 0 0 0
52366- 0 0 0 0 0 0 0 0 0 0 0 0
52367- 0 0 0 0 0 0 10 10 10 30 30 30
52368- 74 74 74 58 58 58 2 2 6 42 42 42
52369- 2 2 6 22 22 22 231 231 231 253 253 253
52370-253 253 253 253 253 253 253 253 253 253 253 253
52371-253 253 253 253 253 253 253 253 253 250 250 250
52372-253 253 253 253 253 253 253 253 253 253 253 253
52373-253 253 253 253 253 253 253 253 253 253 253 253
52374-253 253 253 253 253 253 253 253 253 253 253 253
52375-253 253 253 253 253 253 253 253 253 253 253 253
52376-253 253 253 246 246 246 46 46 46 38 38 38
52377- 42 42 42 14 14 14 38 38 38 14 14 14
52378- 2 2 6 2 2 6 2 2 6 6 6 6
52379- 86 86 86 46 46 46 14 14 14 0 0 0
52380- 0 0 0 0 0 0 0 0 0 0 0 0
52381- 0 0 0 0 0 0 0 0 0 0 0 0
52382- 0 0 0 0 0 0 0 0 0 0 0 0
52383- 0 0 0 0 0 0 0 0 0 0 0 0
52384- 0 0 0 0 0 0 0 0 0 0 0 0
52385- 0 0 0 0 0 0 0 0 0 0 0 0
52386- 0 0 0 0 0 0 0 0 0 0 0 0
52387- 0 0 0 6 6 6 14 14 14 42 42 42
52388- 90 90 90 18 18 18 18 18 18 26 26 26
52389- 2 2 6 116 116 116 253 253 253 253 253 253
52390-253 253 253 253 253 253 253 253 253 253 253 253
52391-253 253 253 253 253 253 250 250 250 238 238 238
52392-253 253 253 253 253 253 253 253 253 253 253 253
52393-253 253 253 253 253 253 253 253 253 253 253 253
52394-253 253 253 253 253 253 253 253 253 253 253 253
52395-253 253 253 253 253 253 253 253 253 253 253 253
52396-253 253 253 253 253 253 94 94 94 6 6 6
52397- 2 2 6 2 2 6 10 10 10 34 34 34
52398- 2 2 6 2 2 6 2 2 6 2 2 6
52399- 74 74 74 58 58 58 22 22 22 6 6 6
52400- 0 0 0 0 0 0 0 0 0 0 0 0
52401- 0 0 0 0 0 0 0 0 0 0 0 0
52402- 0 0 0 0 0 0 0 0 0 0 0 0
52403- 0 0 0 0 0 0 0 0 0 0 0 0
52404- 0 0 0 0 0 0 0 0 0 0 0 0
52405- 0 0 0 0 0 0 0 0 0 0 0 0
52406- 0 0 0 0 0 0 0 0 0 0 0 0
52407- 0 0 0 10 10 10 26 26 26 66 66 66
52408- 82 82 82 2 2 6 38 38 38 6 6 6
52409- 14 14 14 210 210 210 253 253 253 253 253 253
52410-253 253 253 253 253 253 253 253 253 253 253 253
52411-253 253 253 253 253 253 246 246 246 242 242 242
52412-253 253 253 253 253 253 253 253 253 253 253 253
52413-253 253 253 253 253 253 253 253 253 253 253 253
52414-253 253 253 253 253 253 253 253 253 253 253 253
52415-253 253 253 253 253 253 253 253 253 253 253 253
52416-253 253 253 253 253 253 144 144 144 2 2 6
52417- 2 2 6 2 2 6 2 2 6 46 46 46
52418- 2 2 6 2 2 6 2 2 6 2 2 6
52419- 42 42 42 74 74 74 30 30 30 10 10 10
52420- 0 0 0 0 0 0 0 0 0 0 0 0
52421- 0 0 0 0 0 0 0 0 0 0 0 0
52422- 0 0 0 0 0 0 0 0 0 0 0 0
52423- 0 0 0 0 0 0 0 0 0 0 0 0
52424- 0 0 0 0 0 0 0 0 0 0 0 0
52425- 0 0 0 0 0 0 0 0 0 0 0 0
52426- 0 0 0 0 0 0 0 0 0 0 0 0
52427- 6 6 6 14 14 14 42 42 42 90 90 90
52428- 26 26 26 6 6 6 42 42 42 2 2 6
52429- 74 74 74 250 250 250 253 253 253 253 253 253
52430-253 253 253 253 253 253 253 253 253 253 253 253
52431-253 253 253 253 253 253 242 242 242 242 242 242
52432-253 253 253 253 253 253 253 253 253 253 253 253
52433-253 253 253 253 253 253 253 253 253 253 253 253
52434-253 253 253 253 253 253 253 253 253 253 253 253
52435-253 253 253 253 253 253 253 253 253 253 253 253
52436-253 253 253 253 253 253 182 182 182 2 2 6
52437- 2 2 6 2 2 6 2 2 6 46 46 46
52438- 2 2 6 2 2 6 2 2 6 2 2 6
52439- 10 10 10 86 86 86 38 38 38 10 10 10
52440- 0 0 0 0 0 0 0 0 0 0 0 0
52441- 0 0 0 0 0 0 0 0 0 0 0 0
52442- 0 0 0 0 0 0 0 0 0 0 0 0
52443- 0 0 0 0 0 0 0 0 0 0 0 0
52444- 0 0 0 0 0 0 0 0 0 0 0 0
52445- 0 0 0 0 0 0 0 0 0 0 0 0
52446- 0 0 0 0 0 0 0 0 0 0 0 0
52447- 10 10 10 26 26 26 66 66 66 82 82 82
52448- 2 2 6 22 22 22 18 18 18 2 2 6
52449-149 149 149 253 253 253 253 253 253 253 253 253
52450-253 253 253 253 253 253 253 253 253 253 253 253
52451-253 253 253 253 253 253 234 234 234 242 242 242
52452-253 253 253 253 253 253 253 253 253 253 253 253
52453-253 253 253 253 253 253 253 253 253 253 253 253
52454-253 253 253 253 253 253 253 253 253 253 253 253
52455-253 253 253 253 253 253 253 253 253 253 253 253
52456-253 253 253 253 253 253 206 206 206 2 2 6
52457- 2 2 6 2 2 6 2 2 6 38 38 38
52458- 2 2 6 2 2 6 2 2 6 2 2 6
52459- 6 6 6 86 86 86 46 46 46 14 14 14
52460- 0 0 0 0 0 0 0 0 0 0 0 0
52461- 0 0 0 0 0 0 0 0 0 0 0 0
52462- 0 0 0 0 0 0 0 0 0 0 0 0
52463- 0 0 0 0 0 0 0 0 0 0 0 0
52464- 0 0 0 0 0 0 0 0 0 0 0 0
52465- 0 0 0 0 0 0 0 0 0 0 0 0
52466- 0 0 0 0 0 0 0 0 0 6 6 6
52467- 18 18 18 46 46 46 86 86 86 18 18 18
52468- 2 2 6 34 34 34 10 10 10 6 6 6
52469-210 210 210 253 253 253 253 253 253 253 253 253
52470-253 253 253 253 253 253 253 253 253 253 253 253
52471-253 253 253 253 253 253 234 234 234 242 242 242
52472-253 253 253 253 253 253 253 253 253 253 253 253
52473-253 253 253 253 253 253 253 253 253 253 253 253
52474-253 253 253 253 253 253 253 253 253 253 253 253
52475-253 253 253 253 253 253 253 253 253 253 253 253
52476-253 253 253 253 253 253 221 221 221 6 6 6
52477- 2 2 6 2 2 6 6 6 6 30 30 30
52478- 2 2 6 2 2 6 2 2 6 2 2 6
52479- 2 2 6 82 82 82 54 54 54 18 18 18
52480- 6 6 6 0 0 0 0 0 0 0 0 0
52481- 0 0 0 0 0 0 0 0 0 0 0 0
52482- 0 0 0 0 0 0 0 0 0 0 0 0
52483- 0 0 0 0 0 0 0 0 0 0 0 0
52484- 0 0 0 0 0 0 0 0 0 0 0 0
52485- 0 0 0 0 0 0 0 0 0 0 0 0
52486- 0 0 0 0 0 0 0 0 0 10 10 10
52487- 26 26 26 66 66 66 62 62 62 2 2 6
52488- 2 2 6 38 38 38 10 10 10 26 26 26
52489-238 238 238 253 253 253 253 253 253 253 253 253
52490-253 253 253 253 253 253 253 253 253 253 253 253
52491-253 253 253 253 253 253 231 231 231 238 238 238
52492-253 253 253 253 253 253 253 253 253 253 253 253
52493-253 253 253 253 253 253 253 253 253 253 253 253
52494-253 253 253 253 253 253 253 253 253 253 253 253
52495-253 253 253 253 253 253 253 253 253 253 253 253
52496-253 253 253 253 253 253 231 231 231 6 6 6
52497- 2 2 6 2 2 6 10 10 10 30 30 30
52498- 2 2 6 2 2 6 2 2 6 2 2 6
52499- 2 2 6 66 66 66 58 58 58 22 22 22
52500- 6 6 6 0 0 0 0 0 0 0 0 0
52501- 0 0 0 0 0 0 0 0 0 0 0 0
52502- 0 0 0 0 0 0 0 0 0 0 0 0
52503- 0 0 0 0 0 0 0 0 0 0 0 0
52504- 0 0 0 0 0 0 0 0 0 0 0 0
52505- 0 0 0 0 0 0 0 0 0 0 0 0
52506- 0 0 0 0 0 0 0 0 0 10 10 10
52507- 38 38 38 78 78 78 6 6 6 2 2 6
52508- 2 2 6 46 46 46 14 14 14 42 42 42
52509-246 246 246 253 253 253 253 253 253 253 253 253
52510-253 253 253 253 253 253 253 253 253 253 253 253
52511-253 253 253 253 253 253 231 231 231 242 242 242
52512-253 253 253 253 253 253 253 253 253 253 253 253
52513-253 253 253 253 253 253 253 253 253 253 253 253
52514-253 253 253 253 253 253 253 253 253 253 253 253
52515-253 253 253 253 253 253 253 253 253 253 253 253
52516-253 253 253 253 253 253 234 234 234 10 10 10
52517- 2 2 6 2 2 6 22 22 22 14 14 14
52518- 2 2 6 2 2 6 2 2 6 2 2 6
52519- 2 2 6 66 66 66 62 62 62 22 22 22
52520- 6 6 6 0 0 0 0 0 0 0 0 0
52521- 0 0 0 0 0 0 0 0 0 0 0 0
52522- 0 0 0 0 0 0 0 0 0 0 0 0
52523- 0 0 0 0 0 0 0 0 0 0 0 0
52524- 0 0 0 0 0 0 0 0 0 0 0 0
52525- 0 0 0 0 0 0 0 0 0 0 0 0
52526- 0 0 0 0 0 0 6 6 6 18 18 18
52527- 50 50 50 74 74 74 2 2 6 2 2 6
52528- 14 14 14 70 70 70 34 34 34 62 62 62
52529-250 250 250 253 253 253 253 253 253 253 253 253
52530-253 253 253 253 253 253 253 253 253 253 253 253
52531-253 253 253 253 253 253 231 231 231 246 246 246
52532-253 253 253 253 253 253 253 253 253 253 253 253
52533-253 253 253 253 253 253 253 253 253 253 253 253
52534-253 253 253 253 253 253 253 253 253 253 253 253
52535-253 253 253 253 253 253 253 253 253 253 253 253
52536-253 253 253 253 253 253 234 234 234 14 14 14
52537- 2 2 6 2 2 6 30 30 30 2 2 6
52538- 2 2 6 2 2 6 2 2 6 2 2 6
52539- 2 2 6 66 66 66 62 62 62 22 22 22
52540- 6 6 6 0 0 0 0 0 0 0 0 0
52541- 0 0 0 0 0 0 0 0 0 0 0 0
52542- 0 0 0 0 0 0 0 0 0 0 0 0
52543- 0 0 0 0 0 0 0 0 0 0 0 0
52544- 0 0 0 0 0 0 0 0 0 0 0 0
52545- 0 0 0 0 0 0 0 0 0 0 0 0
52546- 0 0 0 0 0 0 6 6 6 18 18 18
52547- 54 54 54 62 62 62 2 2 6 2 2 6
52548- 2 2 6 30 30 30 46 46 46 70 70 70
52549-250 250 250 253 253 253 253 253 253 253 253 253
52550-253 253 253 253 253 253 253 253 253 253 253 253
52551-253 253 253 253 253 253 231 231 231 246 246 246
52552-253 253 253 253 253 253 253 253 253 253 253 253
52553-253 253 253 253 253 253 253 253 253 253 253 253
52554-253 253 253 253 253 253 253 253 253 253 253 253
52555-253 253 253 253 253 253 253 253 253 253 253 253
52556-253 253 253 253 253 253 226 226 226 10 10 10
52557- 2 2 6 6 6 6 30 30 30 2 2 6
52558- 2 2 6 2 2 6 2 2 6 2 2 6
52559- 2 2 6 66 66 66 58 58 58 22 22 22
52560- 6 6 6 0 0 0 0 0 0 0 0 0
52561- 0 0 0 0 0 0 0 0 0 0 0 0
52562- 0 0 0 0 0 0 0 0 0 0 0 0
52563- 0 0 0 0 0 0 0 0 0 0 0 0
52564- 0 0 0 0 0 0 0 0 0 0 0 0
52565- 0 0 0 0 0 0 0 0 0 0 0 0
52566- 0 0 0 0 0 0 6 6 6 22 22 22
52567- 58 58 58 62 62 62 2 2 6 2 2 6
52568- 2 2 6 2 2 6 30 30 30 78 78 78
52569-250 250 250 253 253 253 253 253 253 253 253 253
52570-253 253 253 253 253 253 253 253 253 253 253 253
52571-253 253 253 253 253 253 231 231 231 246 246 246
52572-253 253 253 253 253 253 253 253 253 253 253 253
52573-253 253 253 253 253 253 253 253 253 253 253 253
52574-253 253 253 253 253 253 253 253 253 253 253 253
52575-253 253 253 253 253 253 253 253 253 253 253 253
52576-253 253 253 253 253 253 206 206 206 2 2 6
52577- 22 22 22 34 34 34 18 14 6 22 22 22
52578- 26 26 26 18 18 18 6 6 6 2 2 6
52579- 2 2 6 82 82 82 54 54 54 18 18 18
52580- 6 6 6 0 0 0 0 0 0 0 0 0
52581- 0 0 0 0 0 0 0 0 0 0 0 0
52582- 0 0 0 0 0 0 0 0 0 0 0 0
52583- 0 0 0 0 0 0 0 0 0 0 0 0
52584- 0 0 0 0 0 0 0 0 0 0 0 0
52585- 0 0 0 0 0 0 0 0 0 0 0 0
52586- 0 0 0 0 0 0 6 6 6 26 26 26
52587- 62 62 62 106 106 106 74 54 14 185 133 11
52588-210 162 10 121 92 8 6 6 6 62 62 62
52589-238 238 238 253 253 253 253 253 253 253 253 253
52590-253 253 253 253 253 253 253 253 253 253 253 253
52591-253 253 253 253 253 253 231 231 231 246 246 246
52592-253 253 253 253 253 253 253 253 253 253 253 253
52593-253 253 253 253 253 253 253 253 253 253 253 253
52594-253 253 253 253 253 253 253 253 253 253 253 253
52595-253 253 253 253 253 253 253 253 253 253 253 253
52596-253 253 253 253 253 253 158 158 158 18 18 18
52597- 14 14 14 2 2 6 2 2 6 2 2 6
52598- 6 6 6 18 18 18 66 66 66 38 38 38
52599- 6 6 6 94 94 94 50 50 50 18 18 18
52600- 6 6 6 0 0 0 0 0 0 0 0 0
52601- 0 0 0 0 0 0 0 0 0 0 0 0
52602- 0 0 0 0 0 0 0 0 0 0 0 0
52603- 0 0 0 0 0 0 0 0 0 0 0 0
52604- 0 0 0 0 0 0 0 0 0 0 0 0
52605- 0 0 0 0 0 0 0 0 0 6 6 6
52606- 10 10 10 10 10 10 18 18 18 38 38 38
52607- 78 78 78 142 134 106 216 158 10 242 186 14
52608-246 190 14 246 190 14 156 118 10 10 10 10
52609- 90 90 90 238 238 238 253 253 253 253 253 253
52610-253 253 253 253 253 253 253 253 253 253 253 253
52611-253 253 253 253 253 253 231 231 231 250 250 250
52612-253 253 253 253 253 253 253 253 253 253 253 253
52613-253 253 253 253 253 253 253 253 253 253 253 253
52614-253 253 253 253 253 253 253 253 253 253 253 253
52615-253 253 253 253 253 253 253 253 253 246 230 190
52616-238 204 91 238 204 91 181 142 44 37 26 9
52617- 2 2 6 2 2 6 2 2 6 2 2 6
52618- 2 2 6 2 2 6 38 38 38 46 46 46
52619- 26 26 26 106 106 106 54 54 54 18 18 18
52620- 6 6 6 0 0 0 0 0 0 0 0 0
52621- 0 0 0 0 0 0 0 0 0 0 0 0
52622- 0 0 0 0 0 0 0 0 0 0 0 0
52623- 0 0 0 0 0 0 0 0 0 0 0 0
52624- 0 0 0 0 0 0 0 0 0 0 0 0
52625- 0 0 0 6 6 6 14 14 14 22 22 22
52626- 30 30 30 38 38 38 50 50 50 70 70 70
52627-106 106 106 190 142 34 226 170 11 242 186 14
52628-246 190 14 246 190 14 246 190 14 154 114 10
52629- 6 6 6 74 74 74 226 226 226 253 253 253
52630-253 253 253 253 253 253 253 253 253 253 253 253
52631-253 253 253 253 253 253 231 231 231 250 250 250
52632-253 253 253 253 253 253 253 253 253 253 253 253
52633-253 253 253 253 253 253 253 253 253 253 253 253
52634-253 253 253 253 253 253 253 253 253 253 253 253
52635-253 253 253 253 253 253 253 253 253 228 184 62
52636-241 196 14 241 208 19 232 195 16 38 30 10
52637- 2 2 6 2 2 6 2 2 6 2 2 6
52638- 2 2 6 6 6 6 30 30 30 26 26 26
52639-203 166 17 154 142 90 66 66 66 26 26 26
52640- 6 6 6 0 0 0 0 0 0 0 0 0
52641- 0 0 0 0 0 0 0 0 0 0 0 0
52642- 0 0 0 0 0 0 0 0 0 0 0 0
52643- 0 0 0 0 0 0 0 0 0 0 0 0
52644- 0 0 0 0 0 0 0 0 0 0 0 0
52645- 6 6 6 18 18 18 38 38 38 58 58 58
52646- 78 78 78 86 86 86 101 101 101 123 123 123
52647-175 146 61 210 150 10 234 174 13 246 186 14
52648-246 190 14 246 190 14 246 190 14 238 190 10
52649-102 78 10 2 2 6 46 46 46 198 198 198
52650-253 253 253 253 253 253 253 253 253 253 253 253
52651-253 253 253 253 253 253 234 234 234 242 242 242
52652-253 253 253 253 253 253 253 253 253 253 253 253
52653-253 253 253 253 253 253 253 253 253 253 253 253
52654-253 253 253 253 253 253 253 253 253 253 253 253
52655-253 253 253 253 253 253 253 253 253 224 178 62
52656-242 186 14 241 196 14 210 166 10 22 18 6
52657- 2 2 6 2 2 6 2 2 6 2 2 6
52658- 2 2 6 2 2 6 6 6 6 121 92 8
52659-238 202 15 232 195 16 82 82 82 34 34 34
52660- 10 10 10 0 0 0 0 0 0 0 0 0
52661- 0 0 0 0 0 0 0 0 0 0 0 0
52662- 0 0 0 0 0 0 0 0 0 0 0 0
52663- 0 0 0 0 0 0 0 0 0 0 0 0
52664- 0 0 0 0 0 0 0 0 0 0 0 0
52665- 14 14 14 38 38 38 70 70 70 154 122 46
52666-190 142 34 200 144 11 197 138 11 197 138 11
52667-213 154 11 226 170 11 242 186 14 246 190 14
52668-246 190 14 246 190 14 246 190 14 246 190 14
52669-225 175 15 46 32 6 2 2 6 22 22 22
52670-158 158 158 250 250 250 253 253 253 253 253 253
52671-253 253 253 253 253 253 253 253 253 253 253 253
52672-253 253 253 253 253 253 253 253 253 253 253 253
52673-253 253 253 253 253 253 253 253 253 253 253 253
52674-253 253 253 253 253 253 253 253 253 253 253 253
52675-253 253 253 250 250 250 242 242 242 224 178 62
52676-239 182 13 236 186 11 213 154 11 46 32 6
52677- 2 2 6 2 2 6 2 2 6 2 2 6
52678- 2 2 6 2 2 6 61 42 6 225 175 15
52679-238 190 10 236 186 11 112 100 78 42 42 42
52680- 14 14 14 0 0 0 0 0 0 0 0 0
52681- 0 0 0 0 0 0 0 0 0 0 0 0
52682- 0 0 0 0 0 0 0 0 0 0 0 0
52683- 0 0 0 0 0 0 0 0 0 0 0 0
52684- 0 0 0 0 0 0 0 0 0 6 6 6
52685- 22 22 22 54 54 54 154 122 46 213 154 11
52686-226 170 11 230 174 11 226 170 11 226 170 11
52687-236 178 12 242 186 14 246 190 14 246 190 14
52688-246 190 14 246 190 14 246 190 14 246 190 14
52689-241 196 14 184 144 12 10 10 10 2 2 6
52690- 6 6 6 116 116 116 242 242 242 253 253 253
52691-253 253 253 253 253 253 253 253 253 253 253 253
52692-253 253 253 253 253 253 253 253 253 253 253 253
52693-253 253 253 253 253 253 253 253 253 253 253 253
52694-253 253 253 253 253 253 253 253 253 253 253 253
52695-253 253 253 231 231 231 198 198 198 214 170 54
52696-236 178 12 236 178 12 210 150 10 137 92 6
52697- 18 14 6 2 2 6 2 2 6 2 2 6
52698- 6 6 6 70 47 6 200 144 11 236 178 12
52699-239 182 13 239 182 13 124 112 88 58 58 58
52700- 22 22 22 6 6 6 0 0 0 0 0 0
52701- 0 0 0 0 0 0 0 0 0 0 0 0
52702- 0 0 0 0 0 0 0 0 0 0 0 0
52703- 0 0 0 0 0 0 0 0 0 0 0 0
52704- 0 0 0 0 0 0 0 0 0 10 10 10
52705- 30 30 30 70 70 70 180 133 36 226 170 11
52706-239 182 13 242 186 14 242 186 14 246 186 14
52707-246 190 14 246 190 14 246 190 14 246 190 14
52708-246 190 14 246 190 14 246 190 14 246 190 14
52709-246 190 14 232 195 16 98 70 6 2 2 6
52710- 2 2 6 2 2 6 66 66 66 221 221 221
52711-253 253 253 253 253 253 253 253 253 253 253 253
52712-253 253 253 253 253 253 253 253 253 253 253 253
52713-253 253 253 253 253 253 253 253 253 253 253 253
52714-253 253 253 253 253 253 253 253 253 253 253 253
52715-253 253 253 206 206 206 198 198 198 214 166 58
52716-230 174 11 230 174 11 216 158 10 192 133 9
52717-163 110 8 116 81 8 102 78 10 116 81 8
52718-167 114 7 197 138 11 226 170 11 239 182 13
52719-242 186 14 242 186 14 162 146 94 78 78 78
52720- 34 34 34 14 14 14 6 6 6 0 0 0
52721- 0 0 0 0 0 0 0 0 0 0 0 0
52722- 0 0 0 0 0 0 0 0 0 0 0 0
52723- 0 0 0 0 0 0 0 0 0 0 0 0
52724- 0 0 0 0 0 0 0 0 0 6 6 6
52725- 30 30 30 78 78 78 190 142 34 226 170 11
52726-239 182 13 246 190 14 246 190 14 246 190 14
52727-246 190 14 246 190 14 246 190 14 246 190 14
52728-246 190 14 246 190 14 246 190 14 246 190 14
52729-246 190 14 241 196 14 203 166 17 22 18 6
52730- 2 2 6 2 2 6 2 2 6 38 38 38
52731-218 218 218 253 253 253 253 253 253 253 253 253
52732-253 253 253 253 253 253 253 253 253 253 253 253
52733-253 253 253 253 253 253 253 253 253 253 253 253
52734-253 253 253 253 253 253 253 253 253 253 253 253
52735-250 250 250 206 206 206 198 198 198 202 162 69
52736-226 170 11 236 178 12 224 166 10 210 150 10
52737-200 144 11 197 138 11 192 133 9 197 138 11
52738-210 150 10 226 170 11 242 186 14 246 190 14
52739-246 190 14 246 186 14 225 175 15 124 112 88
52740- 62 62 62 30 30 30 14 14 14 6 6 6
52741- 0 0 0 0 0 0 0 0 0 0 0 0
52742- 0 0 0 0 0 0 0 0 0 0 0 0
52743- 0 0 0 0 0 0 0 0 0 0 0 0
52744- 0 0 0 0 0 0 0 0 0 10 10 10
52745- 30 30 30 78 78 78 174 135 50 224 166 10
52746-239 182 13 246 190 14 246 190 14 246 190 14
52747-246 190 14 246 190 14 246 190 14 246 190 14
52748-246 190 14 246 190 14 246 190 14 246 190 14
52749-246 190 14 246 190 14 241 196 14 139 102 15
52750- 2 2 6 2 2 6 2 2 6 2 2 6
52751- 78 78 78 250 250 250 253 253 253 253 253 253
52752-253 253 253 253 253 253 253 253 253 253 253 253
52753-253 253 253 253 253 253 253 253 253 253 253 253
52754-253 253 253 253 253 253 253 253 253 253 253 253
52755-250 250 250 214 214 214 198 198 198 190 150 46
52756-219 162 10 236 178 12 234 174 13 224 166 10
52757-216 158 10 213 154 11 213 154 11 216 158 10
52758-226 170 11 239 182 13 246 190 14 246 190 14
52759-246 190 14 246 190 14 242 186 14 206 162 42
52760-101 101 101 58 58 58 30 30 30 14 14 14
52761- 6 6 6 0 0 0 0 0 0 0 0 0
52762- 0 0 0 0 0 0 0 0 0 0 0 0
52763- 0 0 0 0 0 0 0 0 0 0 0 0
52764- 0 0 0 0 0 0 0 0 0 10 10 10
52765- 30 30 30 74 74 74 174 135 50 216 158 10
52766-236 178 12 246 190 14 246 190 14 246 190 14
52767-246 190 14 246 190 14 246 190 14 246 190 14
52768-246 190 14 246 190 14 246 190 14 246 190 14
52769-246 190 14 246 190 14 241 196 14 226 184 13
52770- 61 42 6 2 2 6 2 2 6 2 2 6
52771- 22 22 22 238 238 238 253 253 253 253 253 253
52772-253 253 253 253 253 253 253 253 253 253 253 253
52773-253 253 253 253 253 253 253 253 253 253 253 253
52774-253 253 253 253 253 253 253 253 253 253 253 253
52775-253 253 253 226 226 226 187 187 187 180 133 36
52776-216 158 10 236 178 12 239 182 13 236 178 12
52777-230 174 11 226 170 11 226 170 11 230 174 11
52778-236 178 12 242 186 14 246 190 14 246 190 14
52779-246 190 14 246 190 14 246 186 14 239 182 13
52780-206 162 42 106 106 106 66 66 66 34 34 34
52781- 14 14 14 6 6 6 0 0 0 0 0 0
52782- 0 0 0 0 0 0 0 0 0 0 0 0
52783- 0 0 0 0 0 0 0 0 0 0 0 0
52784- 0 0 0 0 0 0 0 0 0 6 6 6
52785- 26 26 26 70 70 70 163 133 67 213 154 11
52786-236 178 12 246 190 14 246 190 14 246 190 14
52787-246 190 14 246 190 14 246 190 14 246 190 14
52788-246 190 14 246 190 14 246 190 14 246 190 14
52789-246 190 14 246 190 14 246 190 14 241 196 14
52790-190 146 13 18 14 6 2 2 6 2 2 6
52791- 46 46 46 246 246 246 253 253 253 253 253 253
52792-253 253 253 253 253 253 253 253 253 253 253 253
52793-253 253 253 253 253 253 253 253 253 253 253 253
52794-253 253 253 253 253 253 253 253 253 253 253 253
52795-253 253 253 221 221 221 86 86 86 156 107 11
52796-216 158 10 236 178 12 242 186 14 246 186 14
52797-242 186 14 239 182 13 239 182 13 242 186 14
52798-242 186 14 246 186 14 246 190 14 246 190 14
52799-246 190 14 246 190 14 246 190 14 246 190 14
52800-242 186 14 225 175 15 142 122 72 66 66 66
52801- 30 30 30 10 10 10 0 0 0 0 0 0
52802- 0 0 0 0 0 0 0 0 0 0 0 0
52803- 0 0 0 0 0 0 0 0 0 0 0 0
52804- 0 0 0 0 0 0 0 0 0 6 6 6
52805- 26 26 26 70 70 70 163 133 67 210 150 10
52806-236 178 12 246 190 14 246 190 14 246 190 14
52807-246 190 14 246 190 14 246 190 14 246 190 14
52808-246 190 14 246 190 14 246 190 14 246 190 14
52809-246 190 14 246 190 14 246 190 14 246 190 14
52810-232 195 16 121 92 8 34 34 34 106 106 106
52811-221 221 221 253 253 253 253 253 253 253 253 253
52812-253 253 253 253 253 253 253 253 253 253 253 253
52813-253 253 253 253 253 253 253 253 253 253 253 253
52814-253 253 253 253 253 253 253 253 253 253 253 253
52815-242 242 242 82 82 82 18 14 6 163 110 8
52816-216 158 10 236 178 12 242 186 14 246 190 14
52817-246 190 14 246 190 14 246 190 14 246 190 14
52818-246 190 14 246 190 14 246 190 14 246 190 14
52819-246 190 14 246 190 14 246 190 14 246 190 14
52820-246 190 14 246 190 14 242 186 14 163 133 67
52821- 46 46 46 18 18 18 6 6 6 0 0 0
52822- 0 0 0 0 0 0 0 0 0 0 0 0
52823- 0 0 0 0 0 0 0 0 0 0 0 0
52824- 0 0 0 0 0 0 0 0 0 10 10 10
52825- 30 30 30 78 78 78 163 133 67 210 150 10
52826-236 178 12 246 186 14 246 190 14 246 190 14
52827-246 190 14 246 190 14 246 190 14 246 190 14
52828-246 190 14 246 190 14 246 190 14 246 190 14
52829-246 190 14 246 190 14 246 190 14 246 190 14
52830-241 196 14 215 174 15 190 178 144 253 253 253
52831-253 253 253 253 253 253 253 253 253 253 253 253
52832-253 253 253 253 253 253 253 253 253 253 253 253
52833-253 253 253 253 253 253 253 253 253 253 253 253
52834-253 253 253 253 253 253 253 253 253 218 218 218
52835- 58 58 58 2 2 6 22 18 6 167 114 7
52836-216 158 10 236 178 12 246 186 14 246 190 14
52837-246 190 14 246 190 14 246 190 14 246 190 14
52838-246 190 14 246 190 14 246 190 14 246 190 14
52839-246 190 14 246 190 14 246 190 14 246 190 14
52840-246 190 14 246 186 14 242 186 14 190 150 46
52841- 54 54 54 22 22 22 6 6 6 0 0 0
52842- 0 0 0 0 0 0 0 0 0 0 0 0
52843- 0 0 0 0 0 0 0 0 0 0 0 0
52844- 0 0 0 0 0 0 0 0 0 14 14 14
52845- 38 38 38 86 86 86 180 133 36 213 154 11
52846-236 178 12 246 186 14 246 190 14 246 190 14
52847-246 190 14 246 190 14 246 190 14 246 190 14
52848-246 190 14 246 190 14 246 190 14 246 190 14
52849-246 190 14 246 190 14 246 190 14 246 190 14
52850-246 190 14 232 195 16 190 146 13 214 214 214
52851-253 253 253 253 253 253 253 253 253 253 253 253
52852-253 253 253 253 253 253 253 253 253 253 253 253
52853-253 253 253 253 253 253 253 253 253 253 253 253
52854-253 253 253 250 250 250 170 170 170 26 26 26
52855- 2 2 6 2 2 6 37 26 9 163 110 8
52856-219 162 10 239 182 13 246 186 14 246 190 14
52857-246 190 14 246 190 14 246 190 14 246 190 14
52858-246 190 14 246 190 14 246 190 14 246 190 14
52859-246 190 14 246 190 14 246 190 14 246 190 14
52860-246 186 14 236 178 12 224 166 10 142 122 72
52861- 46 46 46 18 18 18 6 6 6 0 0 0
52862- 0 0 0 0 0 0 0 0 0 0 0 0
52863- 0 0 0 0 0 0 0 0 0 0 0 0
52864- 0 0 0 0 0 0 6 6 6 18 18 18
52865- 50 50 50 109 106 95 192 133 9 224 166 10
52866-242 186 14 246 190 14 246 190 14 246 190 14
52867-246 190 14 246 190 14 246 190 14 246 190 14
52868-246 190 14 246 190 14 246 190 14 246 190 14
52869-246 190 14 246 190 14 246 190 14 246 190 14
52870-242 186 14 226 184 13 210 162 10 142 110 46
52871-226 226 226 253 253 253 253 253 253 253 253 253
52872-253 253 253 253 253 253 253 253 253 253 253 253
52873-253 253 253 253 253 253 253 253 253 253 253 253
52874-198 198 198 66 66 66 2 2 6 2 2 6
52875- 2 2 6 2 2 6 50 34 6 156 107 11
52876-219 162 10 239 182 13 246 186 14 246 190 14
52877-246 190 14 246 190 14 246 190 14 246 190 14
52878-246 190 14 246 190 14 246 190 14 246 190 14
52879-246 190 14 246 190 14 246 190 14 242 186 14
52880-234 174 13 213 154 11 154 122 46 66 66 66
52881- 30 30 30 10 10 10 0 0 0 0 0 0
52882- 0 0 0 0 0 0 0 0 0 0 0 0
52883- 0 0 0 0 0 0 0 0 0 0 0 0
52884- 0 0 0 0 0 0 6 6 6 22 22 22
52885- 58 58 58 154 121 60 206 145 10 234 174 13
52886-242 186 14 246 186 14 246 190 14 246 190 14
52887-246 190 14 246 190 14 246 190 14 246 190 14
52888-246 190 14 246 190 14 246 190 14 246 190 14
52889-246 190 14 246 190 14 246 190 14 246 190 14
52890-246 186 14 236 178 12 210 162 10 163 110 8
52891- 61 42 6 138 138 138 218 218 218 250 250 250
52892-253 253 253 253 253 253 253 253 253 250 250 250
52893-242 242 242 210 210 210 144 144 144 66 66 66
52894- 6 6 6 2 2 6 2 2 6 2 2 6
52895- 2 2 6 2 2 6 61 42 6 163 110 8
52896-216 158 10 236 178 12 246 190 14 246 190 14
52897-246 190 14 246 190 14 246 190 14 246 190 14
52898-246 190 14 246 190 14 246 190 14 246 190 14
52899-246 190 14 239 182 13 230 174 11 216 158 10
52900-190 142 34 124 112 88 70 70 70 38 38 38
52901- 18 18 18 6 6 6 0 0 0 0 0 0
52902- 0 0 0 0 0 0 0 0 0 0 0 0
52903- 0 0 0 0 0 0 0 0 0 0 0 0
52904- 0 0 0 0 0 0 6 6 6 22 22 22
52905- 62 62 62 168 124 44 206 145 10 224 166 10
52906-236 178 12 239 182 13 242 186 14 242 186 14
52907-246 186 14 246 190 14 246 190 14 246 190 14
52908-246 190 14 246 190 14 246 190 14 246 190 14
52909-246 190 14 246 190 14 246 190 14 246 190 14
52910-246 190 14 236 178 12 216 158 10 175 118 6
52911- 80 54 7 2 2 6 6 6 6 30 30 30
52912- 54 54 54 62 62 62 50 50 50 38 38 38
52913- 14 14 14 2 2 6 2 2 6 2 2 6
52914- 2 2 6 2 2 6 2 2 6 2 2 6
52915- 2 2 6 6 6 6 80 54 7 167 114 7
52916-213 154 11 236 178 12 246 190 14 246 190 14
52917-246 190 14 246 190 14 246 190 14 246 190 14
52918-246 190 14 242 186 14 239 182 13 239 182 13
52919-230 174 11 210 150 10 174 135 50 124 112 88
52920- 82 82 82 54 54 54 34 34 34 18 18 18
52921- 6 6 6 0 0 0 0 0 0 0 0 0
52922- 0 0 0 0 0 0 0 0 0 0 0 0
52923- 0 0 0 0 0 0 0 0 0 0 0 0
52924- 0 0 0 0 0 0 6 6 6 18 18 18
52925- 50 50 50 158 118 36 192 133 9 200 144 11
52926-216 158 10 219 162 10 224 166 10 226 170 11
52927-230 174 11 236 178 12 239 182 13 239 182 13
52928-242 186 14 246 186 14 246 190 14 246 190 14
52929-246 190 14 246 190 14 246 190 14 246 190 14
52930-246 186 14 230 174 11 210 150 10 163 110 8
52931-104 69 6 10 10 10 2 2 6 2 2 6
52932- 2 2 6 2 2 6 2 2 6 2 2 6
52933- 2 2 6 2 2 6 2 2 6 2 2 6
52934- 2 2 6 2 2 6 2 2 6 2 2 6
52935- 2 2 6 6 6 6 91 60 6 167 114 7
52936-206 145 10 230 174 11 242 186 14 246 190 14
52937-246 190 14 246 190 14 246 186 14 242 186 14
52938-239 182 13 230 174 11 224 166 10 213 154 11
52939-180 133 36 124 112 88 86 86 86 58 58 58
52940- 38 38 38 22 22 22 10 10 10 6 6 6
52941- 0 0 0 0 0 0 0 0 0 0 0 0
52942- 0 0 0 0 0 0 0 0 0 0 0 0
52943- 0 0 0 0 0 0 0 0 0 0 0 0
52944- 0 0 0 0 0 0 0 0 0 14 14 14
52945- 34 34 34 70 70 70 138 110 50 158 118 36
52946-167 114 7 180 123 7 192 133 9 197 138 11
52947-200 144 11 206 145 10 213 154 11 219 162 10
52948-224 166 10 230 174 11 239 182 13 242 186 14
52949-246 186 14 246 186 14 246 186 14 246 186 14
52950-239 182 13 216 158 10 185 133 11 152 99 6
52951-104 69 6 18 14 6 2 2 6 2 2 6
52952- 2 2 6 2 2 6 2 2 6 2 2 6
52953- 2 2 6 2 2 6 2 2 6 2 2 6
52954- 2 2 6 2 2 6 2 2 6 2 2 6
52955- 2 2 6 6 6 6 80 54 7 152 99 6
52956-192 133 9 219 162 10 236 178 12 239 182 13
52957-246 186 14 242 186 14 239 182 13 236 178 12
52958-224 166 10 206 145 10 192 133 9 154 121 60
52959- 94 94 94 62 62 62 42 42 42 22 22 22
52960- 14 14 14 6 6 6 0 0 0 0 0 0
52961- 0 0 0 0 0 0 0 0 0 0 0 0
52962- 0 0 0 0 0 0 0 0 0 0 0 0
52963- 0 0 0 0 0 0 0 0 0 0 0 0
52964- 0 0 0 0 0 0 0 0 0 6 6 6
52965- 18 18 18 34 34 34 58 58 58 78 78 78
52966-101 98 89 124 112 88 142 110 46 156 107 11
52967-163 110 8 167 114 7 175 118 6 180 123 7
52968-185 133 11 197 138 11 210 150 10 219 162 10
52969-226 170 11 236 178 12 236 178 12 234 174 13
52970-219 162 10 197 138 11 163 110 8 130 83 6
52971- 91 60 6 10 10 10 2 2 6 2 2 6
52972- 18 18 18 38 38 38 38 38 38 38 38 38
52973- 38 38 38 38 38 38 38 38 38 38 38 38
52974- 38 38 38 38 38 38 26 26 26 2 2 6
52975- 2 2 6 6 6 6 70 47 6 137 92 6
52976-175 118 6 200 144 11 219 162 10 230 174 11
52977-234 174 13 230 174 11 219 162 10 210 150 10
52978-192 133 9 163 110 8 124 112 88 82 82 82
52979- 50 50 50 30 30 30 14 14 14 6 6 6
52980- 0 0 0 0 0 0 0 0 0 0 0 0
52981- 0 0 0 0 0 0 0 0 0 0 0 0
52982- 0 0 0 0 0 0 0 0 0 0 0 0
52983- 0 0 0 0 0 0 0 0 0 0 0 0
52984- 0 0 0 0 0 0 0 0 0 0 0 0
52985- 6 6 6 14 14 14 22 22 22 34 34 34
52986- 42 42 42 58 58 58 74 74 74 86 86 86
52987-101 98 89 122 102 70 130 98 46 121 87 25
52988-137 92 6 152 99 6 163 110 8 180 123 7
52989-185 133 11 197 138 11 206 145 10 200 144 11
52990-180 123 7 156 107 11 130 83 6 104 69 6
52991- 50 34 6 54 54 54 110 110 110 101 98 89
52992- 86 86 86 82 82 82 78 78 78 78 78 78
52993- 78 78 78 78 78 78 78 78 78 78 78 78
52994- 78 78 78 82 82 82 86 86 86 94 94 94
52995-106 106 106 101 101 101 86 66 34 124 80 6
52996-156 107 11 180 123 7 192 133 9 200 144 11
52997-206 145 10 200 144 11 192 133 9 175 118 6
52998-139 102 15 109 106 95 70 70 70 42 42 42
52999- 22 22 22 10 10 10 0 0 0 0 0 0
53000- 0 0 0 0 0 0 0 0 0 0 0 0
53001- 0 0 0 0 0 0 0 0 0 0 0 0
53002- 0 0 0 0 0 0 0 0 0 0 0 0
53003- 0 0 0 0 0 0 0 0 0 0 0 0
53004- 0 0 0 0 0 0 0 0 0 0 0 0
53005- 0 0 0 0 0 0 6 6 6 10 10 10
53006- 14 14 14 22 22 22 30 30 30 38 38 38
53007- 50 50 50 62 62 62 74 74 74 90 90 90
53008-101 98 89 112 100 78 121 87 25 124 80 6
53009-137 92 6 152 99 6 152 99 6 152 99 6
53010-138 86 6 124 80 6 98 70 6 86 66 30
53011-101 98 89 82 82 82 58 58 58 46 46 46
53012- 38 38 38 34 34 34 34 34 34 34 34 34
53013- 34 34 34 34 34 34 34 34 34 34 34 34
53014- 34 34 34 34 34 34 38 38 38 42 42 42
53015- 54 54 54 82 82 82 94 86 76 91 60 6
53016-134 86 6 156 107 11 167 114 7 175 118 6
53017-175 118 6 167 114 7 152 99 6 121 87 25
53018-101 98 89 62 62 62 34 34 34 18 18 18
53019- 6 6 6 0 0 0 0 0 0 0 0 0
53020- 0 0 0 0 0 0 0 0 0 0 0 0
53021- 0 0 0 0 0 0 0 0 0 0 0 0
53022- 0 0 0 0 0 0 0 0 0 0 0 0
53023- 0 0 0 0 0 0 0 0 0 0 0 0
53024- 0 0 0 0 0 0 0 0 0 0 0 0
53025- 0 0 0 0 0 0 0 0 0 0 0 0
53026- 0 0 0 6 6 6 6 6 6 10 10 10
53027- 18 18 18 22 22 22 30 30 30 42 42 42
53028- 50 50 50 66 66 66 86 86 86 101 98 89
53029-106 86 58 98 70 6 104 69 6 104 69 6
53030-104 69 6 91 60 6 82 62 34 90 90 90
53031- 62 62 62 38 38 38 22 22 22 14 14 14
53032- 10 10 10 10 10 10 10 10 10 10 10 10
53033- 10 10 10 10 10 10 6 6 6 10 10 10
53034- 10 10 10 10 10 10 10 10 10 14 14 14
53035- 22 22 22 42 42 42 70 70 70 89 81 66
53036- 80 54 7 104 69 6 124 80 6 137 92 6
53037-134 86 6 116 81 8 100 82 52 86 86 86
53038- 58 58 58 30 30 30 14 14 14 6 6 6
53039- 0 0 0 0 0 0 0 0 0 0 0 0
53040- 0 0 0 0 0 0 0 0 0 0 0 0
53041- 0 0 0 0 0 0 0 0 0 0 0 0
53042- 0 0 0 0 0 0 0 0 0 0 0 0
53043- 0 0 0 0 0 0 0 0 0 0 0 0
53044- 0 0 0 0 0 0 0 0 0 0 0 0
53045- 0 0 0 0 0 0 0 0 0 0 0 0
53046- 0 0 0 0 0 0 0 0 0 0 0 0
53047- 0 0 0 6 6 6 10 10 10 14 14 14
53048- 18 18 18 26 26 26 38 38 38 54 54 54
53049- 70 70 70 86 86 86 94 86 76 89 81 66
53050- 89 81 66 86 86 86 74 74 74 50 50 50
53051- 30 30 30 14 14 14 6 6 6 0 0 0
53052- 0 0 0 0 0 0 0 0 0 0 0 0
53053- 0 0 0 0 0 0 0 0 0 0 0 0
53054- 0 0 0 0 0 0 0 0 0 0 0 0
53055- 6 6 6 18 18 18 34 34 34 58 58 58
53056- 82 82 82 89 81 66 89 81 66 89 81 66
53057- 94 86 66 94 86 76 74 74 74 50 50 50
53058- 26 26 26 14 14 14 6 6 6 0 0 0
53059- 0 0 0 0 0 0 0 0 0 0 0 0
53060- 0 0 0 0 0 0 0 0 0 0 0 0
53061- 0 0 0 0 0 0 0 0 0 0 0 0
53062- 0 0 0 0 0 0 0 0 0 0 0 0
53063- 0 0 0 0 0 0 0 0 0 0 0 0
53064- 0 0 0 0 0 0 0 0 0 0 0 0
53065- 0 0 0 0 0 0 0 0 0 0 0 0
53066- 0 0 0 0 0 0 0 0 0 0 0 0
53067- 0 0 0 0 0 0 0 0 0 0 0 0
53068- 6 6 6 6 6 6 14 14 14 18 18 18
53069- 30 30 30 38 38 38 46 46 46 54 54 54
53070- 50 50 50 42 42 42 30 30 30 18 18 18
53071- 10 10 10 0 0 0 0 0 0 0 0 0
53072- 0 0 0 0 0 0 0 0 0 0 0 0
53073- 0 0 0 0 0 0 0 0 0 0 0 0
53074- 0 0 0 0 0 0 0 0 0 0 0 0
53075- 0 0 0 6 6 6 14 14 14 26 26 26
53076- 38 38 38 50 50 50 58 58 58 58 58 58
53077- 54 54 54 42 42 42 30 30 30 18 18 18
53078- 10 10 10 0 0 0 0 0 0 0 0 0
53079- 0 0 0 0 0 0 0 0 0 0 0 0
53080- 0 0 0 0 0 0 0 0 0 0 0 0
53081- 0 0 0 0 0 0 0 0 0 0 0 0
53082- 0 0 0 0 0 0 0 0 0 0 0 0
53083- 0 0 0 0 0 0 0 0 0 0 0 0
53084- 0 0 0 0 0 0 0 0 0 0 0 0
53085- 0 0 0 0 0 0 0 0 0 0 0 0
53086- 0 0 0 0 0 0 0 0 0 0 0 0
53087- 0 0 0 0 0 0 0 0 0 0 0 0
53088- 0 0 0 0 0 0 0 0 0 6 6 6
53089- 6 6 6 10 10 10 14 14 14 18 18 18
53090- 18 18 18 14 14 14 10 10 10 6 6 6
53091- 0 0 0 0 0 0 0 0 0 0 0 0
53092- 0 0 0 0 0 0 0 0 0 0 0 0
53093- 0 0 0 0 0 0 0 0 0 0 0 0
53094- 0 0 0 0 0 0 0 0 0 0 0 0
53095- 0 0 0 0 0 0 0 0 0 6 6 6
53096- 14 14 14 18 18 18 22 22 22 22 22 22
53097- 18 18 18 14 14 14 10 10 10 6 6 6
53098- 0 0 0 0 0 0 0 0 0 0 0 0
53099- 0 0 0 0 0 0 0 0 0 0 0 0
53100- 0 0 0 0 0 0 0 0 0 0 0 0
53101- 0 0 0 0 0 0 0 0 0 0 0 0
53102- 0 0 0 0 0 0 0 0 0 0 0 0
53103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53116+4 4 4 4 4 4
53117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53130+4 4 4 4 4 4
53131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53144+4 4 4 4 4 4
53145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53158+4 4 4 4 4 4
53159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53172+4 4 4 4 4 4
53173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53186+4 4 4 4 4 4
53187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53191+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
53192+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
53193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53196+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
53197+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53198+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
53199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53200+4 4 4 4 4 4
53201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53205+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
53206+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
53207+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53210+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
53211+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
53212+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
53213+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53214+4 4 4 4 4 4
53215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53219+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
53220+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
53221+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53224+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
53225+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
53226+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
53227+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
53228+4 4 4 4 4 4
53229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53232+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
53233+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
53234+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
53235+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
53236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53237+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53238+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
53239+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
53240+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
53241+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
53242+4 4 4 4 4 4
53243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53246+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
53247+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
53248+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
53249+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
53250+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53251+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
53252+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
53253+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
53254+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
53255+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
53256+4 4 4 4 4 4
53257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
53260+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
53261+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
53262+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
53263+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
53264+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
53265+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
53266+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
53267+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
53268+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
53269+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
53270+4 4 4 4 4 4
53271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53273+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
53274+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
53275+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
53276+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
53277+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
53278+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
53279+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
53280+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
53281+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
53282+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
53283+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
53284+4 4 4 4 4 4
53285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53287+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
53288+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
53289+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
53290+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
53291+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
53292+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
53293+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
53294+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
53295+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
53296+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
53297+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
53298+4 4 4 4 4 4
53299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53301+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
53302+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
53303+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
53304+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
53305+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
53306+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
53307+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
53308+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
53309+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
53310+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
53311+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53312+4 4 4 4 4 4
53313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53315+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
53316+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
53317+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
53318+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
53319+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
53320+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
53321+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
53322+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
53323+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
53324+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
53325+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
53326+4 4 4 4 4 4
53327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53328+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
53329+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
53330+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
53331+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
53332+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
53333+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
53334+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
53335+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
53336+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
53337+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
53338+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
53339+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
53340+4 4 4 4 4 4
53341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53342+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
53343+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
53344+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
53345+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53346+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
53347+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
53348+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
53349+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
53350+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
53351+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
53352+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
53353+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
53354+0 0 0 4 4 4
53355+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53356+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
53357+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
53358+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
53359+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
53360+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
53361+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
53362+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
53363+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
53364+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
53365+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
53366+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
53367+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
53368+2 0 0 0 0 0
53369+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
53370+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
53371+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
53372+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
53373+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
53374+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
53375+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
53376+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
53377+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
53378+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
53379+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
53380+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
53381+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
53382+37 38 37 0 0 0
53383+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53384+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
53385+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
53386+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
53387+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
53388+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
53389+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
53390+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
53391+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
53392+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
53393+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
53394+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
53395+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
53396+85 115 134 4 0 0
53397+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
53398+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
53399+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
53400+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
53401+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
53402+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
53403+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
53404+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
53405+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
53406+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
53407+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
53408+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
53409+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
53410+60 73 81 4 0 0
53411+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
53412+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
53413+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
53414+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
53415+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
53416+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
53417+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
53418+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
53419+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
53420+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
53421+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
53422+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
53423+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
53424+16 19 21 4 0 0
53425+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
53426+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
53427+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
53428+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
53429+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
53430+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
53431+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
53432+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
53433+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
53434+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
53435+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
53436+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
53437+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
53438+4 0 0 4 3 3
53439+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
53440+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
53441+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
53442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
53443+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
53444+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
53445+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
53446+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
53447+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
53448+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
53449+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
53450+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
53451+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
53452+3 2 2 4 4 4
53453+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
53454+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
53455+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
53456+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53457+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
53458+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
53459+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
53460+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
53461+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
53462+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
53463+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
53464+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
53465+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
53466+4 4 4 4 4 4
53467+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
53468+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
53469+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
53470+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
53471+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
53472+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
53473+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
53474+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
53475+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
53476+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
53477+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
53478+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
53479+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
53480+4 4 4 4 4 4
53481+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
53482+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
53483+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
53484+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
53485+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
53486+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53487+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
53488+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
53489+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
53490+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
53491+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
53492+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
53493+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
53494+5 5 5 5 5 5
53495+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
53496+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
53497+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
53498+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
53499+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
53500+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53501+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
53502+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
53503+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
53504+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
53505+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
53506+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
53507+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
53508+5 5 5 4 4 4
53509+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
53510+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
53511+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
53512+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
53513+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53514+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
53515+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
53516+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
53517+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
53518+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
53519+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
53520+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53522+4 4 4 4 4 4
53523+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
53524+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
53525+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
53526+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
53527+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
53528+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53529+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53530+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
53531+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
53532+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
53533+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
53534+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
53535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53536+4 4 4 4 4 4
53537+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
53538+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
53539+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
53540+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
53541+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53542+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
53543+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
53544+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
53545+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
53546+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
53547+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
53548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53550+4 4 4 4 4 4
53551+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
53552+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
53553+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
53554+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
53555+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53556+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53557+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53558+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
53559+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
53560+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
53561+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
53562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53564+4 4 4 4 4 4
53565+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
53566+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
53567+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
53568+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
53569+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53570+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
53571+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53572+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
53573+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
53574+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
53575+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53578+4 4 4 4 4 4
53579+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
53580+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
53581+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
53582+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
53583+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53584+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
53585+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
53586+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
53587+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
53588+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
53589+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
53590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53592+4 4 4 4 4 4
53593+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
53594+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
53595+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
53596+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
53597+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53598+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
53599+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
53600+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
53601+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
53602+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
53603+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
53604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53606+4 4 4 4 4 4
53607+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
53608+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
53609+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
53610+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53611+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
53612+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
53613+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
53614+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
53615+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
53616+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
53617+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53620+4 4 4 4 4 4
53621+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
53622+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
53623+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
53624+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53625+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53626+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
53627+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
53628+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
53629+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
53630+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
53631+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53634+4 4 4 4 4 4
53635+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
53636+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
53637+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53638+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53639+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53640+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
53641+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
53642+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
53643+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
53644+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
53645+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53648+4 4 4 4 4 4
53649+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
53650+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
53651+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53652+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53653+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53654+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
53655+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
53656+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
53657+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53658+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53659+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53662+4 4 4 4 4 4
53663+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53664+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
53665+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53666+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
53667+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
53668+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
53669+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
53670+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
53671+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53672+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53673+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53676+4 4 4 4 4 4
53677+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53678+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
53679+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53680+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
53681+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53682+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
53683+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
53684+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
53685+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53686+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53687+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53690+4 4 4 4 4 4
53691+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
53692+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
53693+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53694+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
53695+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
53696+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
53697+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
53698+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
53699+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53700+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53701+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53704+4 4 4 4 4 4
53705+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
53706+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
53707+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53708+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
53709+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
53710+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
53711+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
53712+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
53713+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53714+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53715+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53718+4 4 4 4 4 4
53719+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53720+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
53721+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53722+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
53723+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
53724+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
53725+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
53726+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
53727+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53728+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53729+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53732+4 4 4 4 4 4
53733+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
53734+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
53735+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53736+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
53737+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
53738+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
53739+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
53740+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
53741+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
53742+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53743+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53746+4 4 4 4 4 4
53747+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53748+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
53749+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
53750+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
53751+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
53752+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
53753+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
53754+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
53755+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53756+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53757+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53760+4 4 4 4 4 4
53761+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53762+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
53763+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53764+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
53765+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
53766+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
53767+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
53768+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
53769+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53770+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53771+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53774+4 4 4 4 4 4
53775+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53776+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
53777+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
53778+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
53779+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
53780+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
53781+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53782+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
53783+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53784+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53785+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53788+4 4 4 4 4 4
53789+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53790+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
53791+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
53792+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53793+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
53794+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
53795+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53796+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
53797+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53798+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53799+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53802+4 4 4 4 4 4
53803+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53804+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
53805+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
53806+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
53807+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
53808+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
53809+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
53810+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
53811+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
53812+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53813+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53816+4 4 4 4 4 4
53817+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53818+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
53819+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
53820+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
53821+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
53822+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
53823+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
53824+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
53825+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
53826+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53827+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53830+4 4 4 4 4 4
53831+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
53832+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
53833+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
53834+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
53835+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53836+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
53837+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
53838+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
53839+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
53840+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53841+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53844+4 4 4 4 4 4
53845+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53846+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
53847+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
53848+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
53849+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
53850+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
53851+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
53852+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
53853+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
53854+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53855+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53858+4 4 4 4 4 4
53859+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
53860+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
53861+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
53862+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
53863+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
53864+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
53865+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
53866+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
53867+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
53868+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
53869+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53872+4 4 4 4 4 4
53873+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
53874+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
53875+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
53876+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
53877+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
53878+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
53879+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
53880+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
53881+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
53882+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
53883+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53886+4 4 4 4 4 4
53887+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
53888+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
53889+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
53890+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
53891+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
53892+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
53893+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53894+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
53895+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
53896+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
53897+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53900+4 4 4 4 4 4
53901+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
53902+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
53903+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
53904+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
53905+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
53906+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
53907+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
53908+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
53909+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
53910+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
53911+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53914+4 4 4 4 4 4
53915+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
53916+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
53917+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
53918+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
53919+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
53920+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
53921+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
53922+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
53923+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
53924+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
53925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53928+4 4 4 4 4 4
53929+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
53930+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
53931+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
53932+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
53933+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
53934+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
53935+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
53936+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
53937+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
53938+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
53939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53942+4 4 4 4 4 4
53943+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
53944+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
53945+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
53946+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
53947+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
53948+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
53949+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
53950+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
53951+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
53952+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53956+4 4 4 4 4 4
53957+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
53958+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
53959+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
53960+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
53961+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
53962+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
53963+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
53964+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
53965+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53966+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53970+4 4 4 4 4 4
53971+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
53972+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
53973+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
53974+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
53975+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
53976+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
53977+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
53978+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
53979+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
53980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53984+4 4 4 4 4 4
53985+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
53986+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
53987+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
53988+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
53989+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
53990+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
53991+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
53992+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
53993+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
53994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53998+4 4 4 4 4 4
53999+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54000+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54001+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54002+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54003+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54004+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54005+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54006+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54007+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54012+4 4 4 4 4 4
54013+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54014+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54015+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54016+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54017+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54018+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54019+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54020+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
54021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54026+4 4 4 4 4 4
54027+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54028+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54029+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54030+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54031+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54032+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54033+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54034+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54040+4 4 4 4 4 4
54041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54042+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54043+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54044+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54045+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54046+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54047+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54048+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54054+4 4 4 4 4 4
54055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54056+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54057+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54058+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54059+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54060+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54061+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54062+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54068+4 4 4 4 4 4
54069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54070+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54071+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54072+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54073+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54074+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54075+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54076+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54082+4 4 4 4 4 4
54083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54085+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54086+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54087+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54088+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54089+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54090+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54096+4 4 4 4 4 4
54097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54100+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54101+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54102+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54103+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54110+4 4 4 4 4 4
54111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54114+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54115+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54116+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54117+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54124+4 4 4 4 4 4
54125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54128+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54129+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54130+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54131+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
54132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54138+4 4 4 4 4 4
54139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54142+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
54143+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
54144+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
54145+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
54146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54152+4 4 4 4 4 4
54153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54157+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
54158+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54159+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54166+4 4 4 4 4 4
54167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54171+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
54172+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
54173+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54180+4 4 4 4 4 4
54181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54185+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
54186+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
54187+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54194+4 4 4 4 4 4
54195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54199+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
54200+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
54201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54208+4 4 4 4 4 4
54209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54213+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54214+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
54215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54222+4 4 4 4 4 4
54223diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
54224index a01147f..5d896f8 100644
54225--- a/drivers/video/matrox/matroxfb_DAC1064.c
54226+++ b/drivers/video/matrox/matroxfb_DAC1064.c
54227@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54228
54229 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54230 struct matrox_switch matrox_mystique = {
54231- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54232+ .preinit = MGA1064_preinit,
54233+ .reset = MGA1064_reset,
54234+ .init = MGA1064_init,
54235+ .restore = MGA1064_restore,
54236 };
54237 EXPORT_SYMBOL(matrox_mystique);
54238 #endif
54239
54240 #ifdef CONFIG_FB_MATROX_G
54241 struct matrox_switch matrox_G100 = {
54242- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54243+ .preinit = MGAG100_preinit,
54244+ .reset = MGAG100_reset,
54245+ .init = MGAG100_init,
54246+ .restore = MGAG100_restore,
54247 };
54248 EXPORT_SYMBOL(matrox_G100);
54249 #endif
54250diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
54251index 195ad7c..09743fc 100644
54252--- a/drivers/video/matrox/matroxfb_Ti3026.c
54253+++ b/drivers/video/matrox/matroxfb_Ti3026.c
54254@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54255 }
54256
54257 struct matrox_switch matrox_millennium = {
54258- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54259+ .preinit = Ti3026_preinit,
54260+ .reset = Ti3026_reset,
54261+ .init = Ti3026_init,
54262+ .restore = Ti3026_restore
54263 };
54264 EXPORT_SYMBOL(matrox_millennium);
54265 #endif
54266diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
54267index fe92eed..106e085 100644
54268--- a/drivers/video/mb862xx/mb862xxfb_accel.c
54269+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
54270@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54271 struct mb862xxfb_par *par = info->par;
54272
54273 if (info->var.bits_per_pixel == 32) {
54274- info->fbops->fb_fillrect = cfb_fillrect;
54275- info->fbops->fb_copyarea = cfb_copyarea;
54276- info->fbops->fb_imageblit = cfb_imageblit;
54277+ pax_open_kernel();
54278+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54279+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54280+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54281+ pax_close_kernel();
54282 } else {
54283 outreg(disp, GC_L0EM, 3);
54284- info->fbops->fb_fillrect = mb86290fb_fillrect;
54285- info->fbops->fb_copyarea = mb86290fb_copyarea;
54286- info->fbops->fb_imageblit = mb86290fb_imageblit;
54287+ pax_open_kernel();
54288+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54289+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54290+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54291+ pax_close_kernel();
54292 }
54293 outreg(draw, GDC_REG_DRAW_BASE, 0);
54294 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54295diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
54296index ff22871..b129bed 100644
54297--- a/drivers/video/nvidia/nvidia.c
54298+++ b/drivers/video/nvidia/nvidia.c
54299@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54300 info->fix.line_length = (info->var.xres_virtual *
54301 info->var.bits_per_pixel) >> 3;
54302 if (info->var.accel_flags) {
54303- info->fbops->fb_imageblit = nvidiafb_imageblit;
54304- info->fbops->fb_fillrect = nvidiafb_fillrect;
54305- info->fbops->fb_copyarea = nvidiafb_copyarea;
54306- info->fbops->fb_sync = nvidiafb_sync;
54307+ pax_open_kernel();
54308+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54309+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54310+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54311+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54312+ pax_close_kernel();
54313 info->pixmap.scan_align = 4;
54314 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54315 info->flags |= FBINFO_READS_FAST;
54316 NVResetGraphics(info);
54317 } else {
54318- info->fbops->fb_imageblit = cfb_imageblit;
54319- info->fbops->fb_fillrect = cfb_fillrect;
54320- info->fbops->fb_copyarea = cfb_copyarea;
54321- info->fbops->fb_sync = NULL;
54322+ pax_open_kernel();
54323+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54324+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54325+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54326+ *(void **)&info->fbops->fb_sync = NULL;
54327+ pax_close_kernel();
54328 info->pixmap.scan_align = 1;
54329 info->flags |= FBINFO_HWACCEL_DISABLED;
54330 info->flags &= ~FBINFO_READS_FAST;
54331@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54332 info->pixmap.size = 8 * 1024;
54333 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54334
54335- if (!hwcur)
54336- info->fbops->fb_cursor = NULL;
54337+ if (!hwcur) {
54338+ pax_open_kernel();
54339+ *(void **)&info->fbops->fb_cursor = NULL;
54340+ pax_close_kernel();
54341+ }
54342
54343 info->var.accel_flags = (!noaccel);
54344
54345diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
54346index 669a81f..e216d76 100644
54347--- a/drivers/video/omap2/dss/display.c
54348+++ b/drivers/video/omap2/dss/display.c
54349@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54350 snprintf(dssdev->alias, sizeof(dssdev->alias),
54351 "display%d", disp_num_counter++);
54352
54353+ pax_open_kernel();
54354 if (drv && drv->get_resolution == NULL)
54355- drv->get_resolution = omapdss_default_get_resolution;
54356+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54357 if (drv && drv->get_recommended_bpp == NULL)
54358- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54359+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54360 if (drv && drv->get_timings == NULL)
54361- drv->get_timings = omapdss_default_get_timings;
54362+ *(void **)&drv->get_timings = omapdss_default_get_timings;
54363+ pax_close_kernel();
54364
54365 mutex_lock(&panel_list_mutex);
54366 list_add_tail(&dssdev->panel_list, &panel_list);
54367diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
54368index 83433cb..71e9b98 100644
54369--- a/drivers/video/s1d13xxxfb.c
54370+++ b/drivers/video/s1d13xxxfb.c
54371@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54372
54373 switch(prod_id) {
54374 case S1D13506_PROD_ID: /* activate acceleration */
54375- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54376- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54377+ pax_open_kernel();
54378+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54379+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54380+ pax_close_kernel();
54381 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54382 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54383 break;
54384diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
54385index d513ed6..90b0de9 100644
54386--- a/drivers/video/smscufx.c
54387+++ b/drivers/video/smscufx.c
54388@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54389 fb_deferred_io_cleanup(info);
54390 kfree(info->fbdefio);
54391 info->fbdefio = NULL;
54392- info->fbops->fb_mmap = ufx_ops_mmap;
54393+ pax_open_kernel();
54394+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54395+ pax_close_kernel();
54396 }
54397
54398 pr_debug("released /dev/fb%d user=%d count=%d",
54399diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
54400index 025f14e..20eb4db 100644
54401--- a/drivers/video/udlfb.c
54402+++ b/drivers/video/udlfb.c
54403@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54404 dlfb_urb_completion(urb);
54405
54406 error:
54407- atomic_add(bytes_sent, &dev->bytes_sent);
54408- atomic_add(bytes_identical, &dev->bytes_identical);
54409- atomic_add(width*height*2, &dev->bytes_rendered);
54410+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54411+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54412+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54413 end_cycles = get_cycles();
54414- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54415+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54416 >> 10)), /* Kcycles */
54417 &dev->cpu_kcycles_used);
54418
54419@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54420 dlfb_urb_completion(urb);
54421
54422 error:
54423- atomic_add(bytes_sent, &dev->bytes_sent);
54424- atomic_add(bytes_identical, &dev->bytes_identical);
54425- atomic_add(bytes_rendered, &dev->bytes_rendered);
54426+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54427+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54428+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54429 end_cycles = get_cycles();
54430- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54431+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54432 >> 10)), /* Kcycles */
54433 &dev->cpu_kcycles_used);
54434 }
54435@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
54436 fb_deferred_io_cleanup(info);
54437 kfree(info->fbdefio);
54438 info->fbdefio = NULL;
54439- info->fbops->fb_mmap = dlfb_ops_mmap;
54440+ pax_open_kernel();
54441+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
54442+ pax_close_kernel();
54443 }
54444
54445 pr_warn("released /dev/fb%d user=%d count=%d\n",
54446@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
54447 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54448 struct dlfb_data *dev = fb_info->par;
54449 return snprintf(buf, PAGE_SIZE, "%u\n",
54450- atomic_read(&dev->bytes_rendered));
54451+ atomic_read_unchecked(&dev->bytes_rendered));
54452 }
54453
54454 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54455@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54456 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54457 struct dlfb_data *dev = fb_info->par;
54458 return snprintf(buf, PAGE_SIZE, "%u\n",
54459- atomic_read(&dev->bytes_identical));
54460+ atomic_read_unchecked(&dev->bytes_identical));
54461 }
54462
54463 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54464@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54465 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54466 struct dlfb_data *dev = fb_info->par;
54467 return snprintf(buf, PAGE_SIZE, "%u\n",
54468- atomic_read(&dev->bytes_sent));
54469+ atomic_read_unchecked(&dev->bytes_sent));
54470 }
54471
54472 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54473@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54474 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54475 struct dlfb_data *dev = fb_info->par;
54476 return snprintf(buf, PAGE_SIZE, "%u\n",
54477- atomic_read(&dev->cpu_kcycles_used));
54478+ atomic_read_unchecked(&dev->cpu_kcycles_used));
54479 }
54480
54481 static ssize_t edid_show(
54482@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
54483 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54484 struct dlfb_data *dev = fb_info->par;
54485
54486- atomic_set(&dev->bytes_rendered, 0);
54487- atomic_set(&dev->bytes_identical, 0);
54488- atomic_set(&dev->bytes_sent, 0);
54489- atomic_set(&dev->cpu_kcycles_used, 0);
54490+ atomic_set_unchecked(&dev->bytes_rendered, 0);
54491+ atomic_set_unchecked(&dev->bytes_identical, 0);
54492+ atomic_set_unchecked(&dev->bytes_sent, 0);
54493+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
54494
54495 return count;
54496 }
54497diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
54498index 256fba7..6e75516 100644
54499--- a/drivers/video/uvesafb.c
54500+++ b/drivers/video/uvesafb.c
54501@@ -19,6 +19,7 @@
54502 #include <linux/io.h>
54503 #include <linux/mutex.h>
54504 #include <linux/slab.h>
54505+#include <linux/moduleloader.h>
54506 #include <video/edid.h>
54507 #include <video/uvesafb.h>
54508 #ifdef CONFIG_X86
54509@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
54510 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
54511 par->pmi_setpal = par->ypan = 0;
54512 } else {
54513+
54514+#ifdef CONFIG_PAX_KERNEXEC
54515+#ifdef CONFIG_MODULES
54516+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
54517+#endif
54518+ if (!par->pmi_code) {
54519+ par->pmi_setpal = par->ypan = 0;
54520+ return 0;
54521+ }
54522+#endif
54523+
54524 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
54525 + task->t.regs.edi);
54526+
54527+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54528+ pax_open_kernel();
54529+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
54530+ pax_close_kernel();
54531+
54532+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
54533+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
54534+#else
54535 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
54536 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
54537+#endif
54538+
54539 printk(KERN_INFO "uvesafb: protected mode interface info at "
54540 "%04x:%04x\n",
54541 (u16)task->t.regs.es, (u16)task->t.regs.edi);
54542@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
54543 par->ypan = ypan;
54544
54545 if (par->pmi_setpal || par->ypan) {
54546+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
54547 if (__supported_pte_mask & _PAGE_NX) {
54548 par->pmi_setpal = par->ypan = 0;
54549 printk(KERN_WARNING "uvesafb: NX protection is active, "
54550 "better not use the PMI.\n");
54551- } else {
54552+ } else
54553+#endif
54554 uvesafb_vbe_getpmi(task, par);
54555- }
54556 }
54557 #else
54558 /* The protected mode interface is not available on non-x86. */
54559@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54560 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
54561
54562 /* Disable blanking if the user requested so. */
54563- if (!blank)
54564- info->fbops->fb_blank = NULL;
54565+ if (!blank) {
54566+ pax_open_kernel();
54567+ *(void **)&info->fbops->fb_blank = NULL;
54568+ pax_close_kernel();
54569+ }
54570
54571 /*
54572 * Find out how much IO memory is required for the mode with
54573@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54574 info->flags = FBINFO_FLAG_DEFAULT |
54575 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
54576
54577- if (!par->ypan)
54578- info->fbops->fb_pan_display = NULL;
54579+ if (!par->ypan) {
54580+ pax_open_kernel();
54581+ *(void **)&info->fbops->fb_pan_display = NULL;
54582+ pax_close_kernel();
54583+ }
54584 }
54585
54586 static void uvesafb_init_mtrr(struct fb_info *info)
54587@@ -1792,6 +1822,11 @@ out_mode:
54588 out:
54589 kfree(par->vbe_modes);
54590
54591+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54592+ if (par->pmi_code)
54593+ module_free_exec(NULL, par->pmi_code);
54594+#endif
54595+
54596 framebuffer_release(info);
54597 return err;
54598 }
54599@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
54600 kfree(par->vbe_modes);
54601 kfree(par->vbe_state_orig);
54602 kfree(par->vbe_state_saved);
54603+
54604+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54605+ if (par->pmi_code)
54606+ module_free_exec(NULL, par->pmi_code);
54607+#endif
54608+
54609 }
54610
54611 framebuffer_release(info);
54612diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
54613index 1c7da3b..56ea0bd 100644
54614--- a/drivers/video/vesafb.c
54615+++ b/drivers/video/vesafb.c
54616@@ -9,6 +9,7 @@
54617 */
54618
54619 #include <linux/module.h>
54620+#include <linux/moduleloader.h>
54621 #include <linux/kernel.h>
54622 #include <linux/errno.h>
54623 #include <linux/string.h>
54624@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
54625 static int vram_total; /* Set total amount of memory */
54626 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
54627 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
54628-static void (*pmi_start)(void) __read_mostly;
54629-static void (*pmi_pal) (void) __read_mostly;
54630+static void (*pmi_start)(void) __read_only;
54631+static void (*pmi_pal) (void) __read_only;
54632 static int depth __read_mostly;
54633 static int vga_compat __read_mostly;
54634 /* --------------------------------------------------------------------- */
54635@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
54636 unsigned int size_remap;
54637 unsigned int size_total;
54638 char *option = NULL;
54639+ void *pmi_code = NULL;
54640
54641 /* ignore error return of fb_get_options */
54642 fb_get_options("vesafb", &option);
54643@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
54644 size_remap = size_total;
54645 vesafb_fix.smem_len = size_remap;
54646
54647-#ifndef __i386__
54648- screen_info.vesapm_seg = 0;
54649-#endif
54650-
54651 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
54652 printk(KERN_WARNING
54653 "vesafb: cannot reserve video memory at 0x%lx\n",
54654@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
54655 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
54656 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
54657
54658+#ifdef __i386__
54659+
54660+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54661+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
54662+ if (!pmi_code)
54663+#elif !defined(CONFIG_PAX_KERNEXEC)
54664+ if (0)
54665+#endif
54666+
54667+#endif
54668+ screen_info.vesapm_seg = 0;
54669+
54670 if (screen_info.vesapm_seg) {
54671- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
54672- screen_info.vesapm_seg,screen_info.vesapm_off);
54673+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
54674+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
54675 }
54676
54677 if (screen_info.vesapm_seg < 0xc000)
54678@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
54679
54680 if (ypan || pmi_setpal) {
54681 unsigned short *pmi_base;
54682+
54683 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
54684- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
54685- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
54686+
54687+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54688+ pax_open_kernel();
54689+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
54690+#else
54691+ pmi_code = pmi_base;
54692+#endif
54693+
54694+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
54695+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
54696+
54697+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54698+ pmi_start = ktva_ktla(pmi_start);
54699+ pmi_pal = ktva_ktla(pmi_pal);
54700+ pax_close_kernel();
54701+#endif
54702+
54703 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
54704 if (pmi_base[3]) {
54705 printk(KERN_INFO "vesafb: pmi: ports = ");
54706@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
54707 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
54708 (ypan ? FBINFO_HWACCEL_YPAN : 0);
54709
54710- if (!ypan)
54711- info->fbops->fb_pan_display = NULL;
54712+ if (!ypan) {
54713+ pax_open_kernel();
54714+ *(void **)&info->fbops->fb_pan_display = NULL;
54715+ pax_close_kernel();
54716+ }
54717
54718 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
54719 err = -ENOMEM;
54720@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
54721 fb_info(info, "%s frame buffer device\n", info->fix.id);
54722 return 0;
54723 err:
54724+
54725+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54726+ module_free_exec(NULL, pmi_code);
54727+#endif
54728+
54729 if (info->screen_base)
54730 iounmap(info->screen_base);
54731 framebuffer_release(info);
54732diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
54733index 88714ae..16c2e11 100644
54734--- a/drivers/video/via/via_clock.h
54735+++ b/drivers/video/via/via_clock.h
54736@@ -56,7 +56,7 @@ struct via_clock {
54737
54738 void (*set_engine_pll_state)(u8 state);
54739 void (*set_engine_pll)(struct via_pll_config config);
54740-};
54741+} __no_const;
54742
54743
54744 static inline u32 get_pll_internal_frequency(u32 ref_freq,
54745diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
54746index fef20db..d28b1ab 100644
54747--- a/drivers/xen/xenfs/xenstored.c
54748+++ b/drivers/xen/xenfs/xenstored.c
54749@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
54750 static int xsd_kva_open(struct inode *inode, struct file *file)
54751 {
54752 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
54753+#ifdef CONFIG_GRKERNSEC_HIDESYM
54754+ NULL);
54755+#else
54756 xen_store_interface);
54757+#endif
54758+
54759 if (!file->private_data)
54760 return -ENOMEM;
54761 return 0;
54762diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
54763index 9ff073f..05cef23 100644
54764--- a/fs/9p/vfs_addr.c
54765+++ b/fs/9p/vfs_addr.c
54766@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
54767
54768 retval = v9fs_file_write_internal(inode,
54769 v9inode->writeback_fid,
54770- (__force const char __user *)buffer,
54771+ (const char __force_user *)buffer,
54772 len, &offset, 0);
54773 if (retval > 0)
54774 retval = 0;
54775diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
54776index 4e65aa9..043dc9a 100644
54777--- a/fs/9p/vfs_inode.c
54778+++ b/fs/9p/vfs_inode.c
54779@@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54780 void
54781 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54782 {
54783- char *s = nd_get_link(nd);
54784+ const char *s = nd_get_link(nd);
54785
54786 p9_debug(P9_DEBUG_VFS, " %s %s\n",
54787 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
54788diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
54789index 370b24c..ff0be7b 100644
54790--- a/fs/Kconfig.binfmt
54791+++ b/fs/Kconfig.binfmt
54792@@ -103,7 +103,7 @@ config HAVE_AOUT
54793
54794 config BINFMT_AOUT
54795 tristate "Kernel support for a.out and ECOFF binaries"
54796- depends on HAVE_AOUT
54797+ depends on HAVE_AOUT && BROKEN
54798 ---help---
54799 A.out (Assembler.OUTput) is a set of formats for libraries and
54800 executables used in the earliest versions of UNIX. Linux used
54801diff --git a/fs/afs/inode.c b/fs/afs/inode.c
54802index ce25d75..dc09eeb 100644
54803--- a/fs/afs/inode.c
54804+++ b/fs/afs/inode.c
54805@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54806 struct afs_vnode *vnode;
54807 struct super_block *sb;
54808 struct inode *inode;
54809- static atomic_t afs_autocell_ino;
54810+ static atomic_unchecked_t afs_autocell_ino;
54811
54812 _enter("{%x:%u},%*.*s,",
54813 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
54814@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54815 data.fid.unique = 0;
54816 data.fid.vnode = 0;
54817
54818- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
54819+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
54820 afs_iget5_autocell_test, afs_iget5_set,
54821 &data);
54822 if (!inode) {
54823diff --git a/fs/aio.c b/fs/aio.c
54824index 062a5f6..e5618e0 100644
54825--- a/fs/aio.c
54826+++ b/fs/aio.c
54827@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
54828 size += sizeof(struct io_event) * nr_events;
54829
54830 nr_pages = PFN_UP(size);
54831- if (nr_pages < 0)
54832+ if (nr_pages <= 0)
54833 return -EINVAL;
54834
54835 file = aio_private_file(ctx, nr_pages);
54836diff --git a/fs/attr.c b/fs/attr.c
54837index 267968d..5dd8f96 100644
54838--- a/fs/attr.c
54839+++ b/fs/attr.c
54840@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
54841 unsigned long limit;
54842
54843 limit = rlimit(RLIMIT_FSIZE);
54844+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
54845 if (limit != RLIM_INFINITY && offset > limit)
54846 goto out_sig;
54847 if (offset > inode->i_sb->s_maxbytes)
54848diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
54849index 689e40d..515cac5 100644
54850--- a/fs/autofs4/waitq.c
54851+++ b/fs/autofs4/waitq.c
54852@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
54853 {
54854 unsigned long sigpipe, flags;
54855 mm_segment_t fs;
54856- const char *data = (const char *)addr;
54857+ const char __user *data = (const char __force_user *)addr;
54858 ssize_t wr = 0;
54859
54860 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
54861@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
54862 return 1;
54863 }
54864
54865+#ifdef CONFIG_GRKERNSEC_HIDESYM
54866+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
54867+#endif
54868+
54869 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
54870 enum autofs_notify notify)
54871 {
54872@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
54873
54874 /* If this is a direct mount request create a dummy name */
54875 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
54876+#ifdef CONFIG_GRKERNSEC_HIDESYM
54877+ /* this name does get written to userland via autofs4_write() */
54878+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
54879+#else
54880 qstr.len = sprintf(name, "%p", dentry);
54881+#endif
54882 else {
54883 qstr.len = autofs4_getpath(sbi, dentry, &name);
54884 if (!qstr.len) {
54885diff --git a/fs/befs/endian.h b/fs/befs/endian.h
54886index 2722387..56059b5 100644
54887--- a/fs/befs/endian.h
54888+++ b/fs/befs/endian.h
54889@@ -11,7 +11,7 @@
54890
54891 #include <asm/byteorder.h>
54892
54893-static inline u64
54894+static inline u64 __intentional_overflow(-1)
54895 fs64_to_cpu(const struct super_block *sb, fs64 n)
54896 {
54897 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54898@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
54899 return (__force fs64)cpu_to_be64(n);
54900 }
54901
54902-static inline u32
54903+static inline u32 __intentional_overflow(-1)
54904 fs32_to_cpu(const struct super_block *sb, fs32 n)
54905 {
54906 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54907@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
54908 return (__force fs32)cpu_to_be32(n);
54909 }
54910
54911-static inline u16
54912+static inline u16 __intentional_overflow(-1)
54913 fs16_to_cpu(const struct super_block *sb, fs16 n)
54914 {
54915 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54916diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
54917index ca0ba15..0fa3257 100644
54918--- a/fs/binfmt_aout.c
54919+++ b/fs/binfmt_aout.c
54920@@ -16,6 +16,7 @@
54921 #include <linux/string.h>
54922 #include <linux/fs.h>
54923 #include <linux/file.h>
54924+#include <linux/security.h>
54925 #include <linux/stat.h>
54926 #include <linux/fcntl.h>
54927 #include <linux/ptrace.h>
54928@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
54929 #endif
54930 # define START_STACK(u) ((void __user *)u.start_stack)
54931
54932+ memset(&dump, 0, sizeof(dump));
54933+
54934 fs = get_fs();
54935 set_fs(KERNEL_DS);
54936 has_dumped = 1;
54937@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
54938
54939 /* If the size of the dump file exceeds the rlimit, then see what would happen
54940 if we wrote the stack, but not the data area. */
54941+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
54942 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
54943 dump.u_dsize = 0;
54944
54945 /* Make sure we have enough room to write the stack and data areas. */
54946+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
54947 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
54948 dump.u_ssize = 0;
54949
54950@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
54951 rlim = rlimit(RLIMIT_DATA);
54952 if (rlim >= RLIM_INFINITY)
54953 rlim = ~0;
54954+
54955+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
54956 if (ex.a_data + ex.a_bss > rlim)
54957 return -ENOMEM;
54958
54959@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
54960
54961 install_exec_creds(bprm);
54962
54963+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54964+ current->mm->pax_flags = 0UL;
54965+#endif
54966+
54967+#ifdef CONFIG_PAX_PAGEEXEC
54968+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
54969+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
54970+
54971+#ifdef CONFIG_PAX_EMUTRAMP
54972+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
54973+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
54974+#endif
54975+
54976+#ifdef CONFIG_PAX_MPROTECT
54977+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
54978+ current->mm->pax_flags |= MF_PAX_MPROTECT;
54979+#endif
54980+
54981+ }
54982+#endif
54983+
54984 if (N_MAGIC(ex) == OMAGIC) {
54985 unsigned long text_addr, map_size;
54986 loff_t pos;
54987@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
54988 }
54989
54990 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
54991- PROT_READ | PROT_WRITE | PROT_EXEC,
54992+ PROT_READ | PROT_WRITE,
54993 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
54994 fd_offset + ex.a_text);
54995 if (error != N_DATADDR(ex)) {
54996diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
54997index 571a423..dbb9c6c 100644
54998--- a/fs/binfmt_elf.c
54999+++ b/fs/binfmt_elf.c
55000@@ -34,6 +34,7 @@
55001 #include <linux/utsname.h>
55002 #include <linux/coredump.h>
55003 #include <linux/sched.h>
55004+#include <linux/xattr.h>
55005 #include <asm/uaccess.h>
55006 #include <asm/param.h>
55007 #include <asm/page.h>
55008@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55009 #define elf_core_dump NULL
55010 #endif
55011
55012+#ifdef CONFIG_PAX_MPROTECT
55013+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55014+#endif
55015+
55016+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55017+static void elf_handle_mmap(struct file *file);
55018+#endif
55019+
55020 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55021 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55022 #else
55023@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55024 .load_binary = load_elf_binary,
55025 .load_shlib = load_elf_library,
55026 .core_dump = elf_core_dump,
55027+
55028+#ifdef CONFIG_PAX_MPROTECT
55029+ .handle_mprotect= elf_handle_mprotect,
55030+#endif
55031+
55032+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55033+ .handle_mmap = elf_handle_mmap,
55034+#endif
55035+
55036 .min_coredump = ELF_EXEC_PAGESIZE,
55037 };
55038
55039@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55040
55041 static int set_brk(unsigned long start, unsigned long end)
55042 {
55043+ unsigned long e = end;
55044+
55045 start = ELF_PAGEALIGN(start);
55046 end = ELF_PAGEALIGN(end);
55047 if (end > start) {
55048@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55049 if (BAD_ADDR(addr))
55050 return addr;
55051 }
55052- current->mm->start_brk = current->mm->brk = end;
55053+ current->mm->start_brk = current->mm->brk = e;
55054 return 0;
55055 }
55056
55057@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55058 elf_addr_t __user *u_rand_bytes;
55059 const char *k_platform = ELF_PLATFORM;
55060 const char *k_base_platform = ELF_BASE_PLATFORM;
55061- unsigned char k_rand_bytes[16];
55062+ u32 k_rand_bytes[4];
55063 int items;
55064 elf_addr_t *elf_info;
55065 int ei_index = 0;
55066 const struct cred *cred = current_cred();
55067 struct vm_area_struct *vma;
55068+ unsigned long saved_auxv[AT_VECTOR_SIZE];
55069
55070 /*
55071 * In some cases (e.g. Hyper-Threading), we want to avoid L1
55072@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55073 * Generate 16 random bytes for userspace PRNG seeding.
55074 */
55075 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
55076- u_rand_bytes = (elf_addr_t __user *)
55077- STACK_ALLOC(p, sizeof(k_rand_bytes));
55078+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
55079+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
55080+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
55081+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
55082+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
55083+ u_rand_bytes = (elf_addr_t __user *) p;
55084 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
55085 return -EFAULT;
55086
55087@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55088 return -EFAULT;
55089 current->mm->env_end = p;
55090
55091+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
55092+
55093 /* Put the elf_info on the stack in the right place. */
55094 sp = (elf_addr_t __user *)envp + 1;
55095- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
55096+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
55097 return -EFAULT;
55098 return 0;
55099 }
55100@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
55101 an ELF header */
55102
55103 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55104- struct file *interpreter, unsigned long *interp_map_addr,
55105- unsigned long no_base)
55106+ struct file *interpreter, unsigned long no_base)
55107 {
55108 struct elf_phdr *elf_phdata;
55109 struct elf_phdr *eppnt;
55110- unsigned long load_addr = 0;
55111+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
55112 int load_addr_set = 0;
55113 unsigned long last_bss = 0, elf_bss = 0;
55114- unsigned long error = ~0UL;
55115+ unsigned long error = -EINVAL;
55116 unsigned long total_size;
55117 int retval, i, size;
55118
55119@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55120 goto out_close;
55121 }
55122
55123+#ifdef CONFIG_PAX_SEGMEXEC
55124+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
55125+ pax_task_size = SEGMEXEC_TASK_SIZE;
55126+#endif
55127+
55128 eppnt = elf_phdata;
55129 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
55130 if (eppnt->p_type == PT_LOAD) {
55131@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55132 map_addr = elf_map(interpreter, load_addr + vaddr,
55133 eppnt, elf_prot, elf_type, total_size);
55134 total_size = 0;
55135- if (!*interp_map_addr)
55136- *interp_map_addr = map_addr;
55137 error = map_addr;
55138 if (BAD_ADDR(map_addr))
55139 goto out_close;
55140@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55141 k = load_addr + eppnt->p_vaddr;
55142 if (BAD_ADDR(k) ||
55143 eppnt->p_filesz > eppnt->p_memsz ||
55144- eppnt->p_memsz > TASK_SIZE ||
55145- TASK_SIZE - eppnt->p_memsz < k) {
55146+ eppnt->p_memsz > pax_task_size ||
55147+ pax_task_size - eppnt->p_memsz < k) {
55148 error = -ENOMEM;
55149 goto out_close;
55150 }
55151@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55152 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
55153
55154 /* Map the last of the bss segment */
55155- error = vm_brk(elf_bss, last_bss - elf_bss);
55156- if (BAD_ADDR(error))
55157- goto out_close;
55158+ if (last_bss > elf_bss) {
55159+ error = vm_brk(elf_bss, last_bss - elf_bss);
55160+ if (BAD_ADDR(error))
55161+ goto out_close;
55162+ }
55163 }
55164
55165 error = load_addr;
55166@@ -538,6 +569,336 @@ out:
55167 return error;
55168 }
55169
55170+#ifdef CONFIG_PAX_PT_PAX_FLAGS
55171+#ifdef CONFIG_PAX_SOFTMODE
55172+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
55173+{
55174+ unsigned long pax_flags = 0UL;
55175+
55176+#ifdef CONFIG_PAX_PAGEEXEC
55177+ if (elf_phdata->p_flags & PF_PAGEEXEC)
55178+ pax_flags |= MF_PAX_PAGEEXEC;
55179+#endif
55180+
55181+#ifdef CONFIG_PAX_SEGMEXEC
55182+ if (elf_phdata->p_flags & PF_SEGMEXEC)
55183+ pax_flags |= MF_PAX_SEGMEXEC;
55184+#endif
55185+
55186+#ifdef CONFIG_PAX_EMUTRAMP
55187+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55188+ pax_flags |= MF_PAX_EMUTRAMP;
55189+#endif
55190+
55191+#ifdef CONFIG_PAX_MPROTECT
55192+ if (elf_phdata->p_flags & PF_MPROTECT)
55193+ pax_flags |= MF_PAX_MPROTECT;
55194+#endif
55195+
55196+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55197+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
55198+ pax_flags |= MF_PAX_RANDMMAP;
55199+#endif
55200+
55201+ return pax_flags;
55202+}
55203+#endif
55204+
55205+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
55206+{
55207+ unsigned long pax_flags = 0UL;
55208+
55209+#ifdef CONFIG_PAX_PAGEEXEC
55210+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
55211+ pax_flags |= MF_PAX_PAGEEXEC;
55212+#endif
55213+
55214+#ifdef CONFIG_PAX_SEGMEXEC
55215+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
55216+ pax_flags |= MF_PAX_SEGMEXEC;
55217+#endif
55218+
55219+#ifdef CONFIG_PAX_EMUTRAMP
55220+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
55221+ pax_flags |= MF_PAX_EMUTRAMP;
55222+#endif
55223+
55224+#ifdef CONFIG_PAX_MPROTECT
55225+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
55226+ pax_flags |= MF_PAX_MPROTECT;
55227+#endif
55228+
55229+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55230+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
55231+ pax_flags |= MF_PAX_RANDMMAP;
55232+#endif
55233+
55234+ return pax_flags;
55235+}
55236+#endif
55237+
55238+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55239+#ifdef CONFIG_PAX_SOFTMODE
55240+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
55241+{
55242+ unsigned long pax_flags = 0UL;
55243+
55244+#ifdef CONFIG_PAX_PAGEEXEC
55245+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
55246+ pax_flags |= MF_PAX_PAGEEXEC;
55247+#endif
55248+
55249+#ifdef CONFIG_PAX_SEGMEXEC
55250+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
55251+ pax_flags |= MF_PAX_SEGMEXEC;
55252+#endif
55253+
55254+#ifdef CONFIG_PAX_EMUTRAMP
55255+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55256+ pax_flags |= MF_PAX_EMUTRAMP;
55257+#endif
55258+
55259+#ifdef CONFIG_PAX_MPROTECT
55260+ if (pax_flags_softmode & MF_PAX_MPROTECT)
55261+ pax_flags |= MF_PAX_MPROTECT;
55262+#endif
55263+
55264+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55265+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
55266+ pax_flags |= MF_PAX_RANDMMAP;
55267+#endif
55268+
55269+ return pax_flags;
55270+}
55271+#endif
55272+
55273+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
55274+{
55275+ unsigned long pax_flags = 0UL;
55276+
55277+#ifdef CONFIG_PAX_PAGEEXEC
55278+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
55279+ pax_flags |= MF_PAX_PAGEEXEC;
55280+#endif
55281+
55282+#ifdef CONFIG_PAX_SEGMEXEC
55283+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
55284+ pax_flags |= MF_PAX_SEGMEXEC;
55285+#endif
55286+
55287+#ifdef CONFIG_PAX_EMUTRAMP
55288+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
55289+ pax_flags |= MF_PAX_EMUTRAMP;
55290+#endif
55291+
55292+#ifdef CONFIG_PAX_MPROTECT
55293+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
55294+ pax_flags |= MF_PAX_MPROTECT;
55295+#endif
55296+
55297+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55298+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
55299+ pax_flags |= MF_PAX_RANDMMAP;
55300+#endif
55301+
55302+ return pax_flags;
55303+}
55304+#endif
55305+
55306+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55307+static unsigned long pax_parse_defaults(void)
55308+{
55309+ unsigned long pax_flags = 0UL;
55310+
55311+#ifdef CONFIG_PAX_SOFTMODE
55312+ if (pax_softmode)
55313+ return pax_flags;
55314+#endif
55315+
55316+#ifdef CONFIG_PAX_PAGEEXEC
55317+ pax_flags |= MF_PAX_PAGEEXEC;
55318+#endif
55319+
55320+#ifdef CONFIG_PAX_SEGMEXEC
55321+ pax_flags |= MF_PAX_SEGMEXEC;
55322+#endif
55323+
55324+#ifdef CONFIG_PAX_MPROTECT
55325+ pax_flags |= MF_PAX_MPROTECT;
55326+#endif
55327+
55328+#ifdef CONFIG_PAX_RANDMMAP
55329+ if (randomize_va_space)
55330+ pax_flags |= MF_PAX_RANDMMAP;
55331+#endif
55332+
55333+ return pax_flags;
55334+}
55335+
55336+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
55337+{
55338+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
55339+
55340+#ifdef CONFIG_PAX_EI_PAX
55341+
55342+#ifdef CONFIG_PAX_SOFTMODE
55343+ if (pax_softmode)
55344+ return pax_flags;
55345+#endif
55346+
55347+ pax_flags = 0UL;
55348+
55349+#ifdef CONFIG_PAX_PAGEEXEC
55350+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
55351+ pax_flags |= MF_PAX_PAGEEXEC;
55352+#endif
55353+
55354+#ifdef CONFIG_PAX_SEGMEXEC
55355+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
55356+ pax_flags |= MF_PAX_SEGMEXEC;
55357+#endif
55358+
55359+#ifdef CONFIG_PAX_EMUTRAMP
55360+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
55361+ pax_flags |= MF_PAX_EMUTRAMP;
55362+#endif
55363+
55364+#ifdef CONFIG_PAX_MPROTECT
55365+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
55366+ pax_flags |= MF_PAX_MPROTECT;
55367+#endif
55368+
55369+#ifdef CONFIG_PAX_ASLR
55370+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
55371+ pax_flags |= MF_PAX_RANDMMAP;
55372+#endif
55373+
55374+#endif
55375+
55376+ return pax_flags;
55377+
55378+}
55379+
55380+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
55381+{
55382+
55383+#ifdef CONFIG_PAX_PT_PAX_FLAGS
55384+ unsigned long i;
55385+
55386+ for (i = 0UL; i < elf_ex->e_phnum; i++)
55387+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
55388+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
55389+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
55390+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
55391+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
55392+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
55393+ return PAX_PARSE_FLAGS_FALLBACK;
55394+
55395+#ifdef CONFIG_PAX_SOFTMODE
55396+ if (pax_softmode)
55397+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
55398+ else
55399+#endif
55400+
55401+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
55402+ break;
55403+ }
55404+#endif
55405+
55406+ return PAX_PARSE_FLAGS_FALLBACK;
55407+}
55408+
55409+static unsigned long pax_parse_xattr_pax(struct file * const file)
55410+{
55411+
55412+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55413+ ssize_t xattr_size, i;
55414+ unsigned char xattr_value[sizeof("pemrs") - 1];
55415+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
55416+
55417+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
55418+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
55419+ return PAX_PARSE_FLAGS_FALLBACK;
55420+
55421+ for (i = 0; i < xattr_size; i++)
55422+ switch (xattr_value[i]) {
55423+ default:
55424+ return PAX_PARSE_FLAGS_FALLBACK;
55425+
55426+#define parse_flag(option1, option2, flag) \
55427+ case option1: \
55428+ if (pax_flags_hardmode & MF_PAX_##flag) \
55429+ return PAX_PARSE_FLAGS_FALLBACK;\
55430+ pax_flags_hardmode |= MF_PAX_##flag; \
55431+ break; \
55432+ case option2: \
55433+ if (pax_flags_softmode & MF_PAX_##flag) \
55434+ return PAX_PARSE_FLAGS_FALLBACK;\
55435+ pax_flags_softmode |= MF_PAX_##flag; \
55436+ break;
55437+
55438+ parse_flag('p', 'P', PAGEEXEC);
55439+ parse_flag('e', 'E', EMUTRAMP);
55440+ parse_flag('m', 'M', MPROTECT);
55441+ parse_flag('r', 'R', RANDMMAP);
55442+ parse_flag('s', 'S', SEGMEXEC);
55443+
55444+#undef parse_flag
55445+ }
55446+
55447+ if (pax_flags_hardmode & pax_flags_softmode)
55448+ return PAX_PARSE_FLAGS_FALLBACK;
55449+
55450+#ifdef CONFIG_PAX_SOFTMODE
55451+ if (pax_softmode)
55452+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
55453+ else
55454+#endif
55455+
55456+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
55457+#else
55458+ return PAX_PARSE_FLAGS_FALLBACK;
55459+#endif
55460+
55461+}
55462+
55463+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
55464+{
55465+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
55466+
55467+ pax_flags = pax_parse_defaults();
55468+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
55469+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
55470+ xattr_pax_flags = pax_parse_xattr_pax(file);
55471+
55472+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55473+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55474+ pt_pax_flags != xattr_pax_flags)
55475+ return -EINVAL;
55476+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55477+ pax_flags = xattr_pax_flags;
55478+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55479+ pax_flags = pt_pax_flags;
55480+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55481+ pax_flags = ei_pax_flags;
55482+
55483+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
55484+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55485+ if ((__supported_pte_mask & _PAGE_NX))
55486+ pax_flags &= ~MF_PAX_SEGMEXEC;
55487+ else
55488+ pax_flags &= ~MF_PAX_PAGEEXEC;
55489+ }
55490+#endif
55491+
55492+ if (0 > pax_check_flags(&pax_flags))
55493+ return -EINVAL;
55494+
55495+ current->mm->pax_flags = pax_flags;
55496+ return 0;
55497+}
55498+#endif
55499+
55500 /*
55501 * These are the functions used to load ELF style executables and shared
55502 * libraries. There is no binary dependent code anywhere else.
55503@@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
55504 {
55505 unsigned int random_variable = 0;
55506
55507+#ifdef CONFIG_PAX_RANDUSTACK
55508+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
55509+ return stack_top - current->mm->delta_stack;
55510+#endif
55511+
55512 if ((current->flags & PF_RANDOMIZE) &&
55513 !(current->personality & ADDR_NO_RANDOMIZE)) {
55514 random_variable = get_random_int() & STACK_RND_MASK;
55515@@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
55516 unsigned long load_addr = 0, load_bias = 0;
55517 int load_addr_set = 0;
55518 char * elf_interpreter = NULL;
55519- unsigned long error;
55520+ unsigned long error = 0;
55521 struct elf_phdr *elf_ppnt, *elf_phdata;
55522 unsigned long elf_bss, elf_brk;
55523 int retval, i;
55524@@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
55525 unsigned long start_code, end_code, start_data, end_data;
55526 unsigned long reloc_func_desc __maybe_unused = 0;
55527 int executable_stack = EXSTACK_DEFAULT;
55528- unsigned long def_flags = 0;
55529 struct pt_regs *regs = current_pt_regs();
55530 struct {
55531 struct elfhdr elf_ex;
55532 struct elfhdr interp_elf_ex;
55533 } *loc;
55534+ unsigned long pax_task_size;
55535
55536 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
55537 if (!loc) {
55538@@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
55539 goto out_free_dentry;
55540
55541 /* OK, This is the point of no return */
55542- current->mm->def_flags = def_flags;
55543+ current->mm->def_flags = 0;
55544
55545 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
55546 may depend on the personality. */
55547 SET_PERSONALITY(loc->elf_ex);
55548+
55549+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55550+ current->mm->pax_flags = 0UL;
55551+#endif
55552+
55553+#ifdef CONFIG_PAX_DLRESOLVE
55554+ current->mm->call_dl_resolve = 0UL;
55555+#endif
55556+
55557+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
55558+ current->mm->call_syscall = 0UL;
55559+#endif
55560+
55561+#ifdef CONFIG_PAX_ASLR
55562+ current->mm->delta_mmap = 0UL;
55563+ current->mm->delta_stack = 0UL;
55564+#endif
55565+
55566+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55567+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
55568+ send_sig(SIGKILL, current, 0);
55569+ goto out_free_dentry;
55570+ }
55571+#endif
55572+
55573+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55574+ pax_set_initial_flags(bprm);
55575+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
55576+ if (pax_set_initial_flags_func)
55577+ (pax_set_initial_flags_func)(bprm);
55578+#endif
55579+
55580+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55581+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
55582+ current->mm->context.user_cs_limit = PAGE_SIZE;
55583+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
55584+ }
55585+#endif
55586+
55587+#ifdef CONFIG_PAX_SEGMEXEC
55588+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
55589+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
55590+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
55591+ pax_task_size = SEGMEXEC_TASK_SIZE;
55592+ current->mm->def_flags |= VM_NOHUGEPAGE;
55593+ } else
55594+#endif
55595+
55596+ pax_task_size = TASK_SIZE;
55597+
55598+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
55599+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55600+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
55601+ put_cpu();
55602+ }
55603+#endif
55604+
55605+#ifdef CONFIG_PAX_ASLR
55606+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55607+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
55608+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
55609+ }
55610+#endif
55611+
55612+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55613+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55614+ executable_stack = EXSTACK_DISABLE_X;
55615+ current->personality &= ~READ_IMPLIES_EXEC;
55616+ } else
55617+#endif
55618+
55619 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
55620 current->personality |= READ_IMPLIES_EXEC;
55621
55622@@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
55623 #else
55624 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
55625 #endif
55626+
55627+#ifdef CONFIG_PAX_RANDMMAP
55628+ /* PaX: randomize base address at the default exe base if requested */
55629+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
55630+#ifdef CONFIG_SPARC64
55631+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
55632+#else
55633+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
55634+#endif
55635+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
55636+ elf_flags |= MAP_FIXED;
55637+ }
55638+#endif
55639+
55640 }
55641
55642 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
55643@@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
55644 * allowed task size. Note that p_filesz must always be
55645 * <= p_memsz so it is only necessary to check p_memsz.
55646 */
55647- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55648- elf_ppnt->p_memsz > TASK_SIZE ||
55649- TASK_SIZE - elf_ppnt->p_memsz < k) {
55650+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55651+ elf_ppnt->p_memsz > pax_task_size ||
55652+ pax_task_size - elf_ppnt->p_memsz < k) {
55653 /* set_brk can never work. Avoid overflows. */
55654 send_sig(SIGKILL, current, 0);
55655 retval = -EINVAL;
55656@@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
55657 goto out_free_dentry;
55658 }
55659 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
55660- send_sig(SIGSEGV, current, 0);
55661- retval = -EFAULT; /* Nobody gets to see this, but.. */
55662- goto out_free_dentry;
55663+ /*
55664+ * This bss-zeroing can fail if the ELF
55665+ * file specifies odd protections. So
55666+ * we don't check the return value
55667+ */
55668 }
55669
55670+#ifdef CONFIG_PAX_RANDMMAP
55671+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55672+ unsigned long start, size, flags;
55673+ vm_flags_t vm_flags;
55674+
55675+ start = ELF_PAGEALIGN(elf_brk);
55676+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
55677+ flags = MAP_FIXED | MAP_PRIVATE;
55678+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
55679+
55680+ down_write(&current->mm->mmap_sem);
55681+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
55682+ retval = -ENOMEM;
55683+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
55684+// if (current->personality & ADDR_NO_RANDOMIZE)
55685+// vm_flags |= VM_READ | VM_MAYREAD;
55686+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
55687+ retval = IS_ERR_VALUE(start) ? start : 0;
55688+ }
55689+ up_write(&current->mm->mmap_sem);
55690+ if (retval == 0)
55691+ retval = set_brk(start + size, start + size + PAGE_SIZE);
55692+ if (retval < 0) {
55693+ send_sig(SIGKILL, current, 0);
55694+ goto out_free_dentry;
55695+ }
55696+ }
55697+#endif
55698+
55699 if (elf_interpreter) {
55700- unsigned long interp_map_addr = 0;
55701-
55702 elf_entry = load_elf_interp(&loc->interp_elf_ex,
55703 interpreter,
55704- &interp_map_addr,
55705 load_bias);
55706 if (!IS_ERR((void *)elf_entry)) {
55707 /*
55708@@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
55709 * Decide what to dump of a segment, part, all or none.
55710 */
55711 static unsigned long vma_dump_size(struct vm_area_struct *vma,
55712- unsigned long mm_flags)
55713+ unsigned long mm_flags, long signr)
55714 {
55715 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
55716
55717@@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
55718 if (vma->vm_file == NULL)
55719 return 0;
55720
55721- if (FILTER(MAPPED_PRIVATE))
55722+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
55723 goto whole;
55724
55725 /*
55726@@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
55727 {
55728 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
55729 int i = 0;
55730- do
55731+ do {
55732 i += 2;
55733- while (auxv[i - 2] != AT_NULL);
55734+ } while (auxv[i - 2] != AT_NULL);
55735 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
55736 }
55737
55738@@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
55739 {
55740 mm_segment_t old_fs = get_fs();
55741 set_fs(KERNEL_DS);
55742- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
55743+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
55744 set_fs(old_fs);
55745 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
55746 }
55747@@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
55748 }
55749
55750 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
55751- unsigned long mm_flags)
55752+ struct coredump_params *cprm)
55753 {
55754 struct vm_area_struct *vma;
55755 size_t size = 0;
55756
55757 for (vma = first_vma(current, gate_vma); vma != NULL;
55758 vma = next_vma(vma, gate_vma))
55759- size += vma_dump_size(vma, mm_flags);
55760+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55761 return size;
55762 }
55763
55764@@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55765
55766 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
55767
55768- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
55769+ offset += elf_core_vma_data_size(gate_vma, cprm);
55770 offset += elf_core_extra_data_size();
55771 e_shoff = offset;
55772
55773@@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55774 phdr.p_offset = offset;
55775 phdr.p_vaddr = vma->vm_start;
55776 phdr.p_paddr = 0;
55777- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
55778+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55779 phdr.p_memsz = vma->vm_end - vma->vm_start;
55780 offset += phdr.p_filesz;
55781 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
55782@@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55783 unsigned long addr;
55784 unsigned long end;
55785
55786- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
55787+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55788
55789 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
55790 struct page *page;
55791@@ -2202,6 +2681,167 @@ out:
55792
55793 #endif /* CONFIG_ELF_CORE */
55794
55795+#ifdef CONFIG_PAX_MPROTECT
55796+/* PaX: non-PIC ELF libraries need relocations on their executable segments
55797+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
55798+ * we'll remove VM_MAYWRITE for good on RELRO segments.
55799+ *
55800+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
55801+ * basis because we want to allow the common case and not the special ones.
55802+ */
55803+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
55804+{
55805+ struct elfhdr elf_h;
55806+ struct elf_phdr elf_p;
55807+ unsigned long i;
55808+ unsigned long oldflags;
55809+ bool is_textrel_rw, is_textrel_rx, is_relro;
55810+
55811+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
55812+ return;
55813+
55814+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
55815+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
55816+
55817+#ifdef CONFIG_PAX_ELFRELOCS
55818+ /* possible TEXTREL */
55819+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
55820+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
55821+#else
55822+ is_textrel_rw = false;
55823+ is_textrel_rx = false;
55824+#endif
55825+
55826+ /* possible RELRO */
55827+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
55828+
55829+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
55830+ return;
55831+
55832+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
55833+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
55834+
55835+#ifdef CONFIG_PAX_ETEXECRELOCS
55836+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55837+#else
55838+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
55839+#endif
55840+
55841+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55842+ !elf_check_arch(&elf_h) ||
55843+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
55844+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
55845+ return;
55846+
55847+ for (i = 0UL; i < elf_h.e_phnum; i++) {
55848+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
55849+ return;
55850+ switch (elf_p.p_type) {
55851+ case PT_DYNAMIC:
55852+ if (!is_textrel_rw && !is_textrel_rx)
55853+ continue;
55854+ i = 0UL;
55855+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
55856+ elf_dyn dyn;
55857+
55858+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
55859+ break;
55860+ if (dyn.d_tag == DT_NULL)
55861+ break;
55862+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
55863+ gr_log_textrel(vma);
55864+ if (is_textrel_rw)
55865+ vma->vm_flags |= VM_MAYWRITE;
55866+ else
55867+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
55868+ vma->vm_flags &= ~VM_MAYWRITE;
55869+ break;
55870+ }
55871+ i++;
55872+ }
55873+ is_textrel_rw = false;
55874+ is_textrel_rx = false;
55875+ continue;
55876+
55877+ case PT_GNU_RELRO:
55878+ if (!is_relro)
55879+ continue;
55880+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
55881+ vma->vm_flags &= ~VM_MAYWRITE;
55882+ is_relro = false;
55883+ continue;
55884+
55885+#ifdef CONFIG_PAX_PT_PAX_FLAGS
55886+ case PT_PAX_FLAGS: {
55887+ const char *msg_mprotect = "", *msg_emutramp = "";
55888+ char *buffer_lib, *buffer_exe;
55889+
55890+ if (elf_p.p_flags & PF_NOMPROTECT)
55891+ msg_mprotect = "MPROTECT disabled";
55892+
55893+#ifdef CONFIG_PAX_EMUTRAMP
55894+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
55895+ msg_emutramp = "EMUTRAMP enabled";
55896+#endif
55897+
55898+ if (!msg_mprotect[0] && !msg_emutramp[0])
55899+ continue;
55900+
55901+ if (!printk_ratelimit())
55902+ continue;
55903+
55904+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
55905+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
55906+ if (buffer_lib && buffer_exe) {
55907+ char *path_lib, *path_exe;
55908+
55909+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
55910+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
55911+
55912+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
55913+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
55914+
55915+ }
55916+ free_page((unsigned long)buffer_exe);
55917+ free_page((unsigned long)buffer_lib);
55918+ continue;
55919+ }
55920+#endif
55921+
55922+ }
55923+ }
55924+}
55925+#endif
55926+
55927+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55928+
55929+extern int grsec_enable_log_rwxmaps;
55930+
55931+static void elf_handle_mmap(struct file *file)
55932+{
55933+ struct elfhdr elf_h;
55934+ struct elf_phdr elf_p;
55935+ unsigned long i;
55936+
55937+ if (!grsec_enable_log_rwxmaps)
55938+ return;
55939+
55940+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
55941+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
55942+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
55943+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
55944+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
55945+ return;
55946+
55947+ for (i = 0UL; i < elf_h.e_phnum; i++) {
55948+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
55949+ return;
55950+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
55951+ gr_log_ptgnustack(file);
55952+ }
55953+}
55954+#endif
55955+
55956 static int __init init_elf_binfmt(void)
55957 {
55958 register_binfmt(&elf_format);
55959diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
55960index d50bbe5..af3b649 100644
55961--- a/fs/binfmt_flat.c
55962+++ b/fs/binfmt_flat.c
55963@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
55964 realdatastart = (unsigned long) -ENOMEM;
55965 printk("Unable to allocate RAM for process data, errno %d\n",
55966 (int)-realdatastart);
55967+ down_write(&current->mm->mmap_sem);
55968 vm_munmap(textpos, text_len);
55969+ up_write(&current->mm->mmap_sem);
55970 ret = realdatastart;
55971 goto err;
55972 }
55973@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
55974 }
55975 if (IS_ERR_VALUE(result)) {
55976 printk("Unable to read data+bss, errno %d\n", (int)-result);
55977+ down_write(&current->mm->mmap_sem);
55978 vm_munmap(textpos, text_len);
55979 vm_munmap(realdatastart, len);
55980+ up_write(&current->mm->mmap_sem);
55981 ret = result;
55982 goto err;
55983 }
55984@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
55985 }
55986 if (IS_ERR_VALUE(result)) {
55987 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
55988+ down_write(&current->mm->mmap_sem);
55989 vm_munmap(textpos, text_len + data_len + extra +
55990 MAX_SHARED_LIBS * sizeof(unsigned long));
55991+ up_write(&current->mm->mmap_sem);
55992 ret = result;
55993 goto err;
55994 }
55995diff --git a/fs/bio.c b/fs/bio.c
55996index 33d79a4..c3c9893 100644
55997--- a/fs/bio.c
55998+++ b/fs/bio.c
55999@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56000 /*
56001 * Overflow, abort
56002 */
56003- if (end < start)
56004+ if (end < start || end - start > INT_MAX - nr_pages)
56005 return ERR_PTR(-EINVAL);
56006
56007 nr_pages += end - start;
56008@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56009 /*
56010 * Overflow, abort
56011 */
56012- if (end < start)
56013+ if (end < start || end - start > INT_MAX - nr_pages)
56014 return ERR_PTR(-EINVAL);
56015
56016 nr_pages += end - start;
56017@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56018 const int read = bio_data_dir(bio) == READ;
56019 struct bio_map_data *bmd = bio->bi_private;
56020 int i;
56021- char *p = bmd->sgvecs[0].iov_base;
56022+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56023
56024 bio_for_each_segment_all(bvec, bio, i) {
56025 char *addr = page_address(bvec->bv_page);
56026diff --git a/fs/block_dev.c b/fs/block_dev.c
56027index 1e86823..8e34695 100644
56028--- a/fs/block_dev.c
56029+++ b/fs/block_dev.c
56030@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56031 else if (bdev->bd_contains == bdev)
56032 return true; /* is a whole device which isn't held */
56033
56034- else if (whole->bd_holder == bd_may_claim)
56035+ else if (whole->bd_holder == (void *)bd_may_claim)
56036 return true; /* is a partition of a device that is being partitioned */
56037 else if (whole->bd_holder != NULL)
56038 return false; /* is a partition of a held device */
56039diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56040index 316136b..e7a3a50 100644
56041--- a/fs/btrfs/ctree.c
56042+++ b/fs/btrfs/ctree.c
56043@@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56044 free_extent_buffer(buf);
56045 add_root_to_dirty_list(root);
56046 } else {
56047- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56048- parent_start = parent->start;
56049- else
56050+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56051+ if (parent)
56052+ parent_start = parent->start;
56053+ else
56054+ parent_start = 0;
56055+ } else
56056 parent_start = 0;
56057
56058 WARN_ON(trans->transid != btrfs_header_generation(parent));
56059diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56060index 8d292fb..bc205c2 100644
56061--- a/fs/btrfs/delayed-inode.c
56062+++ b/fs/btrfs/delayed-inode.c
56063@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56064
56065 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56066 {
56067- int seq = atomic_inc_return(&delayed_root->items_seq);
56068+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
56069 if ((atomic_dec_return(&delayed_root->items) <
56070 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
56071 waitqueue_active(&delayed_root->wait))
56072@@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
56073 static int refs_newer(struct btrfs_delayed_root *delayed_root,
56074 int seq, int count)
56075 {
56076- int val = atomic_read(&delayed_root->items_seq);
56077+ int val = atomic_read_unchecked(&delayed_root->items_seq);
56078
56079 if (val < seq || val >= seq + count)
56080 return 1;
56081@@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
56082 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
56083 return;
56084
56085- seq = atomic_read(&delayed_root->items_seq);
56086+ seq = atomic_read_unchecked(&delayed_root->items_seq);
56087
56088 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
56089 int ret;
56090diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
56091index a4b38f9..f86a509 100644
56092--- a/fs/btrfs/delayed-inode.h
56093+++ b/fs/btrfs/delayed-inode.h
56094@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
56095 */
56096 struct list_head prepare_list;
56097 atomic_t items; /* for delayed items */
56098- atomic_t items_seq; /* for delayed items */
56099+ atomic_unchecked_t items_seq; /* for delayed items */
56100 int nodes; /* for delayed nodes */
56101 wait_queue_head_t wait;
56102 };
56103@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
56104 struct btrfs_delayed_root *delayed_root)
56105 {
56106 atomic_set(&delayed_root->items, 0);
56107- atomic_set(&delayed_root->items_seq, 0);
56108+ atomic_set_unchecked(&delayed_root->items_seq, 0);
56109 delayed_root->nodes = 0;
56110 spin_lock_init(&delayed_root->lock);
56111 init_waitqueue_head(&delayed_root->wait);
56112diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
56113index 21da576..3551e09 100644
56114--- a/fs/btrfs/ioctl.c
56115+++ b/fs/btrfs/ioctl.c
56116@@ -3451,9 +3451,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56117 for (i = 0; i < num_types; i++) {
56118 struct btrfs_space_info *tmp;
56119
56120+ /* Don't copy in more than we allocated */
56121 if (!slot_count)
56122 break;
56123
56124+ slot_count--;
56125+
56126 info = NULL;
56127 rcu_read_lock();
56128 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
56129@@ -3475,10 +3478,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56130 memcpy(dest, &space, sizeof(space));
56131 dest++;
56132 space_args.total_spaces++;
56133- slot_count--;
56134 }
56135- if (!slot_count)
56136- break;
56137 }
56138 up_read(&info->groups_sem);
56139 }
56140diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
56141index d71a11d..384e2c4 100644
56142--- a/fs/btrfs/super.c
56143+++ b/fs/btrfs/super.c
56144@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
56145 function, line, errstr);
56146 return;
56147 }
56148- ACCESS_ONCE(trans->transaction->aborted) = errno;
56149+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
56150 /* Wake up anybody who may be waiting on this transaction */
56151 wake_up(&root->fs_info->transaction_wait);
56152 wake_up(&root->fs_info->transaction_blocked_wait);
56153diff --git a/fs/buffer.c b/fs/buffer.c
56154index 6024877..7bd000a 100644
56155--- a/fs/buffer.c
56156+++ b/fs/buffer.c
56157@@ -3426,7 +3426,7 @@ void __init buffer_init(void)
56158 bh_cachep = kmem_cache_create("buffer_head",
56159 sizeof(struct buffer_head), 0,
56160 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
56161- SLAB_MEM_SPREAD),
56162+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
56163 NULL);
56164
56165 /*
56166diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
56167index 622f469..e8d2d55 100644
56168--- a/fs/cachefiles/bind.c
56169+++ b/fs/cachefiles/bind.c
56170@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
56171 args);
56172
56173 /* start by checking things over */
56174- ASSERT(cache->fstop_percent >= 0 &&
56175- cache->fstop_percent < cache->fcull_percent &&
56176+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
56177 cache->fcull_percent < cache->frun_percent &&
56178 cache->frun_percent < 100);
56179
56180- ASSERT(cache->bstop_percent >= 0 &&
56181- cache->bstop_percent < cache->bcull_percent &&
56182+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
56183 cache->bcull_percent < cache->brun_percent &&
56184 cache->brun_percent < 100);
56185
56186diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
56187index 0a1467b..6a53245 100644
56188--- a/fs/cachefiles/daemon.c
56189+++ b/fs/cachefiles/daemon.c
56190@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
56191 if (n > buflen)
56192 return -EMSGSIZE;
56193
56194- if (copy_to_user(_buffer, buffer, n) != 0)
56195+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
56196 return -EFAULT;
56197
56198 return n;
56199@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
56200 if (test_bit(CACHEFILES_DEAD, &cache->flags))
56201 return -EIO;
56202
56203- if (datalen < 0 || datalen > PAGE_SIZE - 1)
56204+ if (datalen > PAGE_SIZE - 1)
56205 return -EOPNOTSUPP;
56206
56207 /* drag the command string into the kernel so we can parse it */
56208@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
56209 if (args[0] != '%' || args[1] != '\0')
56210 return -EINVAL;
56211
56212- if (fstop < 0 || fstop >= cache->fcull_percent)
56213+ if (fstop >= cache->fcull_percent)
56214 return cachefiles_daemon_range_error(cache, args);
56215
56216 cache->fstop_percent = fstop;
56217@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
56218 if (args[0] != '%' || args[1] != '\0')
56219 return -EINVAL;
56220
56221- if (bstop < 0 || bstop >= cache->bcull_percent)
56222+ if (bstop >= cache->bcull_percent)
56223 return cachefiles_daemon_range_error(cache, args);
56224
56225 cache->bstop_percent = bstop;
56226diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
56227index 5349473..d6c0b93 100644
56228--- a/fs/cachefiles/internal.h
56229+++ b/fs/cachefiles/internal.h
56230@@ -59,7 +59,7 @@ struct cachefiles_cache {
56231 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
56232 struct rb_root active_nodes; /* active nodes (can't be culled) */
56233 rwlock_t active_lock; /* lock for active_nodes */
56234- atomic_t gravecounter; /* graveyard uniquifier */
56235+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
56236 unsigned frun_percent; /* when to stop culling (% files) */
56237 unsigned fcull_percent; /* when to start culling (% files) */
56238 unsigned fstop_percent; /* when to stop allocating (% files) */
56239@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
56240 * proc.c
56241 */
56242 #ifdef CONFIG_CACHEFILES_HISTOGRAM
56243-extern atomic_t cachefiles_lookup_histogram[HZ];
56244-extern atomic_t cachefiles_mkdir_histogram[HZ];
56245-extern atomic_t cachefiles_create_histogram[HZ];
56246+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56247+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56248+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
56249
56250 extern int __init cachefiles_proc_init(void);
56251 extern void cachefiles_proc_cleanup(void);
56252 static inline
56253-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
56254+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
56255 {
56256 unsigned long jif = jiffies - start_jif;
56257 if (jif >= HZ)
56258 jif = HZ - 1;
56259- atomic_inc(&histogram[jif]);
56260+ atomic_inc_unchecked(&histogram[jif]);
56261 }
56262
56263 #else
56264diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
56265index ca65f39..48921e3 100644
56266--- a/fs/cachefiles/namei.c
56267+++ b/fs/cachefiles/namei.c
56268@@ -317,7 +317,7 @@ try_again:
56269 /* first step is to make up a grave dentry in the graveyard */
56270 sprintf(nbuffer, "%08x%08x",
56271 (uint32_t) get_seconds(),
56272- (uint32_t) atomic_inc_return(&cache->gravecounter));
56273+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
56274
56275 /* do the multiway lock magic */
56276 trap = lock_rename(cache->graveyard, dir);
56277diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
56278index eccd339..4c1d995 100644
56279--- a/fs/cachefiles/proc.c
56280+++ b/fs/cachefiles/proc.c
56281@@ -14,9 +14,9 @@
56282 #include <linux/seq_file.h>
56283 #include "internal.h"
56284
56285-atomic_t cachefiles_lookup_histogram[HZ];
56286-atomic_t cachefiles_mkdir_histogram[HZ];
56287-atomic_t cachefiles_create_histogram[HZ];
56288+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56289+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56290+atomic_unchecked_t cachefiles_create_histogram[HZ];
56291
56292 /*
56293 * display the latency histogram
56294@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
56295 return 0;
56296 default:
56297 index = (unsigned long) v - 3;
56298- x = atomic_read(&cachefiles_lookup_histogram[index]);
56299- y = atomic_read(&cachefiles_mkdir_histogram[index]);
56300- z = atomic_read(&cachefiles_create_histogram[index]);
56301+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
56302+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
56303+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
56304 if (x == 0 && y == 0 && z == 0)
56305 return 0;
56306
56307diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
56308index ebaff36..7e3ea26 100644
56309--- a/fs/cachefiles/rdwr.c
56310+++ b/fs/cachefiles/rdwr.c
56311@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
56312 old_fs = get_fs();
56313 set_fs(KERNEL_DS);
56314 ret = file->f_op->write(
56315- file, (const void __user *) data, len, &pos);
56316+ file, (const void __force_user *) data, len, &pos);
56317 set_fs(old_fs);
56318 kunmap(page);
56319 file_end_write(file);
56320diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
56321index 2a0bcae..34ec24e 100644
56322--- a/fs/ceph/dir.c
56323+++ b/fs/ceph/dir.c
56324@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
56325 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
56326 struct ceph_mds_client *mdsc = fsc->mdsc;
56327 unsigned frag = fpos_frag(ctx->pos);
56328- int off = fpos_off(ctx->pos);
56329+ unsigned int off = fpos_off(ctx->pos);
56330 int err;
56331 u32 ftype;
56332 struct ceph_mds_reply_info_parsed *rinfo;
56333diff --git a/fs/ceph/super.c b/fs/ceph/super.c
56334index 6a0951e..03fac6d 100644
56335--- a/fs/ceph/super.c
56336+++ b/fs/ceph/super.c
56337@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
56338 /*
56339 * construct our own bdi so we can control readahead, etc.
56340 */
56341-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
56342+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
56343
56344 static int ceph_register_bdi(struct super_block *sb,
56345 struct ceph_fs_client *fsc)
56346@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
56347 default_backing_dev_info.ra_pages;
56348
56349 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
56350- atomic_long_inc_return(&bdi_seq));
56351+ atomic_long_inc_return_unchecked(&bdi_seq));
56352 if (!err)
56353 sb->s_bdi = &fsc->backing_dev_info;
56354 return err;
56355diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
56356index f3ac415..3d2420c 100644
56357--- a/fs/cifs/cifs_debug.c
56358+++ b/fs/cifs/cifs_debug.c
56359@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56360
56361 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
56362 #ifdef CONFIG_CIFS_STATS2
56363- atomic_set(&totBufAllocCount, 0);
56364- atomic_set(&totSmBufAllocCount, 0);
56365+ atomic_set_unchecked(&totBufAllocCount, 0);
56366+ atomic_set_unchecked(&totSmBufAllocCount, 0);
56367 #endif /* CONFIG_CIFS_STATS2 */
56368 spin_lock(&cifs_tcp_ses_lock);
56369 list_for_each(tmp1, &cifs_tcp_ses_list) {
56370@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56371 tcon = list_entry(tmp3,
56372 struct cifs_tcon,
56373 tcon_list);
56374- atomic_set(&tcon->num_smbs_sent, 0);
56375+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
56376 if (server->ops->clear_stats)
56377 server->ops->clear_stats(tcon);
56378 }
56379@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56380 smBufAllocCount.counter, cifs_min_small);
56381 #ifdef CONFIG_CIFS_STATS2
56382 seq_printf(m, "Total Large %d Small %d Allocations\n",
56383- atomic_read(&totBufAllocCount),
56384- atomic_read(&totSmBufAllocCount));
56385+ atomic_read_unchecked(&totBufAllocCount),
56386+ atomic_read_unchecked(&totSmBufAllocCount));
56387 #endif /* CONFIG_CIFS_STATS2 */
56388
56389 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
56390@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56391 if (tcon->need_reconnect)
56392 seq_puts(m, "\tDISCONNECTED ");
56393 seq_printf(m, "\nSMBs: %d",
56394- atomic_read(&tcon->num_smbs_sent));
56395+ atomic_read_unchecked(&tcon->num_smbs_sent));
56396 if (server->ops->print_stats)
56397 server->ops->print_stats(m, tcon);
56398 }
56399diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
56400index 849f613..eae6dec 100644
56401--- a/fs/cifs/cifsfs.c
56402+++ b/fs/cifs/cifsfs.c
56403@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
56404 */
56405 cifs_req_cachep = kmem_cache_create("cifs_request",
56406 CIFSMaxBufSize + max_hdr_size, 0,
56407- SLAB_HWCACHE_ALIGN, NULL);
56408+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
56409 if (cifs_req_cachep == NULL)
56410 return -ENOMEM;
56411
56412@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
56413 efficient to alloc 1 per page off the slab compared to 17K (5page)
56414 alloc of large cifs buffers even when page debugging is on */
56415 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
56416- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
56417+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
56418 NULL);
56419 if (cifs_sm_req_cachep == NULL) {
56420 mempool_destroy(cifs_req_poolp);
56421@@ -1168,8 +1168,8 @@ init_cifs(void)
56422 atomic_set(&bufAllocCount, 0);
56423 atomic_set(&smBufAllocCount, 0);
56424 #ifdef CONFIG_CIFS_STATS2
56425- atomic_set(&totBufAllocCount, 0);
56426- atomic_set(&totSmBufAllocCount, 0);
56427+ atomic_set_unchecked(&totBufAllocCount, 0);
56428+ atomic_set_unchecked(&totSmBufAllocCount, 0);
56429 #endif /* CONFIG_CIFS_STATS2 */
56430
56431 atomic_set(&midCount, 0);
56432diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
56433index f918a99..bb300d5 100644
56434--- a/fs/cifs/cifsglob.h
56435+++ b/fs/cifs/cifsglob.h
56436@@ -787,35 +787,35 @@ struct cifs_tcon {
56437 __u16 Flags; /* optional support bits */
56438 enum statusEnum tidStatus;
56439 #ifdef CONFIG_CIFS_STATS
56440- atomic_t num_smbs_sent;
56441+ atomic_unchecked_t num_smbs_sent;
56442 union {
56443 struct {
56444- atomic_t num_writes;
56445- atomic_t num_reads;
56446- atomic_t num_flushes;
56447- atomic_t num_oplock_brks;
56448- atomic_t num_opens;
56449- atomic_t num_closes;
56450- atomic_t num_deletes;
56451- atomic_t num_mkdirs;
56452- atomic_t num_posixopens;
56453- atomic_t num_posixmkdirs;
56454- atomic_t num_rmdirs;
56455- atomic_t num_renames;
56456- atomic_t num_t2renames;
56457- atomic_t num_ffirst;
56458- atomic_t num_fnext;
56459- atomic_t num_fclose;
56460- atomic_t num_hardlinks;
56461- atomic_t num_symlinks;
56462- atomic_t num_locks;
56463- atomic_t num_acl_get;
56464- atomic_t num_acl_set;
56465+ atomic_unchecked_t num_writes;
56466+ atomic_unchecked_t num_reads;
56467+ atomic_unchecked_t num_flushes;
56468+ atomic_unchecked_t num_oplock_brks;
56469+ atomic_unchecked_t num_opens;
56470+ atomic_unchecked_t num_closes;
56471+ atomic_unchecked_t num_deletes;
56472+ atomic_unchecked_t num_mkdirs;
56473+ atomic_unchecked_t num_posixopens;
56474+ atomic_unchecked_t num_posixmkdirs;
56475+ atomic_unchecked_t num_rmdirs;
56476+ atomic_unchecked_t num_renames;
56477+ atomic_unchecked_t num_t2renames;
56478+ atomic_unchecked_t num_ffirst;
56479+ atomic_unchecked_t num_fnext;
56480+ atomic_unchecked_t num_fclose;
56481+ atomic_unchecked_t num_hardlinks;
56482+ atomic_unchecked_t num_symlinks;
56483+ atomic_unchecked_t num_locks;
56484+ atomic_unchecked_t num_acl_get;
56485+ atomic_unchecked_t num_acl_set;
56486 } cifs_stats;
56487 #ifdef CONFIG_CIFS_SMB2
56488 struct {
56489- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56490- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56491+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56492+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56493 } smb2_stats;
56494 #endif /* CONFIG_CIFS_SMB2 */
56495 } stats;
56496@@ -1145,7 +1145,7 @@ convert_delimiter(char *path, char delim)
56497 }
56498
56499 #ifdef CONFIG_CIFS_STATS
56500-#define cifs_stats_inc atomic_inc
56501+#define cifs_stats_inc atomic_inc_unchecked
56502
56503 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
56504 unsigned int bytes)
56505@@ -1511,8 +1511,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
56506 /* Various Debug counters */
56507 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
56508 #ifdef CONFIG_CIFS_STATS2
56509-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
56510-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
56511+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
56512+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
56513 #endif
56514 GLOBAL_EXTERN atomic_t smBufAllocCount;
56515 GLOBAL_EXTERN atomic_t midCount;
56516diff --git a/fs/cifs/file.c b/fs/cifs/file.c
56517index 5a5a872..92c3210 100644
56518--- a/fs/cifs/file.c
56519+++ b/fs/cifs/file.c
56520@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
56521 index = mapping->writeback_index; /* Start from prev offset */
56522 end = -1;
56523 } else {
56524- index = wbc->range_start >> PAGE_CACHE_SHIFT;
56525- end = wbc->range_end >> PAGE_CACHE_SHIFT;
56526- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
56527+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
56528 range_whole = true;
56529+ index = 0;
56530+ end = ULONG_MAX;
56531+ } else {
56532+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
56533+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
56534+ }
56535 scanned = true;
56536 }
56537 retry:
56538diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
56539index 2f9f379..43f8025 100644
56540--- a/fs/cifs/misc.c
56541+++ b/fs/cifs/misc.c
56542@@ -170,7 +170,7 @@ cifs_buf_get(void)
56543 memset(ret_buf, 0, buf_size + 3);
56544 atomic_inc(&bufAllocCount);
56545 #ifdef CONFIG_CIFS_STATS2
56546- atomic_inc(&totBufAllocCount);
56547+ atomic_inc_unchecked(&totBufAllocCount);
56548 #endif /* CONFIG_CIFS_STATS2 */
56549 }
56550
56551@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
56552 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
56553 atomic_inc(&smBufAllocCount);
56554 #ifdef CONFIG_CIFS_STATS2
56555- atomic_inc(&totSmBufAllocCount);
56556+ atomic_inc_unchecked(&totSmBufAllocCount);
56557 #endif /* CONFIG_CIFS_STATS2 */
56558
56559 }
56560diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
56561index 5f5ba0d..8d6ef7d 100644
56562--- a/fs/cifs/smb1ops.c
56563+++ b/fs/cifs/smb1ops.c
56564@@ -609,27 +609,27 @@ static void
56565 cifs_clear_stats(struct cifs_tcon *tcon)
56566 {
56567 #ifdef CONFIG_CIFS_STATS
56568- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
56569- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
56570- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
56571- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56572- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
56573- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
56574- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56575- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
56576- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
56577- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
56578- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
56579- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
56580- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
56581- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
56582- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
56583- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
56584- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
56585- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
56586- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
56587- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
56588- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
56589+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
56590+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
56591+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
56592+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56593+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
56594+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
56595+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56596+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
56597+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
56598+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
56599+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
56600+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
56601+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
56602+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
56603+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
56604+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
56605+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
56606+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
56607+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
56608+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
56609+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
56610 #endif
56611 }
56612
56613@@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56614 {
56615 #ifdef CONFIG_CIFS_STATS
56616 seq_printf(m, " Oplocks breaks: %d",
56617- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
56618+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
56619 seq_printf(m, "\nReads: %d Bytes: %llu",
56620- atomic_read(&tcon->stats.cifs_stats.num_reads),
56621+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
56622 (long long)(tcon->bytes_read));
56623 seq_printf(m, "\nWrites: %d Bytes: %llu",
56624- atomic_read(&tcon->stats.cifs_stats.num_writes),
56625+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
56626 (long long)(tcon->bytes_written));
56627 seq_printf(m, "\nFlushes: %d",
56628- atomic_read(&tcon->stats.cifs_stats.num_flushes));
56629+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
56630 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
56631- atomic_read(&tcon->stats.cifs_stats.num_locks),
56632- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
56633- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
56634+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
56635+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
56636+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
56637 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
56638- atomic_read(&tcon->stats.cifs_stats.num_opens),
56639- atomic_read(&tcon->stats.cifs_stats.num_closes),
56640- atomic_read(&tcon->stats.cifs_stats.num_deletes));
56641+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
56642+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
56643+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
56644 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
56645- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
56646- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
56647+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
56648+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
56649 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
56650- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
56651- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
56652+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
56653+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
56654 seq_printf(m, "\nRenames: %d T2 Renames %d",
56655- atomic_read(&tcon->stats.cifs_stats.num_renames),
56656- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
56657+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
56658+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
56659 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
56660- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
56661- atomic_read(&tcon->stats.cifs_stats.num_fnext),
56662- atomic_read(&tcon->stats.cifs_stats.num_fclose));
56663+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
56664+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
56665+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
56666 #endif
56667 }
56668
56669diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
56670index 757da3e..07bf1ed 100644
56671--- a/fs/cifs/smb2ops.c
56672+++ b/fs/cifs/smb2ops.c
56673@@ -370,8 +370,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
56674 #ifdef CONFIG_CIFS_STATS
56675 int i;
56676 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
56677- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56678- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56679+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56680+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56681 }
56682 #endif
56683 }
56684@@ -411,65 +411,65 @@ static void
56685 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56686 {
56687 #ifdef CONFIG_CIFS_STATS
56688- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56689- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56690+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56691+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56692 seq_printf(m, "\nNegotiates: %d sent %d failed",
56693- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
56694- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
56695+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
56696+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
56697 seq_printf(m, "\nSessionSetups: %d sent %d failed",
56698- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
56699- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
56700+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
56701+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
56702 seq_printf(m, "\nLogoffs: %d sent %d failed",
56703- atomic_read(&sent[SMB2_LOGOFF_HE]),
56704- atomic_read(&failed[SMB2_LOGOFF_HE]));
56705+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
56706+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
56707 seq_printf(m, "\nTreeConnects: %d sent %d failed",
56708- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
56709- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
56710+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
56711+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
56712 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
56713- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
56714- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
56715+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
56716+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
56717 seq_printf(m, "\nCreates: %d sent %d failed",
56718- atomic_read(&sent[SMB2_CREATE_HE]),
56719- atomic_read(&failed[SMB2_CREATE_HE]));
56720+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
56721+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
56722 seq_printf(m, "\nCloses: %d sent %d failed",
56723- atomic_read(&sent[SMB2_CLOSE_HE]),
56724- atomic_read(&failed[SMB2_CLOSE_HE]));
56725+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
56726+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
56727 seq_printf(m, "\nFlushes: %d sent %d failed",
56728- atomic_read(&sent[SMB2_FLUSH_HE]),
56729- atomic_read(&failed[SMB2_FLUSH_HE]));
56730+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
56731+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
56732 seq_printf(m, "\nReads: %d sent %d failed",
56733- atomic_read(&sent[SMB2_READ_HE]),
56734- atomic_read(&failed[SMB2_READ_HE]));
56735+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
56736+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
56737 seq_printf(m, "\nWrites: %d sent %d failed",
56738- atomic_read(&sent[SMB2_WRITE_HE]),
56739- atomic_read(&failed[SMB2_WRITE_HE]));
56740+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
56741+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
56742 seq_printf(m, "\nLocks: %d sent %d failed",
56743- atomic_read(&sent[SMB2_LOCK_HE]),
56744- atomic_read(&failed[SMB2_LOCK_HE]));
56745+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
56746+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
56747 seq_printf(m, "\nIOCTLs: %d sent %d failed",
56748- atomic_read(&sent[SMB2_IOCTL_HE]),
56749- atomic_read(&failed[SMB2_IOCTL_HE]));
56750+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
56751+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
56752 seq_printf(m, "\nCancels: %d sent %d failed",
56753- atomic_read(&sent[SMB2_CANCEL_HE]),
56754- atomic_read(&failed[SMB2_CANCEL_HE]));
56755+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
56756+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
56757 seq_printf(m, "\nEchos: %d sent %d failed",
56758- atomic_read(&sent[SMB2_ECHO_HE]),
56759- atomic_read(&failed[SMB2_ECHO_HE]));
56760+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
56761+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
56762 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
56763- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
56764- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
56765+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
56766+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
56767 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
56768- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
56769- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
56770+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
56771+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
56772 seq_printf(m, "\nQueryInfos: %d sent %d failed",
56773- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
56774- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
56775+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
56776+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
56777 seq_printf(m, "\nSetInfos: %d sent %d failed",
56778- atomic_read(&sent[SMB2_SET_INFO_HE]),
56779- atomic_read(&failed[SMB2_SET_INFO_HE]));
56780+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
56781+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
56782 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
56783- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
56784- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
56785+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
56786+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
56787 #endif
56788 }
56789
56790diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
56791index 2013234..a720734 100644
56792--- a/fs/cifs/smb2pdu.c
56793+++ b/fs/cifs/smb2pdu.c
56794@@ -2091,8 +2091,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
56795 default:
56796 cifs_dbg(VFS, "info level %u isn't supported\n",
56797 srch_inf->info_level);
56798- rc = -EINVAL;
56799- goto qdir_exit;
56800+ return -EINVAL;
56801 }
56802
56803 req->FileIndex = cpu_to_le32(index);
56804diff --git a/fs/coda/cache.c b/fs/coda/cache.c
56805index 1da168c..8bc7ff6 100644
56806--- a/fs/coda/cache.c
56807+++ b/fs/coda/cache.c
56808@@ -24,7 +24,7 @@
56809 #include "coda_linux.h"
56810 #include "coda_cache.h"
56811
56812-static atomic_t permission_epoch = ATOMIC_INIT(0);
56813+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
56814
56815 /* replace or extend an acl cache hit */
56816 void coda_cache_enter(struct inode *inode, int mask)
56817@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
56818 struct coda_inode_info *cii = ITOC(inode);
56819
56820 spin_lock(&cii->c_lock);
56821- cii->c_cached_epoch = atomic_read(&permission_epoch);
56822+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
56823 if (!uid_eq(cii->c_uid, current_fsuid())) {
56824 cii->c_uid = current_fsuid();
56825 cii->c_cached_perm = mask;
56826@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
56827 {
56828 struct coda_inode_info *cii = ITOC(inode);
56829 spin_lock(&cii->c_lock);
56830- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
56831+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
56832 spin_unlock(&cii->c_lock);
56833 }
56834
56835 /* remove all acl caches */
56836 void coda_cache_clear_all(struct super_block *sb)
56837 {
56838- atomic_inc(&permission_epoch);
56839+ atomic_inc_unchecked(&permission_epoch);
56840 }
56841
56842
56843@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
56844 spin_lock(&cii->c_lock);
56845 hit = (mask & cii->c_cached_perm) == mask &&
56846 uid_eq(cii->c_uid, current_fsuid()) &&
56847- cii->c_cached_epoch == atomic_read(&permission_epoch);
56848+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
56849 spin_unlock(&cii->c_lock);
56850
56851 return hit;
56852diff --git a/fs/compat.c b/fs/compat.c
56853index 6af20de..fec3fbb 100644
56854--- a/fs/compat.c
56855+++ b/fs/compat.c
56856@@ -54,7 +54,7 @@
56857 #include <asm/ioctls.h>
56858 #include "internal.h"
56859
56860-int compat_log = 1;
56861+int compat_log = 0;
56862
56863 int compat_printk(const char *fmt, ...)
56864 {
56865@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
56866
56867 set_fs(KERNEL_DS);
56868 /* The __user pointer cast is valid because of the set_fs() */
56869- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
56870+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
56871 set_fs(oldfs);
56872 /* truncating is ok because it's a user address */
56873 if (!ret)
56874@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
56875 goto out;
56876
56877 ret = -EINVAL;
56878- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
56879+ if (nr_segs > UIO_MAXIOV)
56880 goto out;
56881 if (nr_segs > fast_segs) {
56882 ret = -ENOMEM;
56883@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
56884 struct compat_readdir_callback {
56885 struct dir_context ctx;
56886 struct compat_old_linux_dirent __user *dirent;
56887+ struct file * file;
56888 int result;
56889 };
56890
56891@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
56892 buf->result = -EOVERFLOW;
56893 return -EOVERFLOW;
56894 }
56895+
56896+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56897+ return 0;
56898+
56899 buf->result++;
56900 dirent = buf->dirent;
56901 if (!access_ok(VERIFY_WRITE, dirent,
56902@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
56903 if (!f.file)
56904 return -EBADF;
56905
56906+ buf.file = f.file;
56907 error = iterate_dir(f.file, &buf.ctx);
56908 if (buf.result)
56909 error = buf.result;
56910@@ -901,6 +907,7 @@ struct compat_getdents_callback {
56911 struct dir_context ctx;
56912 struct compat_linux_dirent __user *current_dir;
56913 struct compat_linux_dirent __user *previous;
56914+ struct file * file;
56915 int count;
56916 int error;
56917 };
56918@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
56919 buf->error = -EOVERFLOW;
56920 return -EOVERFLOW;
56921 }
56922+
56923+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56924+ return 0;
56925+
56926 dirent = buf->previous;
56927 if (dirent) {
56928 if (__put_user(offset, &dirent->d_off))
56929@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
56930 if (!f.file)
56931 return -EBADF;
56932
56933+ buf.file = f.file;
56934 error = iterate_dir(f.file, &buf.ctx);
56935 if (error >= 0)
56936 error = buf.error;
56937@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
56938 struct dir_context ctx;
56939 struct linux_dirent64 __user *current_dir;
56940 struct linux_dirent64 __user *previous;
56941+ struct file * file;
56942 int count;
56943 int error;
56944 };
56945@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
56946 buf->error = -EINVAL; /* only used if we fail.. */
56947 if (reclen > buf->count)
56948 return -EINVAL;
56949+
56950+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56951+ return 0;
56952+
56953 dirent = buf->previous;
56954
56955 if (dirent) {
56956@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
56957 if (!f.file)
56958 return -EBADF;
56959
56960+ buf.file = f.file;
56961 error = iterate_dir(f.file, &buf.ctx);
56962 if (error >= 0)
56963 error = buf.error;
56964diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
56965index a81147e..20bf2b5 100644
56966--- a/fs/compat_binfmt_elf.c
56967+++ b/fs/compat_binfmt_elf.c
56968@@ -30,11 +30,13 @@
56969 #undef elf_phdr
56970 #undef elf_shdr
56971 #undef elf_note
56972+#undef elf_dyn
56973 #undef elf_addr_t
56974 #define elfhdr elf32_hdr
56975 #define elf_phdr elf32_phdr
56976 #define elf_shdr elf32_shdr
56977 #define elf_note elf32_note
56978+#define elf_dyn Elf32_Dyn
56979 #define elf_addr_t Elf32_Addr
56980
56981 /*
56982diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
56983index dc52e13..ec61057 100644
56984--- a/fs/compat_ioctl.c
56985+++ b/fs/compat_ioctl.c
56986@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
56987 return -EFAULT;
56988 if (__get_user(udata, &ss32->iomem_base))
56989 return -EFAULT;
56990- ss.iomem_base = compat_ptr(udata);
56991+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
56992 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
56993 __get_user(ss.port_high, &ss32->port_high))
56994 return -EFAULT;
56995@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
56996 for (i = 0; i < nmsgs; i++) {
56997 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
56998 return -EFAULT;
56999- if (get_user(datap, &umsgs[i].buf) ||
57000- put_user(compat_ptr(datap), &tmsgs[i].buf))
57001+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57002+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57003 return -EFAULT;
57004 }
57005 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57006@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
57007 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57008 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57009 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57010- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57011+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57012 return -EFAULT;
57013
57014 return ioctl_preallocate(file, p);
57015@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57016 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57017 {
57018 unsigned int a, b;
57019- a = *(unsigned int *)p;
57020- b = *(unsigned int *)q;
57021+ a = *(const unsigned int *)p;
57022+ b = *(const unsigned int *)q;
57023 if (a > b)
57024 return 1;
57025 if (a < b)
57026diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57027index e081acb..911df21 100644
57028--- a/fs/configfs/dir.c
57029+++ b/fs/configfs/dir.c
57030@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57031 }
57032 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57033 struct configfs_dirent *next;
57034- const char *name;
57035+ const unsigned char * name;
57036+ char d_name[sizeof(next->s_dentry->d_iname)];
57037 int len;
57038 struct inode *inode = NULL;
57039
57040@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57041 continue;
57042
57043 name = configfs_get_name(next);
57044- len = strlen(name);
57045+ if (next->s_dentry && name == next->s_dentry->d_iname) {
57046+ len = next->s_dentry->d_name.len;
57047+ memcpy(d_name, name, len);
57048+ name = d_name;
57049+ } else
57050+ len = strlen(name);
57051
57052 /*
57053 * We'll have a dentry and an inode for
57054diff --git a/fs/coredump.c b/fs/coredump.c
57055index bc3fbcd..6031650 100644
57056--- a/fs/coredump.c
57057+++ b/fs/coredump.c
57058@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
57059 struct pipe_inode_info *pipe = file->private_data;
57060
57061 pipe_lock(pipe);
57062- pipe->readers++;
57063- pipe->writers--;
57064+ atomic_inc(&pipe->readers);
57065+ atomic_dec(&pipe->writers);
57066 wake_up_interruptible_sync(&pipe->wait);
57067 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57068 pipe_unlock(pipe);
57069@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
57070 * We actually want wait_event_freezable() but then we need
57071 * to clear TIF_SIGPENDING and improve dump_interrupted().
57072 */
57073- wait_event_interruptible(pipe->wait, pipe->readers == 1);
57074+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
57075
57076 pipe_lock(pipe);
57077- pipe->readers--;
57078- pipe->writers++;
57079+ atomic_dec(&pipe->readers);
57080+ atomic_inc(&pipe->writers);
57081 pipe_unlock(pipe);
57082 }
57083
57084@@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
57085 struct files_struct *displaced;
57086 bool need_nonrelative = false;
57087 bool core_dumped = false;
57088- static atomic_t core_dump_count = ATOMIC_INIT(0);
57089+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
57090+ long signr = siginfo->si_signo;
57091+ int dumpable;
57092 struct coredump_params cprm = {
57093 .siginfo = siginfo,
57094 .regs = signal_pt_regs(),
57095@@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
57096 .mm_flags = mm->flags,
57097 };
57098
57099- audit_core_dumps(siginfo->si_signo);
57100+ audit_core_dumps(signr);
57101+
57102+ dumpable = __get_dumpable(cprm.mm_flags);
57103+
57104+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
57105+ gr_handle_brute_attach(dumpable);
57106
57107 binfmt = mm->binfmt;
57108 if (!binfmt || !binfmt->core_dump)
57109 goto fail;
57110- if (!__get_dumpable(cprm.mm_flags))
57111+ if (!dumpable)
57112 goto fail;
57113
57114 cred = prepare_creds();
57115@@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
57116 need_nonrelative = true;
57117 }
57118
57119- retval = coredump_wait(siginfo->si_signo, &core_state);
57120+ retval = coredump_wait(signr, &core_state);
57121 if (retval < 0)
57122 goto fail_creds;
57123
57124@@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
57125 }
57126 cprm.limit = RLIM_INFINITY;
57127
57128- dump_count = atomic_inc_return(&core_dump_count);
57129+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
57130 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
57131 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
57132 task_tgid_vnr(current), current->comm);
57133@@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
57134 } else {
57135 struct inode *inode;
57136
57137+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
57138+
57139 if (cprm.limit < binfmt->min_coredump)
57140 goto fail_unlock;
57141
57142@@ -669,7 +678,7 @@ close_fail:
57143 filp_close(cprm.file, NULL);
57144 fail_dropcount:
57145 if (ispipe)
57146- atomic_dec(&core_dump_count);
57147+ atomic_dec_unchecked(&core_dump_count);
57148 fail_unlock:
57149 kfree(cn.corename);
57150 coredump_finish(mm, core_dumped);
57151@@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
57152 struct file *file = cprm->file;
57153 loff_t pos = file->f_pos;
57154 ssize_t n;
57155+
57156+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
57157 if (cprm->written + nr > cprm->limit)
57158 return 0;
57159 while (nr) {
57160diff --git a/fs/dcache.c b/fs/dcache.c
57161index cb4a106..b75581f 100644
57162--- a/fs/dcache.c
57163+++ b/fs/dcache.c
57164@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
57165 */
57166 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
57167 if (name->len > DNAME_INLINE_LEN-1) {
57168- dname = kmalloc(name->len + 1, GFP_KERNEL);
57169+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
57170 if (!dname) {
57171 kmem_cache_free(dentry_cache, dentry);
57172 return NULL;
57173@@ -3429,7 +3429,8 @@ void __init vfs_caches_init(unsigned long mempages)
57174 mempages -= reserve;
57175
57176 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
57177- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
57178+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
57179+ SLAB_NO_SANITIZE, NULL);
57180
57181 dcache_init();
57182 inode_init();
57183diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
57184index 9c0444c..628490c 100644
57185--- a/fs/debugfs/inode.c
57186+++ b/fs/debugfs/inode.c
57187@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
57188 */
57189 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
57190 {
57191+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
57192+ return __create_file(name, S_IFDIR | S_IRWXU,
57193+#else
57194 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
57195+#endif
57196 parent, NULL, NULL);
57197 }
57198 EXPORT_SYMBOL_GPL(debugfs_create_dir);
57199diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
57200index c36c448..fc96710 100644
57201--- a/fs/ecryptfs/inode.c
57202+++ b/fs/ecryptfs/inode.c
57203@@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
57204 old_fs = get_fs();
57205 set_fs(get_ds());
57206 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
57207- (char __user *)lower_buf,
57208+ (char __force_user *)lower_buf,
57209 PATH_MAX);
57210 set_fs(old_fs);
57211 if (rc < 0)
57212diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
57213index e4141f2..d8263e8 100644
57214--- a/fs/ecryptfs/miscdev.c
57215+++ b/fs/ecryptfs/miscdev.c
57216@@ -304,7 +304,7 @@ check_list:
57217 goto out_unlock_msg_ctx;
57218 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
57219 if (msg_ctx->msg) {
57220- if (copy_to_user(&buf[i], packet_length, packet_length_size))
57221+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
57222 goto out_unlock_msg_ctx;
57223 i += packet_length_size;
57224 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
57225diff --git a/fs/exec.c b/fs/exec.c
57226index 7ea097f..0158d8a 100644
57227--- a/fs/exec.c
57228+++ b/fs/exec.c
57229@@ -55,8 +55,20 @@
57230 #include <linux/pipe_fs_i.h>
57231 #include <linux/oom.h>
57232 #include <linux/compat.h>
57233+#include <linux/random.h>
57234+#include <linux/seq_file.h>
57235+#include <linux/coredump.h>
57236+#include <linux/mman.h>
57237+
57238+#ifdef CONFIG_PAX_REFCOUNT
57239+#include <linux/kallsyms.h>
57240+#include <linux/kdebug.h>
57241+#endif
57242+
57243+#include <trace/events/fs.h>
57244
57245 #include <asm/uaccess.h>
57246+#include <asm/sections.h>
57247 #include <asm/mmu_context.h>
57248 #include <asm/tlb.h>
57249
57250@@ -66,19 +78,34 @@
57251
57252 #include <trace/events/sched.h>
57253
57254+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57255+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
57256+{
57257+ 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");
57258+}
57259+#endif
57260+
57261+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
57262+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
57263+EXPORT_SYMBOL(pax_set_initial_flags_func);
57264+#endif
57265+
57266 int suid_dumpable = 0;
57267
57268 static LIST_HEAD(formats);
57269 static DEFINE_RWLOCK(binfmt_lock);
57270
57271+extern int gr_process_kernel_exec_ban(void);
57272+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
57273+
57274 void __register_binfmt(struct linux_binfmt * fmt, int insert)
57275 {
57276 BUG_ON(!fmt);
57277 if (WARN_ON(!fmt->load_binary))
57278 return;
57279 write_lock(&binfmt_lock);
57280- insert ? list_add(&fmt->lh, &formats) :
57281- list_add_tail(&fmt->lh, &formats);
57282+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
57283+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
57284 write_unlock(&binfmt_lock);
57285 }
57286
57287@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
57288 void unregister_binfmt(struct linux_binfmt * fmt)
57289 {
57290 write_lock(&binfmt_lock);
57291- list_del(&fmt->lh);
57292+ pax_list_del((struct list_head *)&fmt->lh);
57293 write_unlock(&binfmt_lock);
57294 }
57295
57296@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57297 int write)
57298 {
57299 struct page *page;
57300- int ret;
57301
57302-#ifdef CONFIG_STACK_GROWSUP
57303- if (write) {
57304- ret = expand_downwards(bprm->vma, pos);
57305- if (ret < 0)
57306- return NULL;
57307- }
57308-#endif
57309- ret = get_user_pages(current, bprm->mm, pos,
57310- 1, write, 1, &page, NULL);
57311- if (ret <= 0)
57312+ if (0 > expand_downwards(bprm->vma, pos))
57313+ return NULL;
57314+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
57315 return NULL;
57316
57317 if (write) {
57318@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57319 if (size <= ARG_MAX)
57320 return page;
57321
57322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57323+ // only allow 512KB for argv+env on suid/sgid binaries
57324+ // to prevent easy ASLR exhaustion
57325+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
57326+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
57327+ (size > (512 * 1024))) {
57328+ put_page(page);
57329+ return NULL;
57330+ }
57331+#endif
57332+
57333 /*
57334 * Limit to 1/4-th the stack size for the argv+env strings.
57335 * This ensures that:
57336@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57337 vma->vm_end = STACK_TOP_MAX;
57338 vma->vm_start = vma->vm_end - PAGE_SIZE;
57339 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
57340+
57341+#ifdef CONFIG_PAX_SEGMEXEC
57342+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
57343+#endif
57344+
57345 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
57346 INIT_LIST_HEAD(&vma->anon_vma_chain);
57347
57348@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57349 mm->stack_vm = mm->total_vm = 1;
57350 up_write(&mm->mmap_sem);
57351 bprm->p = vma->vm_end - sizeof(void *);
57352+
57353+#ifdef CONFIG_PAX_RANDUSTACK
57354+ if (randomize_va_space)
57355+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
57356+#endif
57357+
57358 return 0;
57359 err:
57360 up_write(&mm->mmap_sem);
57361@@ -397,7 +438,7 @@ struct user_arg_ptr {
57362 } ptr;
57363 };
57364
57365-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57366+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57367 {
57368 const char __user *native;
57369
57370@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57371 compat_uptr_t compat;
57372
57373 if (get_user(compat, argv.ptr.compat + nr))
57374- return ERR_PTR(-EFAULT);
57375+ return (const char __force_user *)ERR_PTR(-EFAULT);
57376
57377 return compat_ptr(compat);
57378 }
57379 #endif
57380
57381 if (get_user(native, argv.ptr.native + nr))
57382- return ERR_PTR(-EFAULT);
57383+ return (const char __force_user *)ERR_PTR(-EFAULT);
57384
57385 return native;
57386 }
57387@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
57388 if (!p)
57389 break;
57390
57391- if (IS_ERR(p))
57392+ if (IS_ERR((const char __force_kernel *)p))
57393 return -EFAULT;
57394
57395 if (i >= max)
57396@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
57397
57398 ret = -EFAULT;
57399 str = get_user_arg_ptr(argv, argc);
57400- if (IS_ERR(str))
57401+ if (IS_ERR((const char __force_kernel *)str))
57402 goto out;
57403
57404 len = strnlen_user(str, MAX_ARG_STRLEN);
57405@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
57406 int r;
57407 mm_segment_t oldfs = get_fs();
57408 struct user_arg_ptr argv = {
57409- .ptr.native = (const char __user *const __user *)__argv,
57410+ .ptr.native = (const char __user * const __force_user *)__argv,
57411 };
57412
57413 set_fs(KERNEL_DS);
57414@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57415 unsigned long new_end = old_end - shift;
57416 struct mmu_gather tlb;
57417
57418- BUG_ON(new_start > new_end);
57419+ if (new_start >= new_end || new_start < mmap_min_addr)
57420+ return -ENOMEM;
57421
57422 /*
57423 * ensure there are no vmas between where we want to go
57424@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57425 if (vma != find_vma(mm, new_start))
57426 return -EFAULT;
57427
57428+#ifdef CONFIG_PAX_SEGMEXEC
57429+ BUG_ON(pax_find_mirror_vma(vma));
57430+#endif
57431+
57432 /*
57433 * cover the whole range: [new_start, old_end)
57434 */
57435@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57436 stack_top = arch_align_stack(stack_top);
57437 stack_top = PAGE_ALIGN(stack_top);
57438
57439- if (unlikely(stack_top < mmap_min_addr) ||
57440- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
57441- return -ENOMEM;
57442-
57443 stack_shift = vma->vm_end - stack_top;
57444
57445 bprm->p -= stack_shift;
57446@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
57447 bprm->exec -= stack_shift;
57448
57449 down_write(&mm->mmap_sem);
57450+
57451+ /* Move stack pages down in memory. */
57452+ if (stack_shift) {
57453+ ret = shift_arg_pages(vma, stack_shift);
57454+ if (ret)
57455+ goto out_unlock;
57456+ }
57457+
57458 vm_flags = VM_STACK_FLAGS;
57459
57460+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57461+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57462+ vm_flags &= ~VM_EXEC;
57463+
57464+#ifdef CONFIG_PAX_MPROTECT
57465+ if (mm->pax_flags & MF_PAX_MPROTECT)
57466+ vm_flags &= ~VM_MAYEXEC;
57467+#endif
57468+
57469+ }
57470+#endif
57471+
57472 /*
57473 * Adjust stack execute permissions; explicitly enable for
57474 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
57475@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57476 goto out_unlock;
57477 BUG_ON(prev != vma);
57478
57479- /* Move stack pages down in memory. */
57480- if (stack_shift) {
57481- ret = shift_arg_pages(vma, stack_shift);
57482- if (ret)
57483- goto out_unlock;
57484- }
57485-
57486 /* mprotect_fixup is overkill to remove the temporary stack flags */
57487 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
57488
57489@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
57490 #endif
57491 current->mm->start_stack = bprm->p;
57492 ret = expand_stack(vma, stack_base);
57493+
57494+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
57495+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
57496+ unsigned long size;
57497+ vm_flags_t vm_flags;
57498+
57499+ size = STACK_TOP - vma->vm_end;
57500+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
57501+
57502+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
57503+
57504+#ifdef CONFIG_X86
57505+ if (!ret) {
57506+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
57507+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
57508+ }
57509+#endif
57510+
57511+ }
57512+#endif
57513+
57514 if (ret)
57515 ret = -EFAULT;
57516
57517@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
57518
57519 fsnotify_open(file);
57520
57521+ trace_open_exec(name);
57522+
57523 err = deny_write_access(file);
57524 if (err)
57525 goto exit;
57526@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
57527 old_fs = get_fs();
57528 set_fs(get_ds());
57529 /* The cast to a user pointer is valid due to the set_fs() */
57530- result = vfs_read(file, (void __user *)addr, count, &pos);
57531+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
57532 set_fs(old_fs);
57533 return result;
57534 }
57535@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
57536 }
57537 rcu_read_unlock();
57538
57539- if (p->fs->users > n_fs) {
57540+ if (atomic_read(&p->fs->users) > n_fs) {
57541 bprm->unsafe |= LSM_UNSAFE_SHARE;
57542 } else {
57543 res = -EAGAIN;
57544@@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
57545 return ret;
57546 }
57547
57548+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57549+static DEFINE_PER_CPU(u64, exec_counter);
57550+static int __init init_exec_counters(void)
57551+{
57552+ unsigned int cpu;
57553+
57554+ for_each_possible_cpu(cpu) {
57555+ per_cpu(exec_counter, cpu) = (u64)cpu;
57556+ }
57557+
57558+ return 0;
57559+}
57560+early_initcall(init_exec_counters);
57561+static inline void increment_exec_counter(void)
57562+{
57563+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
57564+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
57565+}
57566+#else
57567+static inline void increment_exec_counter(void) {}
57568+#endif
57569+
57570+extern void gr_handle_exec_args(struct linux_binprm *bprm,
57571+ struct user_arg_ptr argv);
57572+
57573 /*
57574 * sys_execve() executes a new program.
57575 */
57576@@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
57577 struct user_arg_ptr argv,
57578 struct user_arg_ptr envp)
57579 {
57580+#ifdef CONFIG_GRKERNSEC
57581+ struct file *old_exec_file;
57582+ struct acl_subject_label *old_acl;
57583+ struct rlimit old_rlim[RLIM_NLIMITS];
57584+#endif
57585 struct linux_binprm *bprm;
57586 struct file *file;
57587 struct files_struct *displaced;
57588 bool clear_in_exec;
57589 int retval;
57590
57591+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
57592+
57593 /*
57594 * We move the actual failure in case of RLIMIT_NPROC excess from
57595 * set*uid() to execve() because too many poorly written programs
57596@@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
57597 if (IS_ERR(file))
57598 goto out_unmark;
57599
57600+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
57601+ retval = -EPERM;
57602+ goto out_file;
57603+ }
57604+
57605 sched_exec();
57606
57607 bprm->file = file;
57608 bprm->filename = filename;
57609 bprm->interp = filename;
57610
57611+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
57612+ retval = -EACCES;
57613+ goto out_file;
57614+ }
57615+
57616 retval = bprm_mm_init(bprm);
57617 if (retval)
57618 goto out_file;
57619@@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
57620 if (retval < 0)
57621 goto out;
57622
57623+#ifdef CONFIG_GRKERNSEC
57624+ old_acl = current->acl;
57625+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
57626+ old_exec_file = current->exec_file;
57627+ get_file(file);
57628+ current->exec_file = file;
57629+#endif
57630+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57631+ /* limit suid stack to 8MB
57632+ * we saved the old limits above and will restore them if this exec fails
57633+ */
57634+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
57635+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
57636+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
57637+#endif
57638+
57639+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
57640+ retval = -EPERM;
57641+ goto out_fail;
57642+ }
57643+
57644+ if (!gr_tpe_allow(file)) {
57645+ retval = -EACCES;
57646+ goto out_fail;
57647+ }
57648+
57649+ if (gr_check_crash_exec(file)) {
57650+ retval = -EACCES;
57651+ goto out_fail;
57652+ }
57653+
57654+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
57655+ bprm->unsafe);
57656+ if (retval < 0)
57657+ goto out_fail;
57658+
57659 retval = copy_strings_kernel(1, &bprm->filename, bprm);
57660 if (retval < 0)
57661- goto out;
57662+ goto out_fail;
57663
57664 bprm->exec = bprm->p;
57665 retval = copy_strings(bprm->envc, envp, bprm);
57666 if (retval < 0)
57667- goto out;
57668+ goto out_fail;
57669
57670 retval = copy_strings(bprm->argc, argv, bprm);
57671 if (retval < 0)
57672- goto out;
57673+ goto out_fail;
57674+
57675+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
57676+
57677+ gr_handle_exec_args(bprm, argv);
57678
57679 retval = exec_binprm(bprm);
57680 if (retval < 0)
57681- goto out;
57682+ goto out_fail;
57683+#ifdef CONFIG_GRKERNSEC
57684+ if (old_exec_file)
57685+ fput(old_exec_file);
57686+#endif
57687
57688 /* execve succeeded */
57689+
57690+ increment_exec_counter();
57691 current->fs->in_exec = 0;
57692 current->in_execve = 0;
57693 acct_update_integrals(current);
57694@@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
57695 put_files_struct(displaced);
57696 return retval;
57697
57698+out_fail:
57699+#ifdef CONFIG_GRKERNSEC
57700+ current->acl = old_acl;
57701+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
57702+ fput(current->exec_file);
57703+ current->exec_file = old_exec_file;
57704+#endif
57705+
57706 out:
57707 if (bprm->mm) {
57708 acct_arg_size(bprm, 0);
57709@@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
57710 return error;
57711 }
57712 #endif
57713+
57714+int pax_check_flags(unsigned long *flags)
57715+{
57716+ int retval = 0;
57717+
57718+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
57719+ if (*flags & MF_PAX_SEGMEXEC)
57720+ {
57721+ *flags &= ~MF_PAX_SEGMEXEC;
57722+ retval = -EINVAL;
57723+ }
57724+#endif
57725+
57726+ if ((*flags & MF_PAX_PAGEEXEC)
57727+
57728+#ifdef CONFIG_PAX_PAGEEXEC
57729+ && (*flags & MF_PAX_SEGMEXEC)
57730+#endif
57731+
57732+ )
57733+ {
57734+ *flags &= ~MF_PAX_PAGEEXEC;
57735+ retval = -EINVAL;
57736+ }
57737+
57738+ if ((*flags & MF_PAX_MPROTECT)
57739+
57740+#ifdef CONFIG_PAX_MPROTECT
57741+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57742+#endif
57743+
57744+ )
57745+ {
57746+ *flags &= ~MF_PAX_MPROTECT;
57747+ retval = -EINVAL;
57748+ }
57749+
57750+ if ((*flags & MF_PAX_EMUTRAMP)
57751+
57752+#ifdef CONFIG_PAX_EMUTRAMP
57753+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57754+#endif
57755+
57756+ )
57757+ {
57758+ *flags &= ~MF_PAX_EMUTRAMP;
57759+ retval = -EINVAL;
57760+ }
57761+
57762+ return retval;
57763+}
57764+
57765+EXPORT_SYMBOL(pax_check_flags);
57766+
57767+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57768+char *pax_get_path(const struct path *path, char *buf, int buflen)
57769+{
57770+ char *pathname = d_path(path, buf, buflen);
57771+
57772+ if (IS_ERR(pathname))
57773+ goto toolong;
57774+
57775+ pathname = mangle_path(buf, pathname, "\t\n\\");
57776+ if (!pathname)
57777+ goto toolong;
57778+
57779+ *pathname = 0;
57780+ return buf;
57781+
57782+toolong:
57783+ return "<path too long>";
57784+}
57785+EXPORT_SYMBOL(pax_get_path);
57786+
57787+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
57788+{
57789+ struct task_struct *tsk = current;
57790+ struct mm_struct *mm = current->mm;
57791+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
57792+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
57793+ char *path_exec = NULL;
57794+ char *path_fault = NULL;
57795+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
57796+ siginfo_t info = { };
57797+
57798+ if (buffer_exec && buffer_fault) {
57799+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
57800+
57801+ down_read(&mm->mmap_sem);
57802+ vma = mm->mmap;
57803+ while (vma && (!vma_exec || !vma_fault)) {
57804+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
57805+ vma_exec = vma;
57806+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
57807+ vma_fault = vma;
57808+ vma = vma->vm_next;
57809+ }
57810+ if (vma_exec)
57811+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
57812+ if (vma_fault) {
57813+ start = vma_fault->vm_start;
57814+ end = vma_fault->vm_end;
57815+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
57816+ if (vma_fault->vm_file)
57817+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
57818+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
57819+ path_fault = "<heap>";
57820+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
57821+ path_fault = "<stack>";
57822+ else
57823+ path_fault = "<anonymous mapping>";
57824+ }
57825+ up_read(&mm->mmap_sem);
57826+ }
57827+ if (tsk->signal->curr_ip)
57828+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
57829+ else
57830+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
57831+ 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),
57832+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
57833+ free_page((unsigned long)buffer_exec);
57834+ free_page((unsigned long)buffer_fault);
57835+ pax_report_insns(regs, pc, sp);
57836+ info.si_signo = SIGKILL;
57837+ info.si_errno = 0;
57838+ info.si_code = SI_KERNEL;
57839+ info.si_pid = 0;
57840+ info.si_uid = 0;
57841+ do_coredump(&info);
57842+}
57843+#endif
57844+
57845+#ifdef CONFIG_PAX_REFCOUNT
57846+void pax_report_refcount_overflow(struct pt_regs *regs)
57847+{
57848+ if (current->signal->curr_ip)
57849+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
57850+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
57851+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57852+ else
57853+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
57854+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57855+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
57856+ preempt_disable();
57857+ show_regs(regs);
57858+ preempt_enable();
57859+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
57860+}
57861+#endif
57862+
57863+#ifdef CONFIG_PAX_USERCOPY
57864+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
57865+static noinline int check_stack_object(const void *obj, unsigned long len)
57866+{
57867+ const void * const stack = task_stack_page(current);
57868+ const void * const stackend = stack + THREAD_SIZE;
57869+
57870+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
57871+ const void *frame = NULL;
57872+ const void *oldframe;
57873+#endif
57874+
57875+ if (obj + len < obj)
57876+ return -1;
57877+
57878+ if (obj + len <= stack || stackend <= obj)
57879+ return 0;
57880+
57881+ if (obj < stack || stackend < obj + len)
57882+ return -1;
57883+
57884+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
57885+ oldframe = __builtin_frame_address(1);
57886+ if (oldframe)
57887+ frame = __builtin_frame_address(2);
57888+ /*
57889+ low ----------------------------------------------> high
57890+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
57891+ ^----------------^
57892+ allow copies only within here
57893+ */
57894+ while (stack <= frame && frame < stackend) {
57895+ /* if obj + len extends past the last frame, this
57896+ check won't pass and the next frame will be 0,
57897+ causing us to bail out and correctly report
57898+ the copy as invalid
57899+ */
57900+ if (obj + len <= frame)
57901+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
57902+ oldframe = frame;
57903+ frame = *(const void * const *)frame;
57904+ }
57905+ return -1;
57906+#else
57907+ return 1;
57908+#endif
57909+}
57910+
57911+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
57912+{
57913+ if (current->signal->curr_ip)
57914+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
57915+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
57916+ else
57917+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
57918+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
57919+ dump_stack();
57920+ gr_handle_kernel_exploit();
57921+ do_group_exit(SIGKILL);
57922+}
57923+#endif
57924+
57925+#ifdef CONFIG_PAX_USERCOPY
57926+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
57927+{
57928+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
57929+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
57930+#ifdef CONFIG_MODULES
57931+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
57932+#else
57933+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
57934+#endif
57935+
57936+#else
57937+ unsigned long textlow = (unsigned long)_stext;
57938+ unsigned long texthigh = (unsigned long)_etext;
57939+
57940+#ifdef CONFIG_X86_64
57941+ /* check against linear mapping as well */
57942+ if (high > (unsigned long)__va(__pa(textlow)) &&
57943+ low <= (unsigned long)__va(__pa(texthigh)))
57944+ return true;
57945+#endif
57946+
57947+#endif
57948+
57949+ if (high <= textlow || low > texthigh)
57950+ return false;
57951+ else
57952+ return true;
57953+}
57954+#endif
57955+
57956+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
57957+{
57958+
57959+#ifdef CONFIG_PAX_USERCOPY
57960+ const char *type;
57961+
57962+ if (!n)
57963+ return;
57964+
57965+ type = check_heap_object(ptr, n);
57966+ if (!type) {
57967+ int ret = check_stack_object(ptr, n);
57968+ if (ret == 1 || ret == 2)
57969+ return;
57970+ if (ret == 0) {
57971+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
57972+ type = "<kernel text>";
57973+ else
57974+ return;
57975+ } else
57976+ type = "<process stack>";
57977+ }
57978+
57979+ pax_report_usercopy(ptr, n, to_user, type);
57980+#endif
57981+
57982+}
57983+EXPORT_SYMBOL(__check_object_size);
57984+
57985+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
57986+void pax_track_stack(void)
57987+{
57988+ unsigned long sp = (unsigned long)&sp;
57989+ if (sp < current_thread_info()->lowest_stack &&
57990+ sp > (unsigned long)task_stack_page(current))
57991+ current_thread_info()->lowest_stack = sp;
57992+}
57993+EXPORT_SYMBOL(pax_track_stack);
57994+#endif
57995+
57996+#ifdef CONFIG_PAX_SIZE_OVERFLOW
57997+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
57998+{
57999+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58000+ dump_stack();
58001+ do_group_exit(SIGKILL);
58002+}
58003+EXPORT_SYMBOL(report_size_overflow);
58004+#endif
58005diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58006index 9f9992b..8b59411 100644
58007--- a/fs/ext2/balloc.c
58008+++ b/fs/ext2/balloc.c
58009@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58010
58011 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58012 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58013- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58014+ if (free_blocks < root_blocks + 1 &&
58015 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58016 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58017- !in_group_p (sbi->s_resgid))) {
58018+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58019 return 0;
58020 }
58021 return 1;
58022diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58023index 2d7557d..14e38f94 100644
58024--- a/fs/ext2/xattr.c
58025+++ b/fs/ext2/xattr.c
58026@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58027 struct buffer_head *bh = NULL;
58028 struct ext2_xattr_entry *entry;
58029 char *end;
58030- size_t rest = buffer_size;
58031+ size_t rest = buffer_size, total_size = 0;
58032 int error;
58033
58034 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58035@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58036 buffer += size;
58037 }
58038 rest -= size;
58039+ total_size += size;
58040 }
58041 }
58042- error = buffer_size - rest; /* total size */
58043+ error = total_size;
58044
58045 cleanup:
58046 brelse(bh);
58047diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58048index 22548f5..41521d8 100644
58049--- a/fs/ext3/balloc.c
58050+++ b/fs/ext3/balloc.c
58051@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58052
58053 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58054 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58055- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58056+ if (free_blocks < root_blocks + 1 &&
58057 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58058 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58059- !in_group_p (sbi->s_resgid))) {
58060+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58061 return 0;
58062 }
58063 return 1;
58064diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58065index b1fc963..881228c 100644
58066--- a/fs/ext3/xattr.c
58067+++ b/fs/ext3/xattr.c
58068@@ -330,7 +330,7 @@ static int
58069 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58070 char *buffer, size_t buffer_size)
58071 {
58072- size_t rest = buffer_size;
58073+ size_t rest = buffer_size, total_size = 0;
58074
58075 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
58076 const struct xattr_handler *handler =
58077@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58078 buffer += size;
58079 }
58080 rest -= size;
58081+ total_size += size;
58082 }
58083 }
58084- return buffer_size - rest;
58085+ return total_size;
58086 }
58087
58088 static int
58089diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
58090index 6ea7b14..8fa16d9 100644
58091--- a/fs/ext4/balloc.c
58092+++ b/fs/ext4/balloc.c
58093@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
58094 /* Hm, nope. Are (enough) root reserved clusters available? */
58095 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
58096 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
58097- capable(CAP_SYS_RESOURCE) ||
58098- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
58099+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
58100+ capable_nolog(CAP_SYS_RESOURCE)) {
58101
58102 if (free_clusters >= (nclusters + dirty_clusters +
58103 resv_clusters))
58104diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
58105index ece5556..e39d3a8 100644
58106--- a/fs/ext4/ext4.h
58107+++ b/fs/ext4/ext4.h
58108@@ -1267,19 +1267,19 @@ struct ext4_sb_info {
58109 unsigned long s_mb_last_start;
58110
58111 /* stats for buddy allocator */
58112- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
58113- atomic_t s_bal_success; /* we found long enough chunks */
58114- atomic_t s_bal_allocated; /* in blocks */
58115- atomic_t s_bal_ex_scanned; /* total extents scanned */
58116- atomic_t s_bal_goals; /* goal hits */
58117- atomic_t s_bal_breaks; /* too long searches */
58118- atomic_t s_bal_2orders; /* 2^order hits */
58119+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
58120+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
58121+ atomic_unchecked_t s_bal_allocated; /* in blocks */
58122+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
58123+ atomic_unchecked_t s_bal_goals; /* goal hits */
58124+ atomic_unchecked_t s_bal_breaks; /* too long searches */
58125+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
58126 spinlock_t s_bal_lock;
58127 unsigned long s_mb_buddies_generated;
58128 unsigned long long s_mb_generation_time;
58129- atomic_t s_mb_lost_chunks;
58130- atomic_t s_mb_preallocated;
58131- atomic_t s_mb_discarded;
58132+ atomic_unchecked_t s_mb_lost_chunks;
58133+ atomic_unchecked_t s_mb_preallocated;
58134+ atomic_unchecked_t s_mb_discarded;
58135 atomic_t s_lock_busy;
58136
58137 /* locality groups */
58138diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
58139index 04a5c75..09894fa 100644
58140--- a/fs/ext4/mballoc.c
58141+++ b/fs/ext4/mballoc.c
58142@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
58143 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
58144
58145 if (EXT4_SB(sb)->s_mb_stats)
58146- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
58147+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
58148
58149 break;
58150 }
58151@@ -2189,7 +2189,7 @@ repeat:
58152 ac->ac_status = AC_STATUS_CONTINUE;
58153 ac->ac_flags |= EXT4_MB_HINT_FIRST;
58154 cr = 3;
58155- atomic_inc(&sbi->s_mb_lost_chunks);
58156+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
58157 goto repeat;
58158 }
58159 }
58160@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
58161 if (sbi->s_mb_stats) {
58162 ext4_msg(sb, KERN_INFO,
58163 "mballoc: %u blocks %u reqs (%u success)",
58164- atomic_read(&sbi->s_bal_allocated),
58165- atomic_read(&sbi->s_bal_reqs),
58166- atomic_read(&sbi->s_bal_success));
58167+ atomic_read_unchecked(&sbi->s_bal_allocated),
58168+ atomic_read_unchecked(&sbi->s_bal_reqs),
58169+ atomic_read_unchecked(&sbi->s_bal_success));
58170 ext4_msg(sb, KERN_INFO,
58171 "mballoc: %u extents scanned, %u goal hits, "
58172 "%u 2^N hits, %u breaks, %u lost",
58173- atomic_read(&sbi->s_bal_ex_scanned),
58174- atomic_read(&sbi->s_bal_goals),
58175- atomic_read(&sbi->s_bal_2orders),
58176- atomic_read(&sbi->s_bal_breaks),
58177- atomic_read(&sbi->s_mb_lost_chunks));
58178+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
58179+ atomic_read_unchecked(&sbi->s_bal_goals),
58180+ atomic_read_unchecked(&sbi->s_bal_2orders),
58181+ atomic_read_unchecked(&sbi->s_bal_breaks),
58182+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
58183 ext4_msg(sb, KERN_INFO,
58184 "mballoc: %lu generated and it took %Lu",
58185 sbi->s_mb_buddies_generated,
58186 sbi->s_mb_generation_time);
58187 ext4_msg(sb, KERN_INFO,
58188 "mballoc: %u preallocated, %u discarded",
58189- atomic_read(&sbi->s_mb_preallocated),
58190- atomic_read(&sbi->s_mb_discarded));
58191+ atomic_read_unchecked(&sbi->s_mb_preallocated),
58192+ atomic_read_unchecked(&sbi->s_mb_discarded));
58193 }
58194
58195 free_percpu(sbi->s_locality_groups);
58196@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
58197 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
58198
58199 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
58200- atomic_inc(&sbi->s_bal_reqs);
58201- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58202+ atomic_inc_unchecked(&sbi->s_bal_reqs);
58203+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58204 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
58205- atomic_inc(&sbi->s_bal_success);
58206- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
58207+ atomic_inc_unchecked(&sbi->s_bal_success);
58208+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
58209 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
58210 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
58211- atomic_inc(&sbi->s_bal_goals);
58212+ atomic_inc_unchecked(&sbi->s_bal_goals);
58213 if (ac->ac_found > sbi->s_mb_max_to_scan)
58214- atomic_inc(&sbi->s_bal_breaks);
58215+ atomic_inc_unchecked(&sbi->s_bal_breaks);
58216 }
58217
58218 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
58219@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
58220 trace_ext4_mb_new_inode_pa(ac, pa);
58221
58222 ext4_mb_use_inode_pa(ac, pa);
58223- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
58224+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
58225
58226 ei = EXT4_I(ac->ac_inode);
58227 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58228@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
58229 trace_ext4_mb_new_group_pa(ac, pa);
58230
58231 ext4_mb_use_group_pa(ac, pa);
58232- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58233+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58234
58235 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58236 lg = ac->ac_lg;
58237@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
58238 * from the bitmap and continue.
58239 */
58240 }
58241- atomic_add(free, &sbi->s_mb_discarded);
58242+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
58243
58244 return err;
58245 }
58246@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
58247 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
58248 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
58249 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
58250- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58251+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58252 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
58253
58254 return 0;
58255diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
58256index 04434ad..6404663 100644
58257--- a/fs/ext4/mmp.c
58258+++ b/fs/ext4/mmp.c
58259@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
58260 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
58261 const char *function, unsigned int line, const char *msg)
58262 {
58263- __ext4_warning(sb, function, line, msg);
58264+ __ext4_warning(sb, function, line, "%s", msg);
58265 __ext4_warning(sb, function, line,
58266 "MMP failure info: last update time: %llu, last update "
58267 "node: %s, last update device: %s\n",
58268diff --git a/fs/ext4/super.c b/fs/ext4/super.c
58269index 1f7784d..5d8bbad 100644
58270--- a/fs/ext4/super.c
58271+++ b/fs/ext4/super.c
58272@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
58273 }
58274
58275 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
58276-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58277+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58278 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
58279
58280 #ifdef CONFIG_QUOTA
58281@@ -2450,7 +2450,7 @@ struct ext4_attr {
58282 int offset;
58283 int deprecated_val;
58284 } u;
58285-};
58286+} __do_const;
58287
58288 static int parse_strtoull(const char *buf,
58289 unsigned long long max, unsigned long long *value)
58290diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
58291index 1423c48..9c0c6dc 100644
58292--- a/fs/ext4/xattr.c
58293+++ b/fs/ext4/xattr.c
58294@@ -381,7 +381,7 @@ static int
58295 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58296 char *buffer, size_t buffer_size)
58297 {
58298- size_t rest = buffer_size;
58299+ size_t rest = buffer_size, total_size = 0;
58300
58301 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
58302 const struct xattr_handler *handler =
58303@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58304 buffer += size;
58305 }
58306 rest -= size;
58307+ total_size += size;
58308 }
58309 }
58310- return buffer_size - rest;
58311+ return total_size;
58312 }
58313
58314 static int
58315diff --git a/fs/fcntl.c b/fs/fcntl.c
58316index ef68665..5deacdc 100644
58317--- a/fs/fcntl.c
58318+++ b/fs/fcntl.c
58319@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
58320 if (err)
58321 return err;
58322
58323+ if (gr_handle_chroot_fowner(pid, type))
58324+ return -ENOENT;
58325+ if (gr_check_protected_task_fowner(pid, type))
58326+ return -EACCES;
58327+
58328 f_modown(filp, pid, type, force);
58329 return 0;
58330 }
58331diff --git a/fs/fhandle.c b/fs/fhandle.c
58332index 999ff5c..41f4109 100644
58333--- a/fs/fhandle.c
58334+++ b/fs/fhandle.c
58335@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
58336 } else
58337 retval = 0;
58338 /* copy the mount id */
58339- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
58340- sizeof(*mnt_id)) ||
58341+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
58342 copy_to_user(ufh, handle,
58343 sizeof(struct file_handle) + handle_bytes))
58344 retval = -EFAULT;
58345diff --git a/fs/file.c b/fs/file.c
58346index 4a78f98..f9a6d25 100644
58347--- a/fs/file.c
58348+++ b/fs/file.c
58349@@ -16,6 +16,7 @@
58350 #include <linux/slab.h>
58351 #include <linux/vmalloc.h>
58352 #include <linux/file.h>
58353+#include <linux/security.h>
58354 #include <linux/fdtable.h>
58355 #include <linux/bitops.h>
58356 #include <linux/interrupt.h>
58357@@ -141,7 +142,7 @@ out:
58358 * Return <0 error code on error; 1 on successful completion.
58359 * The files->file_lock should be held on entry, and will be held on exit.
58360 */
58361-static int expand_fdtable(struct files_struct *files, int nr)
58362+static int expand_fdtable(struct files_struct *files, unsigned int nr)
58363 __releases(files->file_lock)
58364 __acquires(files->file_lock)
58365 {
58366@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
58367 * expanded and execution may have blocked.
58368 * The files->file_lock should be held on entry, and will be held on exit.
58369 */
58370-static int expand_files(struct files_struct *files, int nr)
58371+static int expand_files(struct files_struct *files, unsigned int nr)
58372 {
58373 struct fdtable *fdt;
58374
58375@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
58376 if (!file)
58377 return __close_fd(files, fd);
58378
58379+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
58380 if (fd >= rlimit(RLIMIT_NOFILE))
58381 return -EBADF;
58382
58383@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
58384 if (unlikely(oldfd == newfd))
58385 return -EINVAL;
58386
58387+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
58388 if (newfd >= rlimit(RLIMIT_NOFILE))
58389 return -EBADF;
58390
58391@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
58392 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
58393 {
58394 int err;
58395+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
58396 if (from >= rlimit(RLIMIT_NOFILE))
58397 return -EINVAL;
58398 err = alloc_fd(from, flags);
58399diff --git a/fs/filesystems.c b/fs/filesystems.c
58400index 92567d9..fcd8cbf 100644
58401--- a/fs/filesystems.c
58402+++ b/fs/filesystems.c
58403@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
58404 int len = dot ? dot - name : strlen(name);
58405
58406 fs = __get_fs_type(name, len);
58407+#ifdef CONFIG_GRKERNSEC_MODHARDEN
58408+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
58409+#else
58410 if (!fs && (request_module("fs-%.*s", len, name) == 0))
58411+#endif
58412 fs = __get_fs_type(name, len);
58413
58414 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
58415diff --git a/fs/fs_struct.c b/fs/fs_struct.c
58416index 7dca743..543d620 100644
58417--- a/fs/fs_struct.c
58418+++ b/fs/fs_struct.c
58419@@ -4,6 +4,7 @@
58420 #include <linux/path.h>
58421 #include <linux/slab.h>
58422 #include <linux/fs_struct.h>
58423+#include <linux/grsecurity.h>
58424 #include "internal.h"
58425
58426 /*
58427@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
58428 write_seqcount_begin(&fs->seq);
58429 old_root = fs->root;
58430 fs->root = *path;
58431+ gr_set_chroot_entries(current, path);
58432 write_seqcount_end(&fs->seq);
58433 spin_unlock(&fs->lock);
58434 if (old_root.dentry)
58435@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
58436 int hits = 0;
58437 spin_lock(&fs->lock);
58438 write_seqcount_begin(&fs->seq);
58439+ /* this root replacement is only done by pivot_root,
58440+ leave grsec's chroot tagging alone for this task
58441+ so that a pivoted root isn't treated as a chroot
58442+ */
58443 hits += replace_path(&fs->root, old_root, new_root);
58444 hits += replace_path(&fs->pwd, old_root, new_root);
58445 write_seqcount_end(&fs->seq);
58446@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
58447 task_lock(tsk);
58448 spin_lock(&fs->lock);
58449 tsk->fs = NULL;
58450- kill = !--fs->users;
58451+ gr_clear_chroot_entries(tsk);
58452+ kill = !atomic_dec_return(&fs->users);
58453 spin_unlock(&fs->lock);
58454 task_unlock(tsk);
58455 if (kill)
58456@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58457 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
58458 /* We don't need to lock fs - think why ;-) */
58459 if (fs) {
58460- fs->users = 1;
58461+ atomic_set(&fs->users, 1);
58462 fs->in_exec = 0;
58463 spin_lock_init(&fs->lock);
58464 seqcount_init(&fs->seq);
58465@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58466 spin_lock(&old->lock);
58467 fs->root = old->root;
58468 path_get(&fs->root);
58469+ /* instead of calling gr_set_chroot_entries here,
58470+ we call it from every caller of this function
58471+ */
58472 fs->pwd = old->pwd;
58473 path_get(&fs->pwd);
58474 spin_unlock(&old->lock);
58475@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
58476
58477 task_lock(current);
58478 spin_lock(&fs->lock);
58479- kill = !--fs->users;
58480+ kill = !atomic_dec_return(&fs->users);
58481 current->fs = new_fs;
58482+ gr_set_chroot_entries(current, &new_fs->root);
58483 spin_unlock(&fs->lock);
58484 task_unlock(current);
58485
58486@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
58487
58488 int current_umask(void)
58489 {
58490- return current->fs->umask;
58491+ return current->fs->umask | gr_acl_umask();
58492 }
58493 EXPORT_SYMBOL(current_umask);
58494
58495 /* to be mentioned only in INIT_TASK */
58496 struct fs_struct init_fs = {
58497- .users = 1,
58498+ .users = ATOMIC_INIT(1),
58499 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
58500 .seq = SEQCNT_ZERO(init_fs.seq),
58501 .umask = 0022,
58502diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
58503index 29d7feb..303644d 100644
58504--- a/fs/fscache/cookie.c
58505+++ b/fs/fscache/cookie.c
58506@@ -19,7 +19,7 @@
58507
58508 struct kmem_cache *fscache_cookie_jar;
58509
58510-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
58511+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
58512
58513 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
58514 static int fscache_alloc_object(struct fscache_cache *cache,
58515@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
58516 parent ? (char *) parent->def->name : "<no-parent>",
58517 def->name, netfs_data, enable);
58518
58519- fscache_stat(&fscache_n_acquires);
58520+ fscache_stat_unchecked(&fscache_n_acquires);
58521
58522 /* if there's no parent cookie, then we don't create one here either */
58523 if (!parent) {
58524- fscache_stat(&fscache_n_acquires_null);
58525+ fscache_stat_unchecked(&fscache_n_acquires_null);
58526 _leave(" [no parent]");
58527 return NULL;
58528 }
58529@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58530 /* allocate and initialise a cookie */
58531 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
58532 if (!cookie) {
58533- fscache_stat(&fscache_n_acquires_oom);
58534+ fscache_stat_unchecked(&fscache_n_acquires_oom);
58535 _leave(" [ENOMEM]");
58536 return NULL;
58537 }
58538@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
58539
58540 switch (cookie->def->type) {
58541 case FSCACHE_COOKIE_TYPE_INDEX:
58542- fscache_stat(&fscache_n_cookie_index);
58543+ fscache_stat_unchecked(&fscache_n_cookie_index);
58544 break;
58545 case FSCACHE_COOKIE_TYPE_DATAFILE:
58546- fscache_stat(&fscache_n_cookie_data);
58547+ fscache_stat_unchecked(&fscache_n_cookie_data);
58548 break;
58549 default:
58550- fscache_stat(&fscache_n_cookie_special);
58551+ fscache_stat_unchecked(&fscache_n_cookie_special);
58552 break;
58553 }
58554
58555@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58556 } else {
58557 atomic_dec(&parent->n_children);
58558 __fscache_cookie_put(cookie);
58559- fscache_stat(&fscache_n_acquires_nobufs);
58560+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
58561 _leave(" = NULL");
58562 return NULL;
58563 }
58564@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58565 }
58566 }
58567
58568- fscache_stat(&fscache_n_acquires_ok);
58569+ fscache_stat_unchecked(&fscache_n_acquires_ok);
58570 _leave(" = %p", cookie);
58571 return cookie;
58572 }
58573@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
58574 cache = fscache_select_cache_for_object(cookie->parent);
58575 if (!cache) {
58576 up_read(&fscache_addremove_sem);
58577- fscache_stat(&fscache_n_acquires_no_cache);
58578+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
58579 _leave(" = -ENOMEDIUM [no cache]");
58580 return -ENOMEDIUM;
58581 }
58582@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
58583 object = cache->ops->alloc_object(cache, cookie);
58584 fscache_stat_d(&fscache_n_cop_alloc_object);
58585 if (IS_ERR(object)) {
58586- fscache_stat(&fscache_n_object_no_alloc);
58587+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
58588 ret = PTR_ERR(object);
58589 goto error;
58590 }
58591
58592- fscache_stat(&fscache_n_object_alloc);
58593+ fscache_stat_unchecked(&fscache_n_object_alloc);
58594
58595- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
58596+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
58597
58598 _debug("ALLOC OBJ%x: %s {%lx}",
58599 object->debug_id, cookie->def->name, object->events);
58600@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
58601
58602 _enter("{%s}", cookie->def->name);
58603
58604- fscache_stat(&fscache_n_invalidates);
58605+ fscache_stat_unchecked(&fscache_n_invalidates);
58606
58607 /* Only permit invalidation of data files. Invalidating an index will
58608 * require the caller to release all its attachments to the tree rooted
58609@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
58610 {
58611 struct fscache_object *object;
58612
58613- fscache_stat(&fscache_n_updates);
58614+ fscache_stat_unchecked(&fscache_n_updates);
58615
58616 if (!cookie) {
58617- fscache_stat(&fscache_n_updates_null);
58618+ fscache_stat_unchecked(&fscache_n_updates_null);
58619 _leave(" [no cookie]");
58620 return;
58621 }
58622@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
58623 */
58624 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
58625 {
58626- fscache_stat(&fscache_n_relinquishes);
58627+ fscache_stat_unchecked(&fscache_n_relinquishes);
58628 if (retire)
58629- fscache_stat(&fscache_n_relinquishes_retire);
58630+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
58631
58632 if (!cookie) {
58633- fscache_stat(&fscache_n_relinquishes_null);
58634+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
58635 _leave(" [no cookie]");
58636 return;
58637 }
58638@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
58639 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
58640 goto inconsistent;
58641
58642- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58643+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58644
58645 __fscache_use_cookie(cookie);
58646 if (fscache_submit_op(object, op) < 0)
58647diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
58648index 4226f66..0fb3f45 100644
58649--- a/fs/fscache/internal.h
58650+++ b/fs/fscache/internal.h
58651@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
58652 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
58653 extern int fscache_wait_for_operation_activation(struct fscache_object *,
58654 struct fscache_operation *,
58655- atomic_t *,
58656- atomic_t *,
58657+ atomic_unchecked_t *,
58658+ atomic_unchecked_t *,
58659 void (*)(struct fscache_operation *));
58660 extern void fscache_invalidate_writes(struct fscache_cookie *);
58661
58662@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
58663 * stats.c
58664 */
58665 #ifdef CONFIG_FSCACHE_STATS
58666-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58667-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58668+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58669+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58670
58671-extern atomic_t fscache_n_op_pend;
58672-extern atomic_t fscache_n_op_run;
58673-extern atomic_t fscache_n_op_enqueue;
58674-extern atomic_t fscache_n_op_deferred_release;
58675-extern atomic_t fscache_n_op_release;
58676-extern atomic_t fscache_n_op_gc;
58677-extern atomic_t fscache_n_op_cancelled;
58678-extern atomic_t fscache_n_op_rejected;
58679+extern atomic_unchecked_t fscache_n_op_pend;
58680+extern atomic_unchecked_t fscache_n_op_run;
58681+extern atomic_unchecked_t fscache_n_op_enqueue;
58682+extern atomic_unchecked_t fscache_n_op_deferred_release;
58683+extern atomic_unchecked_t fscache_n_op_release;
58684+extern atomic_unchecked_t fscache_n_op_gc;
58685+extern atomic_unchecked_t fscache_n_op_cancelled;
58686+extern atomic_unchecked_t fscache_n_op_rejected;
58687
58688-extern atomic_t fscache_n_attr_changed;
58689-extern atomic_t fscache_n_attr_changed_ok;
58690-extern atomic_t fscache_n_attr_changed_nobufs;
58691-extern atomic_t fscache_n_attr_changed_nomem;
58692-extern atomic_t fscache_n_attr_changed_calls;
58693+extern atomic_unchecked_t fscache_n_attr_changed;
58694+extern atomic_unchecked_t fscache_n_attr_changed_ok;
58695+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
58696+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
58697+extern atomic_unchecked_t fscache_n_attr_changed_calls;
58698
58699-extern atomic_t fscache_n_allocs;
58700-extern atomic_t fscache_n_allocs_ok;
58701-extern atomic_t fscache_n_allocs_wait;
58702-extern atomic_t fscache_n_allocs_nobufs;
58703-extern atomic_t fscache_n_allocs_intr;
58704-extern atomic_t fscache_n_allocs_object_dead;
58705-extern atomic_t fscache_n_alloc_ops;
58706-extern atomic_t fscache_n_alloc_op_waits;
58707+extern atomic_unchecked_t fscache_n_allocs;
58708+extern atomic_unchecked_t fscache_n_allocs_ok;
58709+extern atomic_unchecked_t fscache_n_allocs_wait;
58710+extern atomic_unchecked_t fscache_n_allocs_nobufs;
58711+extern atomic_unchecked_t fscache_n_allocs_intr;
58712+extern atomic_unchecked_t fscache_n_allocs_object_dead;
58713+extern atomic_unchecked_t fscache_n_alloc_ops;
58714+extern atomic_unchecked_t fscache_n_alloc_op_waits;
58715
58716-extern atomic_t fscache_n_retrievals;
58717-extern atomic_t fscache_n_retrievals_ok;
58718-extern atomic_t fscache_n_retrievals_wait;
58719-extern atomic_t fscache_n_retrievals_nodata;
58720-extern atomic_t fscache_n_retrievals_nobufs;
58721-extern atomic_t fscache_n_retrievals_intr;
58722-extern atomic_t fscache_n_retrievals_nomem;
58723-extern atomic_t fscache_n_retrievals_object_dead;
58724-extern atomic_t fscache_n_retrieval_ops;
58725-extern atomic_t fscache_n_retrieval_op_waits;
58726+extern atomic_unchecked_t fscache_n_retrievals;
58727+extern atomic_unchecked_t fscache_n_retrievals_ok;
58728+extern atomic_unchecked_t fscache_n_retrievals_wait;
58729+extern atomic_unchecked_t fscache_n_retrievals_nodata;
58730+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
58731+extern atomic_unchecked_t fscache_n_retrievals_intr;
58732+extern atomic_unchecked_t fscache_n_retrievals_nomem;
58733+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
58734+extern atomic_unchecked_t fscache_n_retrieval_ops;
58735+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
58736
58737-extern atomic_t fscache_n_stores;
58738-extern atomic_t fscache_n_stores_ok;
58739-extern atomic_t fscache_n_stores_again;
58740-extern atomic_t fscache_n_stores_nobufs;
58741-extern atomic_t fscache_n_stores_oom;
58742-extern atomic_t fscache_n_store_ops;
58743-extern atomic_t fscache_n_store_calls;
58744-extern atomic_t fscache_n_store_pages;
58745-extern atomic_t fscache_n_store_radix_deletes;
58746-extern atomic_t fscache_n_store_pages_over_limit;
58747+extern atomic_unchecked_t fscache_n_stores;
58748+extern atomic_unchecked_t fscache_n_stores_ok;
58749+extern atomic_unchecked_t fscache_n_stores_again;
58750+extern atomic_unchecked_t fscache_n_stores_nobufs;
58751+extern atomic_unchecked_t fscache_n_stores_oom;
58752+extern atomic_unchecked_t fscache_n_store_ops;
58753+extern atomic_unchecked_t fscache_n_store_calls;
58754+extern atomic_unchecked_t fscache_n_store_pages;
58755+extern atomic_unchecked_t fscache_n_store_radix_deletes;
58756+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
58757
58758-extern atomic_t fscache_n_store_vmscan_not_storing;
58759-extern atomic_t fscache_n_store_vmscan_gone;
58760-extern atomic_t fscache_n_store_vmscan_busy;
58761-extern atomic_t fscache_n_store_vmscan_cancelled;
58762-extern atomic_t fscache_n_store_vmscan_wait;
58763+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
58764+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
58765+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
58766+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
58767+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
58768
58769-extern atomic_t fscache_n_marks;
58770-extern atomic_t fscache_n_uncaches;
58771+extern atomic_unchecked_t fscache_n_marks;
58772+extern atomic_unchecked_t fscache_n_uncaches;
58773
58774-extern atomic_t fscache_n_acquires;
58775-extern atomic_t fscache_n_acquires_null;
58776-extern atomic_t fscache_n_acquires_no_cache;
58777-extern atomic_t fscache_n_acquires_ok;
58778-extern atomic_t fscache_n_acquires_nobufs;
58779-extern atomic_t fscache_n_acquires_oom;
58780+extern atomic_unchecked_t fscache_n_acquires;
58781+extern atomic_unchecked_t fscache_n_acquires_null;
58782+extern atomic_unchecked_t fscache_n_acquires_no_cache;
58783+extern atomic_unchecked_t fscache_n_acquires_ok;
58784+extern atomic_unchecked_t fscache_n_acquires_nobufs;
58785+extern atomic_unchecked_t fscache_n_acquires_oom;
58786
58787-extern atomic_t fscache_n_invalidates;
58788-extern atomic_t fscache_n_invalidates_run;
58789+extern atomic_unchecked_t fscache_n_invalidates;
58790+extern atomic_unchecked_t fscache_n_invalidates_run;
58791
58792-extern atomic_t fscache_n_updates;
58793-extern atomic_t fscache_n_updates_null;
58794-extern atomic_t fscache_n_updates_run;
58795+extern atomic_unchecked_t fscache_n_updates;
58796+extern atomic_unchecked_t fscache_n_updates_null;
58797+extern atomic_unchecked_t fscache_n_updates_run;
58798
58799-extern atomic_t fscache_n_relinquishes;
58800-extern atomic_t fscache_n_relinquishes_null;
58801-extern atomic_t fscache_n_relinquishes_waitcrt;
58802-extern atomic_t fscache_n_relinquishes_retire;
58803+extern atomic_unchecked_t fscache_n_relinquishes;
58804+extern atomic_unchecked_t fscache_n_relinquishes_null;
58805+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
58806+extern atomic_unchecked_t fscache_n_relinquishes_retire;
58807
58808-extern atomic_t fscache_n_cookie_index;
58809-extern atomic_t fscache_n_cookie_data;
58810-extern atomic_t fscache_n_cookie_special;
58811+extern atomic_unchecked_t fscache_n_cookie_index;
58812+extern atomic_unchecked_t fscache_n_cookie_data;
58813+extern atomic_unchecked_t fscache_n_cookie_special;
58814
58815-extern atomic_t fscache_n_object_alloc;
58816-extern atomic_t fscache_n_object_no_alloc;
58817-extern atomic_t fscache_n_object_lookups;
58818-extern atomic_t fscache_n_object_lookups_negative;
58819-extern atomic_t fscache_n_object_lookups_positive;
58820-extern atomic_t fscache_n_object_lookups_timed_out;
58821-extern atomic_t fscache_n_object_created;
58822-extern atomic_t fscache_n_object_avail;
58823-extern atomic_t fscache_n_object_dead;
58824+extern atomic_unchecked_t fscache_n_object_alloc;
58825+extern atomic_unchecked_t fscache_n_object_no_alloc;
58826+extern atomic_unchecked_t fscache_n_object_lookups;
58827+extern atomic_unchecked_t fscache_n_object_lookups_negative;
58828+extern atomic_unchecked_t fscache_n_object_lookups_positive;
58829+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
58830+extern atomic_unchecked_t fscache_n_object_created;
58831+extern atomic_unchecked_t fscache_n_object_avail;
58832+extern atomic_unchecked_t fscache_n_object_dead;
58833
58834-extern atomic_t fscache_n_checkaux_none;
58835-extern atomic_t fscache_n_checkaux_okay;
58836-extern atomic_t fscache_n_checkaux_update;
58837-extern atomic_t fscache_n_checkaux_obsolete;
58838+extern atomic_unchecked_t fscache_n_checkaux_none;
58839+extern atomic_unchecked_t fscache_n_checkaux_okay;
58840+extern atomic_unchecked_t fscache_n_checkaux_update;
58841+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
58842
58843 extern atomic_t fscache_n_cop_alloc_object;
58844 extern atomic_t fscache_n_cop_lookup_object;
58845@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
58846 atomic_inc(stat);
58847 }
58848
58849+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
58850+{
58851+ atomic_inc_unchecked(stat);
58852+}
58853+
58854 static inline void fscache_stat_d(atomic_t *stat)
58855 {
58856 atomic_dec(stat);
58857@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
58858
58859 #define __fscache_stat(stat) (NULL)
58860 #define fscache_stat(stat) do {} while (0)
58861+#define fscache_stat_unchecked(stat) do {} while (0)
58862 #define fscache_stat_d(stat) do {} while (0)
58863 #endif
58864
58865diff --git a/fs/fscache/object.c b/fs/fscache/object.c
58866index 53d35c5..5d68ed4 100644
58867--- a/fs/fscache/object.c
58868+++ b/fs/fscache/object.c
58869@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
58870 _debug("LOOKUP \"%s\" in \"%s\"",
58871 cookie->def->name, object->cache->tag->name);
58872
58873- fscache_stat(&fscache_n_object_lookups);
58874+ fscache_stat_unchecked(&fscache_n_object_lookups);
58875 fscache_stat(&fscache_n_cop_lookup_object);
58876 ret = object->cache->ops->lookup_object(object);
58877 fscache_stat_d(&fscache_n_cop_lookup_object);
58878@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
58879 if (ret == -ETIMEDOUT) {
58880 /* probably stuck behind another object, so move this one to
58881 * the back of the queue */
58882- fscache_stat(&fscache_n_object_lookups_timed_out);
58883+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
58884 _leave(" [timeout]");
58885 return NO_TRANSIT;
58886 }
58887@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
58888 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
58889
58890 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
58891- fscache_stat(&fscache_n_object_lookups_negative);
58892+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
58893
58894 /* Allow write requests to begin stacking up and read requests to begin
58895 * returning ENODATA.
58896@@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
58897 /* if we were still looking up, then we must have a positive lookup
58898 * result, in which case there may be data available */
58899 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
58900- fscache_stat(&fscache_n_object_lookups_positive);
58901+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
58902
58903 /* We do (presumably) have data */
58904 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
58905@@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
58906 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
58907 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
58908 } else {
58909- fscache_stat(&fscache_n_object_created);
58910+ fscache_stat_unchecked(&fscache_n_object_created);
58911 }
58912
58913 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
58914@@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
58915 fscache_stat_d(&fscache_n_cop_lookup_complete);
58916
58917 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
58918- fscache_stat(&fscache_n_object_avail);
58919+ fscache_stat_unchecked(&fscache_n_object_avail);
58920
58921 _leave("");
58922 return transit_to(JUMPSTART_DEPS);
58923@@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
58924
58925 /* this just shifts the object release to the work processor */
58926 fscache_put_object(object);
58927- fscache_stat(&fscache_n_object_dead);
58928+ fscache_stat_unchecked(&fscache_n_object_dead);
58929
58930 _leave("");
58931 return transit_to(OBJECT_DEAD);
58932@@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
58933 enum fscache_checkaux result;
58934
58935 if (!object->cookie->def->check_aux) {
58936- fscache_stat(&fscache_n_checkaux_none);
58937+ fscache_stat_unchecked(&fscache_n_checkaux_none);
58938 return FSCACHE_CHECKAUX_OKAY;
58939 }
58940
58941@@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
58942 switch (result) {
58943 /* entry okay as is */
58944 case FSCACHE_CHECKAUX_OKAY:
58945- fscache_stat(&fscache_n_checkaux_okay);
58946+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
58947 break;
58948
58949 /* entry requires update */
58950 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
58951- fscache_stat(&fscache_n_checkaux_update);
58952+ fscache_stat_unchecked(&fscache_n_checkaux_update);
58953 break;
58954
58955 /* entry requires deletion */
58956 case FSCACHE_CHECKAUX_OBSOLETE:
58957- fscache_stat(&fscache_n_checkaux_obsolete);
58958+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
58959 break;
58960
58961 default:
58962@@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
58963 {
58964 const struct fscache_state *s;
58965
58966- fscache_stat(&fscache_n_invalidates_run);
58967+ fscache_stat_unchecked(&fscache_n_invalidates_run);
58968 fscache_stat(&fscache_n_cop_invalidate_object);
58969 s = _fscache_invalidate_object(object, event);
58970 fscache_stat_d(&fscache_n_cop_invalidate_object);
58971@@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
58972 {
58973 _enter("{OBJ%x},%d", object->debug_id, event);
58974
58975- fscache_stat(&fscache_n_updates_run);
58976+ fscache_stat_unchecked(&fscache_n_updates_run);
58977 fscache_stat(&fscache_n_cop_update_object);
58978 object->cache->ops->update_object(object);
58979 fscache_stat_d(&fscache_n_cop_update_object);
58980diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
58981index 318071a..379938b 100644
58982--- a/fs/fscache/operation.c
58983+++ b/fs/fscache/operation.c
58984@@ -17,7 +17,7 @@
58985 #include <linux/slab.h>
58986 #include "internal.h"
58987
58988-atomic_t fscache_op_debug_id;
58989+atomic_unchecked_t fscache_op_debug_id;
58990 EXPORT_SYMBOL(fscache_op_debug_id);
58991
58992 /**
58993@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
58994 ASSERTCMP(atomic_read(&op->usage), >, 0);
58995 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
58996
58997- fscache_stat(&fscache_n_op_enqueue);
58998+ fscache_stat_unchecked(&fscache_n_op_enqueue);
58999 switch (op->flags & FSCACHE_OP_TYPE) {
59000 case FSCACHE_OP_ASYNC:
59001 _debug("queue async");
59002@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59003 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59004 if (op->processor)
59005 fscache_enqueue_operation(op);
59006- fscache_stat(&fscache_n_op_run);
59007+ fscache_stat_unchecked(&fscache_n_op_run);
59008 }
59009
59010 /*
59011@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59012 if (object->n_in_progress > 0) {
59013 atomic_inc(&op->usage);
59014 list_add_tail(&op->pend_link, &object->pending_ops);
59015- fscache_stat(&fscache_n_op_pend);
59016+ fscache_stat_unchecked(&fscache_n_op_pend);
59017 } else if (!list_empty(&object->pending_ops)) {
59018 atomic_inc(&op->usage);
59019 list_add_tail(&op->pend_link, &object->pending_ops);
59020- fscache_stat(&fscache_n_op_pend);
59021+ fscache_stat_unchecked(&fscache_n_op_pend);
59022 fscache_start_operations(object);
59023 } else {
59024 ASSERTCMP(object->n_in_progress, ==, 0);
59025@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59026 object->n_exclusive++; /* reads and writes must wait */
59027 atomic_inc(&op->usage);
59028 list_add_tail(&op->pend_link, &object->pending_ops);
59029- fscache_stat(&fscache_n_op_pend);
59030+ fscache_stat_unchecked(&fscache_n_op_pend);
59031 ret = 0;
59032 } else {
59033 /* If we're in any other state, there must have been an I/O
59034@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59035 if (object->n_exclusive > 0) {
59036 atomic_inc(&op->usage);
59037 list_add_tail(&op->pend_link, &object->pending_ops);
59038- fscache_stat(&fscache_n_op_pend);
59039+ fscache_stat_unchecked(&fscache_n_op_pend);
59040 } else if (!list_empty(&object->pending_ops)) {
59041 atomic_inc(&op->usage);
59042 list_add_tail(&op->pend_link, &object->pending_ops);
59043- fscache_stat(&fscache_n_op_pend);
59044+ fscache_stat_unchecked(&fscache_n_op_pend);
59045 fscache_start_operations(object);
59046 } else {
59047 ASSERTCMP(object->n_exclusive, ==, 0);
59048@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59049 object->n_ops++;
59050 atomic_inc(&op->usage);
59051 list_add_tail(&op->pend_link, &object->pending_ops);
59052- fscache_stat(&fscache_n_op_pend);
59053+ fscache_stat_unchecked(&fscache_n_op_pend);
59054 ret = 0;
59055 } else if (fscache_object_is_dying(object)) {
59056- fscache_stat(&fscache_n_op_rejected);
59057+ fscache_stat_unchecked(&fscache_n_op_rejected);
59058 op->state = FSCACHE_OP_ST_CANCELLED;
59059 ret = -ENOBUFS;
59060 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59061@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59062 ret = -EBUSY;
59063 if (op->state == FSCACHE_OP_ST_PENDING) {
59064 ASSERT(!list_empty(&op->pend_link));
59065- fscache_stat(&fscache_n_op_cancelled);
59066+ fscache_stat_unchecked(&fscache_n_op_cancelled);
59067 list_del_init(&op->pend_link);
59068 if (do_cancel)
59069 do_cancel(op);
59070@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
59071 while (!list_empty(&object->pending_ops)) {
59072 op = list_entry(object->pending_ops.next,
59073 struct fscache_operation, pend_link);
59074- fscache_stat(&fscache_n_op_cancelled);
59075+ fscache_stat_unchecked(&fscache_n_op_cancelled);
59076 list_del_init(&op->pend_link);
59077
59078 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
59079@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
59080 op->state, ==, FSCACHE_OP_ST_CANCELLED);
59081 op->state = FSCACHE_OP_ST_DEAD;
59082
59083- fscache_stat(&fscache_n_op_release);
59084+ fscache_stat_unchecked(&fscache_n_op_release);
59085
59086 if (op->release) {
59087 op->release(op);
59088@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
59089 * lock, and defer it otherwise */
59090 if (!spin_trylock(&object->lock)) {
59091 _debug("defer put");
59092- fscache_stat(&fscache_n_op_deferred_release);
59093+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
59094
59095 cache = object->cache;
59096 spin_lock(&cache->op_gc_list_lock);
59097@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
59098
59099 _debug("GC DEFERRED REL OBJ%x OP%x",
59100 object->debug_id, op->debug_id);
59101- fscache_stat(&fscache_n_op_gc);
59102+ fscache_stat_unchecked(&fscache_n_op_gc);
59103
59104 ASSERTCMP(atomic_read(&op->usage), ==, 0);
59105 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
59106diff --git a/fs/fscache/page.c b/fs/fscache/page.c
59107index 7f5c658..6c1e164 100644
59108--- a/fs/fscache/page.c
59109+++ b/fs/fscache/page.c
59110@@ -61,7 +61,7 @@ try_again:
59111 val = radix_tree_lookup(&cookie->stores, page->index);
59112 if (!val) {
59113 rcu_read_unlock();
59114- fscache_stat(&fscache_n_store_vmscan_not_storing);
59115+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
59116 __fscache_uncache_page(cookie, page);
59117 return true;
59118 }
59119@@ -91,11 +91,11 @@ try_again:
59120 spin_unlock(&cookie->stores_lock);
59121
59122 if (xpage) {
59123- fscache_stat(&fscache_n_store_vmscan_cancelled);
59124- fscache_stat(&fscache_n_store_radix_deletes);
59125+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
59126+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59127 ASSERTCMP(xpage, ==, page);
59128 } else {
59129- fscache_stat(&fscache_n_store_vmscan_gone);
59130+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
59131 }
59132
59133 wake_up_bit(&cookie->flags, 0);
59134@@ -110,11 +110,11 @@ page_busy:
59135 * sleeping on memory allocation, so we may need to impose a timeout
59136 * too. */
59137 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
59138- fscache_stat(&fscache_n_store_vmscan_busy);
59139+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
59140 return false;
59141 }
59142
59143- fscache_stat(&fscache_n_store_vmscan_wait);
59144+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
59145 __fscache_wait_on_page_write(cookie, page);
59146 gfp &= ~__GFP_WAIT;
59147 goto try_again;
59148@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
59149 FSCACHE_COOKIE_STORING_TAG);
59150 if (!radix_tree_tag_get(&cookie->stores, page->index,
59151 FSCACHE_COOKIE_PENDING_TAG)) {
59152- fscache_stat(&fscache_n_store_radix_deletes);
59153+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59154 xpage = radix_tree_delete(&cookie->stores, page->index);
59155 }
59156 spin_unlock(&cookie->stores_lock);
59157@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
59158
59159 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
59160
59161- fscache_stat(&fscache_n_attr_changed_calls);
59162+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
59163
59164 if (fscache_object_is_active(object)) {
59165 fscache_stat(&fscache_n_cop_attr_changed);
59166@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59167
59168 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59169
59170- fscache_stat(&fscache_n_attr_changed);
59171+ fscache_stat_unchecked(&fscache_n_attr_changed);
59172
59173 op = kzalloc(sizeof(*op), GFP_KERNEL);
59174 if (!op) {
59175- fscache_stat(&fscache_n_attr_changed_nomem);
59176+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
59177 _leave(" = -ENOMEM");
59178 return -ENOMEM;
59179 }
59180@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59181 if (fscache_submit_exclusive_op(object, op) < 0)
59182 goto nobufs;
59183 spin_unlock(&cookie->lock);
59184- fscache_stat(&fscache_n_attr_changed_ok);
59185+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
59186 fscache_put_operation(op);
59187 _leave(" = 0");
59188 return 0;
59189@@ -225,7 +225,7 @@ nobufs:
59190 kfree(op);
59191 if (wake_cookie)
59192 __fscache_wake_unused_cookie(cookie);
59193- fscache_stat(&fscache_n_attr_changed_nobufs);
59194+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
59195 _leave(" = %d", -ENOBUFS);
59196 return -ENOBUFS;
59197 }
59198@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
59199 /* allocate a retrieval operation and attempt to submit it */
59200 op = kzalloc(sizeof(*op), GFP_NOIO);
59201 if (!op) {
59202- fscache_stat(&fscache_n_retrievals_nomem);
59203+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59204 return NULL;
59205 }
59206
59207@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
59208 return 0;
59209 }
59210
59211- fscache_stat(&fscache_n_retrievals_wait);
59212+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
59213
59214 jif = jiffies;
59215 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
59216 fscache_wait_bit_interruptible,
59217 TASK_INTERRUPTIBLE) != 0) {
59218- fscache_stat(&fscache_n_retrievals_intr);
59219+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
59220 _leave(" = -ERESTARTSYS");
59221 return -ERESTARTSYS;
59222 }
59223@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
59224 */
59225 int fscache_wait_for_operation_activation(struct fscache_object *object,
59226 struct fscache_operation *op,
59227- atomic_t *stat_op_waits,
59228- atomic_t *stat_object_dead,
59229+ atomic_unchecked_t *stat_op_waits,
59230+ atomic_unchecked_t *stat_object_dead,
59231 void (*do_cancel)(struct fscache_operation *))
59232 {
59233 int ret;
59234@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59235
59236 _debug(">>> WT");
59237 if (stat_op_waits)
59238- fscache_stat(stat_op_waits);
59239+ fscache_stat_unchecked(stat_op_waits);
59240 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
59241 fscache_wait_bit_interruptible,
59242 TASK_INTERRUPTIBLE) != 0) {
59243@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59244 check_if_dead:
59245 if (op->state == FSCACHE_OP_ST_CANCELLED) {
59246 if (stat_object_dead)
59247- fscache_stat(stat_object_dead);
59248+ fscache_stat_unchecked(stat_object_dead);
59249 _leave(" = -ENOBUFS [cancelled]");
59250 return -ENOBUFS;
59251 }
59252@@ -366,7 +366,7 @@ check_if_dead:
59253 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
59254 fscache_cancel_op(op, do_cancel);
59255 if (stat_object_dead)
59256- fscache_stat(stat_object_dead);
59257+ fscache_stat_unchecked(stat_object_dead);
59258 return -ENOBUFS;
59259 }
59260 return 0;
59261@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59262
59263 _enter("%p,%p,,,", cookie, page);
59264
59265- fscache_stat(&fscache_n_retrievals);
59266+ fscache_stat_unchecked(&fscache_n_retrievals);
59267
59268 if (hlist_empty(&cookie->backing_objects))
59269 goto nobufs;
59270@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59271 goto nobufs_unlock_dec;
59272 spin_unlock(&cookie->lock);
59273
59274- fscache_stat(&fscache_n_retrieval_ops);
59275+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
59276
59277 /* pin the netfs read context in case we need to do the actual netfs
59278 * read because we've encountered a cache read failure */
59279@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59280
59281 error:
59282 if (ret == -ENOMEM)
59283- fscache_stat(&fscache_n_retrievals_nomem);
59284+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59285 else if (ret == -ERESTARTSYS)
59286- fscache_stat(&fscache_n_retrievals_intr);
59287+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
59288 else if (ret == -ENODATA)
59289- fscache_stat(&fscache_n_retrievals_nodata);
59290+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59291 else if (ret < 0)
59292- fscache_stat(&fscache_n_retrievals_nobufs);
59293+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59294 else
59295- fscache_stat(&fscache_n_retrievals_ok);
59296+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
59297
59298 fscache_put_retrieval(op);
59299 _leave(" = %d", ret);
59300@@ -490,7 +490,7 @@ nobufs_unlock:
59301 __fscache_wake_unused_cookie(cookie);
59302 kfree(op);
59303 nobufs:
59304- fscache_stat(&fscache_n_retrievals_nobufs);
59305+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59306 _leave(" = -ENOBUFS");
59307 return -ENOBUFS;
59308 }
59309@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59310
59311 _enter("%p,,%d,,,", cookie, *nr_pages);
59312
59313- fscache_stat(&fscache_n_retrievals);
59314+ fscache_stat_unchecked(&fscache_n_retrievals);
59315
59316 if (hlist_empty(&cookie->backing_objects))
59317 goto nobufs;
59318@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59319 goto nobufs_unlock_dec;
59320 spin_unlock(&cookie->lock);
59321
59322- fscache_stat(&fscache_n_retrieval_ops);
59323+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
59324
59325 /* pin the netfs read context in case we need to do the actual netfs
59326 * read because we've encountered a cache read failure */
59327@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59328
59329 error:
59330 if (ret == -ENOMEM)
59331- fscache_stat(&fscache_n_retrievals_nomem);
59332+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59333 else if (ret == -ERESTARTSYS)
59334- fscache_stat(&fscache_n_retrievals_intr);
59335+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
59336 else if (ret == -ENODATA)
59337- fscache_stat(&fscache_n_retrievals_nodata);
59338+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59339 else if (ret < 0)
59340- fscache_stat(&fscache_n_retrievals_nobufs);
59341+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59342 else
59343- fscache_stat(&fscache_n_retrievals_ok);
59344+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
59345
59346 fscache_put_retrieval(op);
59347 _leave(" = %d", ret);
59348@@ -621,7 +621,7 @@ nobufs_unlock:
59349 if (wake_cookie)
59350 __fscache_wake_unused_cookie(cookie);
59351 nobufs:
59352- fscache_stat(&fscache_n_retrievals_nobufs);
59353+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59354 _leave(" = -ENOBUFS");
59355 return -ENOBUFS;
59356 }
59357@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59358
59359 _enter("%p,%p,,,", cookie, page);
59360
59361- fscache_stat(&fscache_n_allocs);
59362+ fscache_stat_unchecked(&fscache_n_allocs);
59363
59364 if (hlist_empty(&cookie->backing_objects))
59365 goto nobufs;
59366@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59367 goto nobufs_unlock_dec;
59368 spin_unlock(&cookie->lock);
59369
59370- fscache_stat(&fscache_n_alloc_ops);
59371+ fscache_stat_unchecked(&fscache_n_alloc_ops);
59372
59373 ret = fscache_wait_for_operation_activation(
59374 object, &op->op,
59375@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59376
59377 error:
59378 if (ret == -ERESTARTSYS)
59379- fscache_stat(&fscache_n_allocs_intr);
59380+ fscache_stat_unchecked(&fscache_n_allocs_intr);
59381 else if (ret < 0)
59382- fscache_stat(&fscache_n_allocs_nobufs);
59383+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59384 else
59385- fscache_stat(&fscache_n_allocs_ok);
59386+ fscache_stat_unchecked(&fscache_n_allocs_ok);
59387
59388 fscache_put_retrieval(op);
59389 _leave(" = %d", ret);
59390@@ -715,7 +715,7 @@ nobufs_unlock:
59391 if (wake_cookie)
59392 __fscache_wake_unused_cookie(cookie);
59393 nobufs:
59394- fscache_stat(&fscache_n_allocs_nobufs);
59395+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59396 _leave(" = -ENOBUFS");
59397 return -ENOBUFS;
59398 }
59399@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59400
59401 spin_lock(&cookie->stores_lock);
59402
59403- fscache_stat(&fscache_n_store_calls);
59404+ fscache_stat_unchecked(&fscache_n_store_calls);
59405
59406 /* find a page to store */
59407 page = NULL;
59408@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59409 page = results[0];
59410 _debug("gang %d [%lx]", n, page->index);
59411 if (page->index > op->store_limit) {
59412- fscache_stat(&fscache_n_store_pages_over_limit);
59413+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
59414 goto superseded;
59415 }
59416
59417@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59418 spin_unlock(&cookie->stores_lock);
59419 spin_unlock(&object->lock);
59420
59421- fscache_stat(&fscache_n_store_pages);
59422+ fscache_stat_unchecked(&fscache_n_store_pages);
59423 fscache_stat(&fscache_n_cop_write_page);
59424 ret = object->cache->ops->write_page(op, page);
59425 fscache_stat_d(&fscache_n_cop_write_page);
59426@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59427 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59428 ASSERT(PageFsCache(page));
59429
59430- fscache_stat(&fscache_n_stores);
59431+ fscache_stat_unchecked(&fscache_n_stores);
59432
59433 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
59434 _leave(" = -ENOBUFS [invalidating]");
59435@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59436 spin_unlock(&cookie->stores_lock);
59437 spin_unlock(&object->lock);
59438
59439- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
59440+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59441 op->store_limit = object->store_limit;
59442
59443 __fscache_use_cookie(cookie);
59444@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59445
59446 spin_unlock(&cookie->lock);
59447 radix_tree_preload_end();
59448- fscache_stat(&fscache_n_store_ops);
59449- fscache_stat(&fscache_n_stores_ok);
59450+ fscache_stat_unchecked(&fscache_n_store_ops);
59451+ fscache_stat_unchecked(&fscache_n_stores_ok);
59452
59453 /* the work queue now carries its own ref on the object */
59454 fscache_put_operation(&op->op);
59455@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59456 return 0;
59457
59458 already_queued:
59459- fscache_stat(&fscache_n_stores_again);
59460+ fscache_stat_unchecked(&fscache_n_stores_again);
59461 already_pending:
59462 spin_unlock(&cookie->stores_lock);
59463 spin_unlock(&object->lock);
59464 spin_unlock(&cookie->lock);
59465 radix_tree_preload_end();
59466 kfree(op);
59467- fscache_stat(&fscache_n_stores_ok);
59468+ fscache_stat_unchecked(&fscache_n_stores_ok);
59469 _leave(" = 0");
59470 return 0;
59471
59472@@ -1024,14 +1024,14 @@ nobufs:
59473 kfree(op);
59474 if (wake_cookie)
59475 __fscache_wake_unused_cookie(cookie);
59476- fscache_stat(&fscache_n_stores_nobufs);
59477+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
59478 _leave(" = -ENOBUFS");
59479 return -ENOBUFS;
59480
59481 nomem_free:
59482 kfree(op);
59483 nomem:
59484- fscache_stat(&fscache_n_stores_oom);
59485+ fscache_stat_unchecked(&fscache_n_stores_oom);
59486 _leave(" = -ENOMEM");
59487 return -ENOMEM;
59488 }
59489@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
59490 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59491 ASSERTCMP(page, !=, NULL);
59492
59493- fscache_stat(&fscache_n_uncaches);
59494+ fscache_stat_unchecked(&fscache_n_uncaches);
59495
59496 /* cache withdrawal may beat us to it */
59497 if (!PageFsCache(page))
59498@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
59499 struct fscache_cookie *cookie = op->op.object->cookie;
59500
59501 #ifdef CONFIG_FSCACHE_STATS
59502- atomic_inc(&fscache_n_marks);
59503+ atomic_inc_unchecked(&fscache_n_marks);
59504 #endif
59505
59506 _debug("- mark %p{%lx}", page, page->index);
59507diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
59508index 40d13c7..ddf52b9 100644
59509--- a/fs/fscache/stats.c
59510+++ b/fs/fscache/stats.c
59511@@ -18,99 +18,99 @@
59512 /*
59513 * operation counters
59514 */
59515-atomic_t fscache_n_op_pend;
59516-atomic_t fscache_n_op_run;
59517-atomic_t fscache_n_op_enqueue;
59518-atomic_t fscache_n_op_requeue;
59519-atomic_t fscache_n_op_deferred_release;
59520-atomic_t fscache_n_op_release;
59521-atomic_t fscache_n_op_gc;
59522-atomic_t fscache_n_op_cancelled;
59523-atomic_t fscache_n_op_rejected;
59524+atomic_unchecked_t fscache_n_op_pend;
59525+atomic_unchecked_t fscache_n_op_run;
59526+atomic_unchecked_t fscache_n_op_enqueue;
59527+atomic_unchecked_t fscache_n_op_requeue;
59528+atomic_unchecked_t fscache_n_op_deferred_release;
59529+atomic_unchecked_t fscache_n_op_release;
59530+atomic_unchecked_t fscache_n_op_gc;
59531+atomic_unchecked_t fscache_n_op_cancelled;
59532+atomic_unchecked_t fscache_n_op_rejected;
59533
59534-atomic_t fscache_n_attr_changed;
59535-atomic_t fscache_n_attr_changed_ok;
59536-atomic_t fscache_n_attr_changed_nobufs;
59537-atomic_t fscache_n_attr_changed_nomem;
59538-atomic_t fscache_n_attr_changed_calls;
59539+atomic_unchecked_t fscache_n_attr_changed;
59540+atomic_unchecked_t fscache_n_attr_changed_ok;
59541+atomic_unchecked_t fscache_n_attr_changed_nobufs;
59542+atomic_unchecked_t fscache_n_attr_changed_nomem;
59543+atomic_unchecked_t fscache_n_attr_changed_calls;
59544
59545-atomic_t fscache_n_allocs;
59546-atomic_t fscache_n_allocs_ok;
59547-atomic_t fscache_n_allocs_wait;
59548-atomic_t fscache_n_allocs_nobufs;
59549-atomic_t fscache_n_allocs_intr;
59550-atomic_t fscache_n_allocs_object_dead;
59551-atomic_t fscache_n_alloc_ops;
59552-atomic_t fscache_n_alloc_op_waits;
59553+atomic_unchecked_t fscache_n_allocs;
59554+atomic_unchecked_t fscache_n_allocs_ok;
59555+atomic_unchecked_t fscache_n_allocs_wait;
59556+atomic_unchecked_t fscache_n_allocs_nobufs;
59557+atomic_unchecked_t fscache_n_allocs_intr;
59558+atomic_unchecked_t fscache_n_allocs_object_dead;
59559+atomic_unchecked_t fscache_n_alloc_ops;
59560+atomic_unchecked_t fscache_n_alloc_op_waits;
59561
59562-atomic_t fscache_n_retrievals;
59563-atomic_t fscache_n_retrievals_ok;
59564-atomic_t fscache_n_retrievals_wait;
59565-atomic_t fscache_n_retrievals_nodata;
59566-atomic_t fscache_n_retrievals_nobufs;
59567-atomic_t fscache_n_retrievals_intr;
59568-atomic_t fscache_n_retrievals_nomem;
59569-atomic_t fscache_n_retrievals_object_dead;
59570-atomic_t fscache_n_retrieval_ops;
59571-atomic_t fscache_n_retrieval_op_waits;
59572+atomic_unchecked_t fscache_n_retrievals;
59573+atomic_unchecked_t fscache_n_retrievals_ok;
59574+atomic_unchecked_t fscache_n_retrievals_wait;
59575+atomic_unchecked_t fscache_n_retrievals_nodata;
59576+atomic_unchecked_t fscache_n_retrievals_nobufs;
59577+atomic_unchecked_t fscache_n_retrievals_intr;
59578+atomic_unchecked_t fscache_n_retrievals_nomem;
59579+atomic_unchecked_t fscache_n_retrievals_object_dead;
59580+atomic_unchecked_t fscache_n_retrieval_ops;
59581+atomic_unchecked_t fscache_n_retrieval_op_waits;
59582
59583-atomic_t fscache_n_stores;
59584-atomic_t fscache_n_stores_ok;
59585-atomic_t fscache_n_stores_again;
59586-atomic_t fscache_n_stores_nobufs;
59587-atomic_t fscache_n_stores_oom;
59588-atomic_t fscache_n_store_ops;
59589-atomic_t fscache_n_store_calls;
59590-atomic_t fscache_n_store_pages;
59591-atomic_t fscache_n_store_radix_deletes;
59592-atomic_t fscache_n_store_pages_over_limit;
59593+atomic_unchecked_t fscache_n_stores;
59594+atomic_unchecked_t fscache_n_stores_ok;
59595+atomic_unchecked_t fscache_n_stores_again;
59596+atomic_unchecked_t fscache_n_stores_nobufs;
59597+atomic_unchecked_t fscache_n_stores_oom;
59598+atomic_unchecked_t fscache_n_store_ops;
59599+atomic_unchecked_t fscache_n_store_calls;
59600+atomic_unchecked_t fscache_n_store_pages;
59601+atomic_unchecked_t fscache_n_store_radix_deletes;
59602+atomic_unchecked_t fscache_n_store_pages_over_limit;
59603
59604-atomic_t fscache_n_store_vmscan_not_storing;
59605-atomic_t fscache_n_store_vmscan_gone;
59606-atomic_t fscache_n_store_vmscan_busy;
59607-atomic_t fscache_n_store_vmscan_cancelled;
59608-atomic_t fscache_n_store_vmscan_wait;
59609+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59610+atomic_unchecked_t fscache_n_store_vmscan_gone;
59611+atomic_unchecked_t fscache_n_store_vmscan_busy;
59612+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59613+atomic_unchecked_t fscache_n_store_vmscan_wait;
59614
59615-atomic_t fscache_n_marks;
59616-atomic_t fscache_n_uncaches;
59617+atomic_unchecked_t fscache_n_marks;
59618+atomic_unchecked_t fscache_n_uncaches;
59619
59620-atomic_t fscache_n_acquires;
59621-atomic_t fscache_n_acquires_null;
59622-atomic_t fscache_n_acquires_no_cache;
59623-atomic_t fscache_n_acquires_ok;
59624-atomic_t fscache_n_acquires_nobufs;
59625-atomic_t fscache_n_acquires_oom;
59626+atomic_unchecked_t fscache_n_acquires;
59627+atomic_unchecked_t fscache_n_acquires_null;
59628+atomic_unchecked_t fscache_n_acquires_no_cache;
59629+atomic_unchecked_t fscache_n_acquires_ok;
59630+atomic_unchecked_t fscache_n_acquires_nobufs;
59631+atomic_unchecked_t fscache_n_acquires_oom;
59632
59633-atomic_t fscache_n_invalidates;
59634-atomic_t fscache_n_invalidates_run;
59635+atomic_unchecked_t fscache_n_invalidates;
59636+atomic_unchecked_t fscache_n_invalidates_run;
59637
59638-atomic_t fscache_n_updates;
59639-atomic_t fscache_n_updates_null;
59640-atomic_t fscache_n_updates_run;
59641+atomic_unchecked_t fscache_n_updates;
59642+atomic_unchecked_t fscache_n_updates_null;
59643+atomic_unchecked_t fscache_n_updates_run;
59644
59645-atomic_t fscache_n_relinquishes;
59646-atomic_t fscache_n_relinquishes_null;
59647-atomic_t fscache_n_relinquishes_waitcrt;
59648-atomic_t fscache_n_relinquishes_retire;
59649+atomic_unchecked_t fscache_n_relinquishes;
59650+atomic_unchecked_t fscache_n_relinquishes_null;
59651+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59652+atomic_unchecked_t fscache_n_relinquishes_retire;
59653
59654-atomic_t fscache_n_cookie_index;
59655-atomic_t fscache_n_cookie_data;
59656-atomic_t fscache_n_cookie_special;
59657+atomic_unchecked_t fscache_n_cookie_index;
59658+atomic_unchecked_t fscache_n_cookie_data;
59659+atomic_unchecked_t fscache_n_cookie_special;
59660
59661-atomic_t fscache_n_object_alloc;
59662-atomic_t fscache_n_object_no_alloc;
59663-atomic_t fscache_n_object_lookups;
59664-atomic_t fscache_n_object_lookups_negative;
59665-atomic_t fscache_n_object_lookups_positive;
59666-atomic_t fscache_n_object_lookups_timed_out;
59667-atomic_t fscache_n_object_created;
59668-atomic_t fscache_n_object_avail;
59669-atomic_t fscache_n_object_dead;
59670+atomic_unchecked_t fscache_n_object_alloc;
59671+atomic_unchecked_t fscache_n_object_no_alloc;
59672+atomic_unchecked_t fscache_n_object_lookups;
59673+atomic_unchecked_t fscache_n_object_lookups_negative;
59674+atomic_unchecked_t fscache_n_object_lookups_positive;
59675+atomic_unchecked_t fscache_n_object_lookups_timed_out;
59676+atomic_unchecked_t fscache_n_object_created;
59677+atomic_unchecked_t fscache_n_object_avail;
59678+atomic_unchecked_t fscache_n_object_dead;
59679
59680-atomic_t fscache_n_checkaux_none;
59681-atomic_t fscache_n_checkaux_okay;
59682-atomic_t fscache_n_checkaux_update;
59683-atomic_t fscache_n_checkaux_obsolete;
59684+atomic_unchecked_t fscache_n_checkaux_none;
59685+atomic_unchecked_t fscache_n_checkaux_okay;
59686+atomic_unchecked_t fscache_n_checkaux_update;
59687+atomic_unchecked_t fscache_n_checkaux_obsolete;
59688
59689 atomic_t fscache_n_cop_alloc_object;
59690 atomic_t fscache_n_cop_lookup_object;
59691@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
59692 seq_puts(m, "FS-Cache statistics\n");
59693
59694 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
59695- atomic_read(&fscache_n_cookie_index),
59696- atomic_read(&fscache_n_cookie_data),
59697- atomic_read(&fscache_n_cookie_special));
59698+ atomic_read_unchecked(&fscache_n_cookie_index),
59699+ atomic_read_unchecked(&fscache_n_cookie_data),
59700+ atomic_read_unchecked(&fscache_n_cookie_special));
59701
59702 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
59703- atomic_read(&fscache_n_object_alloc),
59704- atomic_read(&fscache_n_object_no_alloc),
59705- atomic_read(&fscache_n_object_avail),
59706- atomic_read(&fscache_n_object_dead));
59707+ atomic_read_unchecked(&fscache_n_object_alloc),
59708+ atomic_read_unchecked(&fscache_n_object_no_alloc),
59709+ atomic_read_unchecked(&fscache_n_object_avail),
59710+ atomic_read_unchecked(&fscache_n_object_dead));
59711 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
59712- atomic_read(&fscache_n_checkaux_none),
59713- atomic_read(&fscache_n_checkaux_okay),
59714- atomic_read(&fscache_n_checkaux_update),
59715- atomic_read(&fscache_n_checkaux_obsolete));
59716+ atomic_read_unchecked(&fscache_n_checkaux_none),
59717+ atomic_read_unchecked(&fscache_n_checkaux_okay),
59718+ atomic_read_unchecked(&fscache_n_checkaux_update),
59719+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
59720
59721 seq_printf(m, "Pages : mrk=%u unc=%u\n",
59722- atomic_read(&fscache_n_marks),
59723- atomic_read(&fscache_n_uncaches));
59724+ atomic_read_unchecked(&fscache_n_marks),
59725+ atomic_read_unchecked(&fscache_n_uncaches));
59726
59727 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
59728 " oom=%u\n",
59729- atomic_read(&fscache_n_acquires),
59730- atomic_read(&fscache_n_acquires_null),
59731- atomic_read(&fscache_n_acquires_no_cache),
59732- atomic_read(&fscache_n_acquires_ok),
59733- atomic_read(&fscache_n_acquires_nobufs),
59734- atomic_read(&fscache_n_acquires_oom));
59735+ atomic_read_unchecked(&fscache_n_acquires),
59736+ atomic_read_unchecked(&fscache_n_acquires_null),
59737+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
59738+ atomic_read_unchecked(&fscache_n_acquires_ok),
59739+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
59740+ atomic_read_unchecked(&fscache_n_acquires_oom));
59741
59742 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
59743- atomic_read(&fscache_n_object_lookups),
59744- atomic_read(&fscache_n_object_lookups_negative),
59745- atomic_read(&fscache_n_object_lookups_positive),
59746- atomic_read(&fscache_n_object_created),
59747- atomic_read(&fscache_n_object_lookups_timed_out));
59748+ atomic_read_unchecked(&fscache_n_object_lookups),
59749+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
59750+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
59751+ atomic_read_unchecked(&fscache_n_object_created),
59752+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
59753
59754 seq_printf(m, "Invals : n=%u run=%u\n",
59755- atomic_read(&fscache_n_invalidates),
59756- atomic_read(&fscache_n_invalidates_run));
59757+ atomic_read_unchecked(&fscache_n_invalidates),
59758+ atomic_read_unchecked(&fscache_n_invalidates_run));
59759
59760 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
59761- atomic_read(&fscache_n_updates),
59762- atomic_read(&fscache_n_updates_null),
59763- atomic_read(&fscache_n_updates_run));
59764+ atomic_read_unchecked(&fscache_n_updates),
59765+ atomic_read_unchecked(&fscache_n_updates_null),
59766+ atomic_read_unchecked(&fscache_n_updates_run));
59767
59768 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
59769- atomic_read(&fscache_n_relinquishes),
59770- atomic_read(&fscache_n_relinquishes_null),
59771- atomic_read(&fscache_n_relinquishes_waitcrt),
59772- atomic_read(&fscache_n_relinquishes_retire));
59773+ atomic_read_unchecked(&fscache_n_relinquishes),
59774+ atomic_read_unchecked(&fscache_n_relinquishes_null),
59775+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
59776+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
59777
59778 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
59779- atomic_read(&fscache_n_attr_changed),
59780- atomic_read(&fscache_n_attr_changed_ok),
59781- atomic_read(&fscache_n_attr_changed_nobufs),
59782- atomic_read(&fscache_n_attr_changed_nomem),
59783- atomic_read(&fscache_n_attr_changed_calls));
59784+ atomic_read_unchecked(&fscache_n_attr_changed),
59785+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
59786+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
59787+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
59788+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
59789
59790 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
59791- atomic_read(&fscache_n_allocs),
59792- atomic_read(&fscache_n_allocs_ok),
59793- atomic_read(&fscache_n_allocs_wait),
59794- atomic_read(&fscache_n_allocs_nobufs),
59795- atomic_read(&fscache_n_allocs_intr));
59796+ atomic_read_unchecked(&fscache_n_allocs),
59797+ atomic_read_unchecked(&fscache_n_allocs_ok),
59798+ atomic_read_unchecked(&fscache_n_allocs_wait),
59799+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
59800+ atomic_read_unchecked(&fscache_n_allocs_intr));
59801 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
59802- atomic_read(&fscache_n_alloc_ops),
59803- atomic_read(&fscache_n_alloc_op_waits),
59804- atomic_read(&fscache_n_allocs_object_dead));
59805+ atomic_read_unchecked(&fscache_n_alloc_ops),
59806+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
59807+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
59808
59809 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
59810 " int=%u oom=%u\n",
59811- atomic_read(&fscache_n_retrievals),
59812- atomic_read(&fscache_n_retrievals_ok),
59813- atomic_read(&fscache_n_retrievals_wait),
59814- atomic_read(&fscache_n_retrievals_nodata),
59815- atomic_read(&fscache_n_retrievals_nobufs),
59816- atomic_read(&fscache_n_retrievals_intr),
59817- atomic_read(&fscache_n_retrievals_nomem));
59818+ atomic_read_unchecked(&fscache_n_retrievals),
59819+ atomic_read_unchecked(&fscache_n_retrievals_ok),
59820+ atomic_read_unchecked(&fscache_n_retrievals_wait),
59821+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
59822+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
59823+ atomic_read_unchecked(&fscache_n_retrievals_intr),
59824+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
59825 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
59826- atomic_read(&fscache_n_retrieval_ops),
59827- atomic_read(&fscache_n_retrieval_op_waits),
59828- atomic_read(&fscache_n_retrievals_object_dead));
59829+ atomic_read_unchecked(&fscache_n_retrieval_ops),
59830+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
59831+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
59832
59833 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
59834- atomic_read(&fscache_n_stores),
59835- atomic_read(&fscache_n_stores_ok),
59836- atomic_read(&fscache_n_stores_again),
59837- atomic_read(&fscache_n_stores_nobufs),
59838- atomic_read(&fscache_n_stores_oom));
59839+ atomic_read_unchecked(&fscache_n_stores),
59840+ atomic_read_unchecked(&fscache_n_stores_ok),
59841+ atomic_read_unchecked(&fscache_n_stores_again),
59842+ atomic_read_unchecked(&fscache_n_stores_nobufs),
59843+ atomic_read_unchecked(&fscache_n_stores_oom));
59844 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
59845- atomic_read(&fscache_n_store_ops),
59846- atomic_read(&fscache_n_store_calls),
59847- atomic_read(&fscache_n_store_pages),
59848- atomic_read(&fscache_n_store_radix_deletes),
59849- atomic_read(&fscache_n_store_pages_over_limit));
59850+ atomic_read_unchecked(&fscache_n_store_ops),
59851+ atomic_read_unchecked(&fscache_n_store_calls),
59852+ atomic_read_unchecked(&fscache_n_store_pages),
59853+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
59854+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
59855
59856 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
59857- atomic_read(&fscache_n_store_vmscan_not_storing),
59858- atomic_read(&fscache_n_store_vmscan_gone),
59859- atomic_read(&fscache_n_store_vmscan_busy),
59860- atomic_read(&fscache_n_store_vmscan_cancelled),
59861- atomic_read(&fscache_n_store_vmscan_wait));
59862+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
59863+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
59864+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
59865+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
59866+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
59867
59868 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
59869- atomic_read(&fscache_n_op_pend),
59870- atomic_read(&fscache_n_op_run),
59871- atomic_read(&fscache_n_op_enqueue),
59872- atomic_read(&fscache_n_op_cancelled),
59873- atomic_read(&fscache_n_op_rejected));
59874+ atomic_read_unchecked(&fscache_n_op_pend),
59875+ atomic_read_unchecked(&fscache_n_op_run),
59876+ atomic_read_unchecked(&fscache_n_op_enqueue),
59877+ atomic_read_unchecked(&fscache_n_op_cancelled),
59878+ atomic_read_unchecked(&fscache_n_op_rejected));
59879 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
59880- atomic_read(&fscache_n_op_deferred_release),
59881- atomic_read(&fscache_n_op_release),
59882- atomic_read(&fscache_n_op_gc));
59883+ atomic_read_unchecked(&fscache_n_op_deferred_release),
59884+ atomic_read_unchecked(&fscache_n_op_release),
59885+ atomic_read_unchecked(&fscache_n_op_gc));
59886
59887 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
59888 atomic_read(&fscache_n_cop_alloc_object),
59889diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
59890index b96a49b..9bfdc47 100644
59891--- a/fs/fuse/cuse.c
59892+++ b/fs/fuse/cuse.c
59893@@ -606,10 +606,12 @@ static int __init cuse_init(void)
59894 INIT_LIST_HEAD(&cuse_conntbl[i]);
59895
59896 /* inherit and extend fuse_dev_operations */
59897- cuse_channel_fops = fuse_dev_operations;
59898- cuse_channel_fops.owner = THIS_MODULE;
59899- cuse_channel_fops.open = cuse_channel_open;
59900- cuse_channel_fops.release = cuse_channel_release;
59901+ pax_open_kernel();
59902+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
59903+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
59904+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
59905+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
59906+ pax_close_kernel();
59907
59908 cuse_class = class_create(THIS_MODULE, "cuse");
59909 if (IS_ERR(cuse_class))
59910diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
59911index ef74ad5..c9ac759e 100644
59912--- a/fs/fuse/dev.c
59913+++ b/fs/fuse/dev.c
59914@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
59915 ret = 0;
59916 pipe_lock(pipe);
59917
59918- if (!pipe->readers) {
59919+ if (!atomic_read(&pipe->readers)) {
59920 send_sig(SIGPIPE, current, 0);
59921 if (!ret)
59922 ret = -EPIPE;
59923@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
59924 page_nr++;
59925 ret += buf->len;
59926
59927- if (pipe->files)
59928+ if (atomic_read(&pipe->files))
59929 do_wakeup = 1;
59930 }
59931
59932diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
59933index c3eb2c4..98007d4 100644
59934--- a/fs/fuse/dir.c
59935+++ b/fs/fuse/dir.c
59936@@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
59937 return link;
59938 }
59939
59940-static void free_link(char *link)
59941+static void free_link(const char *link)
59942 {
59943 if (!IS_ERR(link))
59944 free_page((unsigned long) link);
59945diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
59946index db23ce1..9e6cd9d 100644
59947--- a/fs/hostfs/hostfs_kern.c
59948+++ b/fs/hostfs/hostfs_kern.c
59949@@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59950
59951 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
59952 {
59953- char *s = nd_get_link(nd);
59954+ const char *s = nd_get_link(nd);
59955 if (!IS_ERR(s))
59956 __putname(s);
59957 }
59958diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
59959index d19b30a..ef89c36 100644
59960--- a/fs/hugetlbfs/inode.c
59961+++ b/fs/hugetlbfs/inode.c
59962@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
59963 struct mm_struct *mm = current->mm;
59964 struct vm_area_struct *vma;
59965 struct hstate *h = hstate_file(file);
59966+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
59967 struct vm_unmapped_area_info info;
59968
59969 if (len & ~huge_page_mask(h))
59970@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
59971 return addr;
59972 }
59973
59974+#ifdef CONFIG_PAX_RANDMMAP
59975+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
59976+#endif
59977+
59978 if (addr) {
59979 addr = ALIGN(addr, huge_page_size(h));
59980 vma = find_vma(mm, addr);
59981- if (TASK_SIZE - len >= addr &&
59982- (!vma || addr + len <= vma->vm_start))
59983+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
59984 return addr;
59985 }
59986
59987 info.flags = 0;
59988 info.length = len;
59989 info.low_limit = TASK_UNMAPPED_BASE;
59990+
59991+#ifdef CONFIG_PAX_RANDMMAP
59992+ if (mm->pax_flags & MF_PAX_RANDMMAP)
59993+ info.low_limit += mm->delta_mmap;
59994+#endif
59995+
59996 info.high_limit = TASK_SIZE;
59997 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
59998 info.align_offset = 0;
59999@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60000 };
60001 MODULE_ALIAS_FS("hugetlbfs");
60002
60003-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60004+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60005
60006 static int can_do_hugetlb_shm(void)
60007 {
60008diff --git a/fs/inode.c b/fs/inode.c
60009index 4bcdad3..1883822 100644
60010--- a/fs/inode.c
60011+++ b/fs/inode.c
60012@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60013
60014 #ifdef CONFIG_SMP
60015 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60016- static atomic_t shared_last_ino;
60017- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60018+ static atomic_unchecked_t shared_last_ino;
60019+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60020
60021 res = next - LAST_INO_BATCH;
60022 }
60023diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60024index 4a6cf28..d3a29d3 100644
60025--- a/fs/jffs2/erase.c
60026+++ b/fs/jffs2/erase.c
60027@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60028 struct jffs2_unknown_node marker = {
60029 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60030 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60031- .totlen = cpu_to_je32(c->cleanmarker_size)
60032+ .totlen = cpu_to_je32(c->cleanmarker_size),
60033+ .hdr_crc = cpu_to_je32(0)
60034 };
60035
60036 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60037diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60038index a6597d6..41b30ec 100644
60039--- a/fs/jffs2/wbuf.c
60040+++ b/fs/jffs2/wbuf.c
60041@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60042 {
60043 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60044 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60045- .totlen = constant_cpu_to_je32(8)
60046+ .totlen = constant_cpu_to_je32(8),
60047+ .hdr_crc = constant_cpu_to_je32(0)
60048 };
60049
60050 /*
60051diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60052index 6669aa2..36b033d 100644
60053--- a/fs/jfs/super.c
60054+++ b/fs/jfs/super.c
60055@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
60056
60057 jfs_inode_cachep =
60058 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60059- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60060+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60061 init_once);
60062 if (jfs_inode_cachep == NULL)
60063 return -ENOMEM;
60064diff --git a/fs/libfs.c b/fs/libfs.c
60065index a184424..944ddce 100644
60066--- a/fs/libfs.c
60067+++ b/fs/libfs.c
60068@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60069
60070 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
60071 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
60072+ char d_name[sizeof(next->d_iname)];
60073+ const unsigned char *name;
60074+
60075 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
60076 if (!simple_positive(next)) {
60077 spin_unlock(&next->d_lock);
60078@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60079
60080 spin_unlock(&next->d_lock);
60081 spin_unlock(&dentry->d_lock);
60082- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
60083+ name = next->d_name.name;
60084+ if (name == next->d_iname) {
60085+ memcpy(d_name, name, next->d_name.len);
60086+ name = d_name;
60087+ }
60088+ if (!dir_emit(ctx, name, next->d_name.len,
60089 next->d_inode->i_ino, dt_type(next->d_inode)))
60090 return 0;
60091 spin_lock(&dentry->d_lock);
60092@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
60093 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
60094 void *cookie)
60095 {
60096- char *s = nd_get_link(nd);
60097+ const char *s = nd_get_link(nd);
60098 if (!IS_ERR(s))
60099 kfree(s);
60100 }
60101diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
60102index acd3947..1f896e2 100644
60103--- a/fs/lockd/clntproc.c
60104+++ b/fs/lockd/clntproc.c
60105@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
60106 /*
60107 * Cookie counter for NLM requests
60108 */
60109-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
60110+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
60111
60112 void nlmclnt_next_cookie(struct nlm_cookie *c)
60113 {
60114- u32 cookie = atomic_inc_return(&nlm_cookie);
60115+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
60116
60117 memcpy(c->data, &cookie, 4);
60118 c->len=4;
60119diff --git a/fs/locks.c b/fs/locks.c
60120index 92a0f0a..45a48f0 100644
60121--- a/fs/locks.c
60122+++ b/fs/locks.c
60123@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
60124 return;
60125
60126 if (filp->f_op->flock) {
60127- struct file_lock fl = {
60128+ struct file_lock flock = {
60129 .fl_pid = current->tgid,
60130 .fl_file = filp,
60131 .fl_flags = FL_FLOCK,
60132 .fl_type = F_UNLCK,
60133 .fl_end = OFFSET_MAX,
60134 };
60135- filp->f_op->flock(filp, F_SETLKW, &fl);
60136- if (fl.fl_ops && fl.fl_ops->fl_release_private)
60137- fl.fl_ops->fl_release_private(&fl);
60138+ filp->f_op->flock(filp, F_SETLKW, &flock);
60139+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
60140+ flock.fl_ops->fl_release_private(&flock);
60141 }
60142
60143 spin_lock(&inode->i_lock);
60144diff --git a/fs/mount.h b/fs/mount.h
60145index d64c594..6c283db 100644
60146--- a/fs/mount.h
60147+++ b/fs/mount.h
60148@@ -11,7 +11,7 @@ struct mnt_namespace {
60149 u64 seq; /* Sequence number to prevent loops */
60150 wait_queue_head_t poll;
60151 int event;
60152-};
60153+} __randomize_layout;
60154
60155 struct mnt_pcp {
60156 int mnt_count;
60157@@ -57,7 +57,7 @@ struct mount {
60158 int mnt_expiry_mark; /* true if marked for expiry */
60159 int mnt_pinned;
60160 struct path mnt_ex_mountpoint;
60161-};
60162+} __randomize_layout;
60163
60164 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
60165
60166diff --git a/fs/namei.c b/fs/namei.c
60167index 3531dee..3177227 100644
60168--- a/fs/namei.c
60169+++ b/fs/namei.c
60170@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
60171 if (ret != -EACCES)
60172 return ret;
60173
60174+#ifdef CONFIG_GRKERNSEC
60175+ /* we'll block if we have to log due to a denied capability use */
60176+ if (mask & MAY_NOT_BLOCK)
60177+ return -ECHILD;
60178+#endif
60179+
60180 if (S_ISDIR(inode->i_mode)) {
60181 /* DACs are overridable for directories */
60182- if (inode_capable(inode, CAP_DAC_OVERRIDE))
60183- return 0;
60184 if (!(mask & MAY_WRITE))
60185- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60186+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60187+ inode_capable(inode, CAP_DAC_READ_SEARCH))
60188 return 0;
60189+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
60190+ return 0;
60191 return -EACCES;
60192 }
60193 /*
60194+ * Searching includes executable on directories, else just read.
60195+ */
60196+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60197+ if (mask == MAY_READ)
60198+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60199+ inode_capable(inode, CAP_DAC_READ_SEARCH))
60200+ return 0;
60201+
60202+ /*
60203 * Read/write DACs are always overridable.
60204 * Executable DACs are overridable when there is
60205 * at least one exec bit set.
60206@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
60207 if (inode_capable(inode, CAP_DAC_OVERRIDE))
60208 return 0;
60209
60210- /*
60211- * Searching includes executable on directories, else just read.
60212- */
60213- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60214- if (mask == MAY_READ)
60215- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60216- return 0;
60217-
60218 return -EACCES;
60219 }
60220
60221@@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60222 {
60223 struct dentry *dentry = link->dentry;
60224 int error;
60225- char *s;
60226+ const char *s;
60227
60228 BUG_ON(nd->flags & LOOKUP_RCU);
60229
60230@@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60231 if (error)
60232 goto out_put_nd_path;
60233
60234+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
60235+ dentry->d_inode, dentry, nd->path.mnt)) {
60236+ error = -EACCES;
60237+ goto out_put_nd_path;
60238+ }
60239+
60240 nd->last_type = LAST_BIND;
60241 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
60242 error = PTR_ERR(*p);
60243@@ -1582,6 +1596,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
60244 if (res)
60245 break;
60246 res = walk_component(nd, path, LOOKUP_FOLLOW);
60247+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
60248+ res = -EACCES;
60249 put_link(nd, &link, cookie);
60250 } while (res > 0);
60251
60252@@ -1655,7 +1671,7 @@ EXPORT_SYMBOL(full_name_hash);
60253 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
60254 {
60255 unsigned long a, b, adata, bdata, mask, hash, len;
60256- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60257+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60258
60259 hash = a = 0;
60260 len = -sizeof(unsigned long);
60261@@ -1939,6 +1955,8 @@ static int path_lookupat(int dfd, const char *name,
60262 if (err)
60263 break;
60264 err = lookup_last(nd, &path);
60265+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
60266+ err = -EACCES;
60267 put_link(nd, &link, cookie);
60268 }
60269 }
60270@@ -1946,6 +1964,13 @@ static int path_lookupat(int dfd, const char *name,
60271 if (!err)
60272 err = complete_walk(nd);
60273
60274+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
60275+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60276+ path_put(&nd->path);
60277+ err = -ENOENT;
60278+ }
60279+ }
60280+
60281 if (!err && nd->flags & LOOKUP_DIRECTORY) {
60282 if (!d_is_directory(nd->path.dentry)) {
60283 path_put(&nd->path);
60284@@ -1973,8 +1998,15 @@ static int filename_lookup(int dfd, struct filename *name,
60285 retval = path_lookupat(dfd, name->name,
60286 flags | LOOKUP_REVAL, nd);
60287
60288- if (likely(!retval))
60289+ if (likely(!retval)) {
60290 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
60291+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
60292+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
60293+ path_put(&nd->path);
60294+ return -ENOENT;
60295+ }
60296+ }
60297+ }
60298 return retval;
60299 }
60300
60301@@ -2548,6 +2580,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
60302 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
60303 return -EPERM;
60304
60305+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
60306+ return -EPERM;
60307+ if (gr_handle_rawio(inode))
60308+ return -EPERM;
60309+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
60310+ return -EACCES;
60311+
60312 return 0;
60313 }
60314
60315@@ -2779,7 +2818,7 @@ looked_up:
60316 * cleared otherwise prior to returning.
60317 */
60318 static int lookup_open(struct nameidata *nd, struct path *path,
60319- struct file *file,
60320+ struct path *link, struct file *file,
60321 const struct open_flags *op,
60322 bool got_write, int *opened)
60323 {
60324@@ -2814,6 +2853,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60325 /* Negative dentry, just create the file */
60326 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
60327 umode_t mode = op->mode;
60328+
60329+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
60330+ error = -EACCES;
60331+ goto out_dput;
60332+ }
60333+
60334+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
60335+ error = -EACCES;
60336+ goto out_dput;
60337+ }
60338+
60339 if (!IS_POSIXACL(dir->d_inode))
60340 mode &= ~current_umask();
60341 /*
60342@@ -2835,6 +2885,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60343 nd->flags & LOOKUP_EXCL);
60344 if (error)
60345 goto out_dput;
60346+ else
60347+ gr_handle_create(dentry, nd->path.mnt);
60348 }
60349 out_no_open:
60350 path->dentry = dentry;
60351@@ -2849,7 +2901,7 @@ out_dput:
60352 /*
60353 * Handle the last step of open()
60354 */
60355-static int do_last(struct nameidata *nd, struct path *path,
60356+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
60357 struct file *file, const struct open_flags *op,
60358 int *opened, struct filename *name)
60359 {
60360@@ -2899,6 +2951,15 @@ static int do_last(struct nameidata *nd, struct path *path,
60361 if (error)
60362 return error;
60363
60364+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
60365+ error = -ENOENT;
60366+ goto out;
60367+ }
60368+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
60369+ error = -EACCES;
60370+ goto out;
60371+ }
60372+
60373 audit_inode(name, dir, LOOKUP_PARENT);
60374 error = -EISDIR;
60375 /* trailing slashes? */
60376@@ -2918,7 +2979,7 @@ retry_lookup:
60377 */
60378 }
60379 mutex_lock(&dir->d_inode->i_mutex);
60380- error = lookup_open(nd, path, file, op, got_write, opened);
60381+ error = lookup_open(nd, path, link, file, op, got_write, opened);
60382 mutex_unlock(&dir->d_inode->i_mutex);
60383
60384 if (error <= 0) {
60385@@ -2942,11 +3003,28 @@ retry_lookup:
60386 goto finish_open_created;
60387 }
60388
60389+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
60390+ error = -ENOENT;
60391+ goto exit_dput;
60392+ }
60393+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
60394+ error = -EACCES;
60395+ goto exit_dput;
60396+ }
60397+
60398 /*
60399 * create/update audit record if it already exists.
60400 */
60401- if (d_is_positive(path->dentry))
60402+ if (d_is_positive(path->dentry)) {
60403+ /* only check if O_CREAT is specified, all other checks need to go
60404+ into may_open */
60405+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
60406+ error = -EACCES;
60407+ goto exit_dput;
60408+ }
60409+
60410 audit_inode(name, path->dentry, 0);
60411+ }
60412
60413 /*
60414 * If atomic_open() acquired write access it is dropped now due to
60415@@ -2987,6 +3065,11 @@ finish_lookup:
60416 }
60417 }
60418 BUG_ON(inode != path->dentry->d_inode);
60419+ /* if we're resolving a symlink to another symlink */
60420+ if (link && gr_handle_symlink_owner(link, inode)) {
60421+ error = -EACCES;
60422+ goto out;
60423+ }
60424 return 1;
60425 }
60426
60427@@ -2996,7 +3079,6 @@ finish_lookup:
60428 save_parent.dentry = nd->path.dentry;
60429 save_parent.mnt = mntget(path->mnt);
60430 nd->path.dentry = path->dentry;
60431-
60432 }
60433 nd->inode = inode;
60434 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
60435@@ -3006,7 +3088,18 @@ finish_open:
60436 path_put(&save_parent);
60437 return error;
60438 }
60439+
60440+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60441+ error = -ENOENT;
60442+ goto out;
60443+ }
60444+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
60445+ error = -EACCES;
60446+ goto out;
60447+ }
60448+
60449 audit_inode(name, nd->path.dentry, 0);
60450+
60451 error = -EISDIR;
60452 if ((open_flag & O_CREAT) &&
60453 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
60454@@ -3170,7 +3263,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60455 if (unlikely(error))
60456 goto out;
60457
60458- error = do_last(nd, &path, file, op, &opened, pathname);
60459+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
60460 while (unlikely(error > 0)) { /* trailing symlink */
60461 struct path link = path;
60462 void *cookie;
60463@@ -3188,7 +3281,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60464 error = follow_link(&link, nd, &cookie);
60465 if (unlikely(error))
60466 break;
60467- error = do_last(nd, &path, file, op, &opened, pathname);
60468+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
60469 put_link(nd, &link, cookie);
60470 }
60471 out:
60472@@ -3288,9 +3381,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
60473 goto unlock;
60474
60475 error = -EEXIST;
60476- if (d_is_positive(dentry))
60477+ if (d_is_positive(dentry)) {
60478+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
60479+ error = -ENOENT;
60480 goto fail;
60481-
60482+ }
60483 /*
60484 * Special case - lookup gave negative, but... we had foo/bar/
60485 * From the vfs_mknod() POV we just have a negative dentry -
60486@@ -3342,6 +3437,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
60487 }
60488 EXPORT_SYMBOL(user_path_create);
60489
60490+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
60491+{
60492+ struct filename *tmp = getname(pathname);
60493+ struct dentry *res;
60494+ if (IS_ERR(tmp))
60495+ return ERR_CAST(tmp);
60496+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
60497+ if (IS_ERR(res))
60498+ putname(tmp);
60499+ else
60500+ *to = tmp;
60501+ return res;
60502+}
60503+
60504 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
60505 {
60506 int error = may_create(dir, dentry);
60507@@ -3404,6 +3513,17 @@ retry:
60508
60509 if (!IS_POSIXACL(path.dentry->d_inode))
60510 mode &= ~current_umask();
60511+
60512+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
60513+ error = -EPERM;
60514+ goto out;
60515+ }
60516+
60517+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
60518+ error = -EACCES;
60519+ goto out;
60520+ }
60521+
60522 error = security_path_mknod(&path, dentry, mode, dev);
60523 if (error)
60524 goto out;
60525@@ -3420,6 +3540,8 @@ retry:
60526 break;
60527 }
60528 out:
60529+ if (!error)
60530+ gr_handle_create(dentry, path.mnt);
60531 done_path_create(&path, dentry);
60532 if (retry_estale(error, lookup_flags)) {
60533 lookup_flags |= LOOKUP_REVAL;
60534@@ -3472,9 +3594,16 @@ retry:
60535
60536 if (!IS_POSIXACL(path.dentry->d_inode))
60537 mode &= ~current_umask();
60538+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
60539+ error = -EACCES;
60540+ goto out;
60541+ }
60542 error = security_path_mkdir(&path, dentry, mode);
60543 if (!error)
60544 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
60545+ if (!error)
60546+ gr_handle_create(dentry, path.mnt);
60547+out:
60548 done_path_create(&path, dentry);
60549 if (retry_estale(error, lookup_flags)) {
60550 lookup_flags |= LOOKUP_REVAL;
60551@@ -3555,6 +3684,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
60552 struct filename *name;
60553 struct dentry *dentry;
60554 struct nameidata nd;
60555+ ino_t saved_ino = 0;
60556+ dev_t saved_dev = 0;
60557 unsigned int lookup_flags = 0;
60558 retry:
60559 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60560@@ -3587,10 +3718,21 @@ retry:
60561 error = -ENOENT;
60562 goto exit3;
60563 }
60564+
60565+ saved_ino = dentry->d_inode->i_ino;
60566+ saved_dev = gr_get_dev_from_dentry(dentry);
60567+
60568+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
60569+ error = -EACCES;
60570+ goto exit3;
60571+ }
60572+
60573 error = security_path_rmdir(&nd.path, dentry);
60574 if (error)
60575 goto exit3;
60576 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
60577+ if (!error && (saved_dev || saved_ino))
60578+ gr_handle_delete(saved_ino, saved_dev);
60579 exit3:
60580 dput(dentry);
60581 exit2:
60582@@ -3680,6 +3822,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
60583 struct nameidata nd;
60584 struct inode *inode = NULL;
60585 struct inode *delegated_inode = NULL;
60586+ ino_t saved_ino = 0;
60587+ dev_t saved_dev = 0;
60588 unsigned int lookup_flags = 0;
60589 retry:
60590 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60591@@ -3706,10 +3850,22 @@ retry_deleg:
60592 if (d_is_negative(dentry))
60593 goto slashes;
60594 ihold(inode);
60595+
60596+ if (inode->i_nlink <= 1) {
60597+ saved_ino = inode->i_ino;
60598+ saved_dev = gr_get_dev_from_dentry(dentry);
60599+ }
60600+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
60601+ error = -EACCES;
60602+ goto exit2;
60603+ }
60604+
60605 error = security_path_unlink(&nd.path, dentry);
60606 if (error)
60607 goto exit2;
60608 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
60609+ if (!error && (saved_ino || saved_dev))
60610+ gr_handle_delete(saved_ino, saved_dev);
60611 exit2:
60612 dput(dentry);
60613 }
60614@@ -3797,9 +3953,17 @@ retry:
60615 if (IS_ERR(dentry))
60616 goto out_putname;
60617
60618+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
60619+ error = -EACCES;
60620+ goto out;
60621+ }
60622+
60623 error = security_path_symlink(&path, dentry, from->name);
60624 if (!error)
60625 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
60626+ if (!error)
60627+ gr_handle_create(dentry, path.mnt);
60628+out:
60629 done_path_create(&path, dentry);
60630 if (retry_estale(error, lookup_flags)) {
60631 lookup_flags |= LOOKUP_REVAL;
60632@@ -3902,6 +4066,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
60633 struct dentry *new_dentry;
60634 struct path old_path, new_path;
60635 struct inode *delegated_inode = NULL;
60636+ struct filename *to = NULL;
60637 int how = 0;
60638 int error;
60639
60640@@ -3925,7 +4090,7 @@ retry:
60641 if (error)
60642 return error;
60643
60644- new_dentry = user_path_create(newdfd, newname, &new_path,
60645+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
60646 (how & LOOKUP_REVAL));
60647 error = PTR_ERR(new_dentry);
60648 if (IS_ERR(new_dentry))
60649@@ -3937,11 +4102,28 @@ retry:
60650 error = may_linkat(&old_path);
60651 if (unlikely(error))
60652 goto out_dput;
60653+
60654+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
60655+ old_path.dentry->d_inode,
60656+ old_path.dentry->d_inode->i_mode, to)) {
60657+ error = -EACCES;
60658+ goto out_dput;
60659+ }
60660+
60661+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
60662+ old_path.dentry, old_path.mnt, to)) {
60663+ error = -EACCES;
60664+ goto out_dput;
60665+ }
60666+
60667 error = security_path_link(old_path.dentry, &new_path, new_dentry);
60668 if (error)
60669 goto out_dput;
60670 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
60671+ if (!error)
60672+ gr_handle_create(new_dentry, new_path.mnt);
60673 out_dput:
60674+ putname(to);
60675 done_path_create(&new_path, new_dentry);
60676 if (delegated_inode) {
60677 error = break_deleg_wait(&delegated_inode);
60678@@ -4225,6 +4407,12 @@ retry_deleg:
60679 if (new_dentry == trap)
60680 goto exit5;
60681
60682+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
60683+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
60684+ to);
60685+ if (error)
60686+ goto exit5;
60687+
60688 error = security_path_rename(&oldnd.path, old_dentry,
60689 &newnd.path, new_dentry);
60690 if (error)
60691@@ -4232,6 +4420,9 @@ retry_deleg:
60692 error = vfs_rename(old_dir->d_inode, old_dentry,
60693 new_dir->d_inode, new_dentry,
60694 &delegated_inode);
60695+ if (!error)
60696+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
60697+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
60698 exit5:
60699 dput(new_dentry);
60700 exit4:
60701@@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
60702
60703 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
60704 {
60705+ char tmpbuf[64];
60706+ const char *newlink;
60707 int len;
60708
60709 len = PTR_ERR(link);
60710@@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
60711 len = strlen(link);
60712 if (len > (unsigned) buflen)
60713 len = buflen;
60714- if (copy_to_user(buffer, link, len))
60715+
60716+ if (len < sizeof(tmpbuf)) {
60717+ memcpy(tmpbuf, link, len);
60718+ newlink = tmpbuf;
60719+ } else
60720+ newlink = link;
60721+
60722+ if (copy_to_user(buffer, newlink, len))
60723 len = -EFAULT;
60724 out:
60725 return len;
60726diff --git a/fs/namespace.c b/fs/namespace.c
60727index be32ebc..c595734 100644
60728--- a/fs/namespace.c
60729+++ b/fs/namespace.c
60730@@ -1293,6 +1293,9 @@ static int do_umount(struct mount *mnt, int flags)
60731 if (!(sb->s_flags & MS_RDONLY))
60732 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
60733 up_write(&sb->s_umount);
60734+
60735+ gr_log_remount(mnt->mnt_devname, retval);
60736+
60737 return retval;
60738 }
60739
60740@@ -1315,6 +1318,9 @@ static int do_umount(struct mount *mnt, int flags)
60741 }
60742 unlock_mount_hash();
60743 namespace_unlock();
60744+
60745+ gr_log_unmount(mnt->mnt_devname, retval);
60746+
60747 return retval;
60748 }
60749
60750@@ -1334,7 +1340,7 @@ static inline bool may_mount(void)
60751 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
60752 */
60753
60754-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
60755+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
60756 {
60757 struct path path;
60758 struct mount *mnt;
60759@@ -1376,7 +1382,7 @@ out:
60760 /*
60761 * The 2.0 compatible umount. No flags.
60762 */
60763-SYSCALL_DEFINE1(oldumount, char __user *, name)
60764+SYSCALL_DEFINE1(oldumount, const char __user *, name)
60765 {
60766 return sys_umount(name, 0);
60767 }
60768@@ -2379,6 +2385,16 @@ long do_mount(const char *dev_name, const char *dir_name,
60769 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
60770 MS_STRICTATIME);
60771
60772+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
60773+ retval = -EPERM;
60774+ goto dput_out;
60775+ }
60776+
60777+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
60778+ retval = -EPERM;
60779+ goto dput_out;
60780+ }
60781+
60782 if (flags & MS_REMOUNT)
60783 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
60784 data_page);
60785@@ -2393,6 +2409,9 @@ long do_mount(const char *dev_name, const char *dir_name,
60786 dev_name, data_page);
60787 dput_out:
60788 path_put(&path);
60789+
60790+ gr_log_mount(dev_name, dir_name, retval);
60791+
60792 return retval;
60793 }
60794
60795@@ -2410,7 +2429,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
60796 * number incrementing at 10Ghz will take 12,427 years to wrap which
60797 * is effectively never, so we can ignore the possibility.
60798 */
60799-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
60800+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
60801
60802 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60803 {
60804@@ -2425,7 +2444,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60805 kfree(new_ns);
60806 return ERR_PTR(ret);
60807 }
60808- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
60809+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
60810 atomic_set(&new_ns->count, 1);
60811 new_ns->root = NULL;
60812 INIT_LIST_HEAD(&new_ns->list);
60813@@ -2435,7 +2454,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60814 return new_ns;
60815 }
60816
60817-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60818+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60819 struct user_namespace *user_ns, struct fs_struct *new_fs)
60820 {
60821 struct mnt_namespace *new_ns;
60822@@ -2556,8 +2575,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
60823 }
60824 EXPORT_SYMBOL(mount_subtree);
60825
60826-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
60827- char __user *, type, unsigned long, flags, void __user *, data)
60828+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
60829+ const char __user *, type, unsigned long, flags, void __user *, data)
60830 {
60831 int ret;
60832 char *kernel_type;
60833@@ -2670,6 +2689,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
60834 if (error)
60835 goto out2;
60836
60837+ if (gr_handle_chroot_pivot()) {
60838+ error = -EPERM;
60839+ goto out2;
60840+ }
60841+
60842 get_fs_root(current->fs, &root);
60843 old_mp = lock_mount(&old);
60844 error = PTR_ERR(old_mp);
60845@@ -2930,7 +2954,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
60846 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
60847 return -EPERM;
60848
60849- if (fs->users != 1)
60850+ if (atomic_read(&fs->users) != 1)
60851 return -EINVAL;
60852
60853 get_mnt_ns(mnt_ns);
60854diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
60855index f4ccfe6..a5cf064 100644
60856--- a/fs/nfs/callback_xdr.c
60857+++ b/fs/nfs/callback_xdr.c
60858@@ -51,7 +51,7 @@ struct callback_op {
60859 callback_decode_arg_t decode_args;
60860 callback_encode_res_t encode_res;
60861 long res_maxsize;
60862-};
60863+} __do_const;
60864
60865 static struct callback_op callback_ops[];
60866
60867diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
60868index 00ad1c2..2fde15e 100644
60869--- a/fs/nfs/inode.c
60870+++ b/fs/nfs/inode.c
60871@@ -1146,16 +1146,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
60872 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
60873 }
60874
60875-static atomic_long_t nfs_attr_generation_counter;
60876+static atomic_long_unchecked_t nfs_attr_generation_counter;
60877
60878 static unsigned long nfs_read_attr_generation_counter(void)
60879 {
60880- return atomic_long_read(&nfs_attr_generation_counter);
60881+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
60882 }
60883
60884 unsigned long nfs_inc_attr_generation_counter(void)
60885 {
60886- return atomic_long_inc_return(&nfs_attr_generation_counter);
60887+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
60888 }
60889
60890 void nfs_fattr_init(struct nfs_fattr *fattr)
60891diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
60892index 419572f..5414a23 100644
60893--- a/fs/nfsd/nfs4proc.c
60894+++ b/fs/nfsd/nfs4proc.c
60895@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
60896 nfsd4op_rsize op_rsize_bop;
60897 stateid_getter op_get_currentstateid;
60898 stateid_setter op_set_currentstateid;
60899-};
60900+} __do_const;
60901
60902 static struct nfsd4_operation nfsd4_ops[];
60903
60904diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
60905index ee7237f..e3ae60a 100644
60906--- a/fs/nfsd/nfs4xdr.c
60907+++ b/fs/nfsd/nfs4xdr.c
60908@@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
60909
60910 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
60911
60912-static nfsd4_dec nfsd4_dec_ops[] = {
60913+static const nfsd4_dec nfsd4_dec_ops[] = {
60914 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
60915 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
60916 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
60917diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
60918index b6af150..f6ec5e3 100644
60919--- a/fs/nfsd/nfscache.c
60920+++ b/fs/nfsd/nfscache.c
60921@@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
60922 {
60923 struct svc_cacherep *rp = rqstp->rq_cacherep;
60924 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
60925- int len;
60926+ long len;
60927 size_t bufsize = 0;
60928
60929 if (!rp)
60930 return;
60931
60932- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
60933- len >>= 2;
60934+ if (statp) {
60935+ len = (char*)statp - (char*)resv->iov_base;
60936+ len = resv->iov_len - len;
60937+ len >>= 2;
60938+ }
60939
60940 /* Don't cache excessive amounts of data and XDR failures */
60941 if (!statp || len > (256 >> 2)) {
60942diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
60943index 7eea63c..a35f4fb 100644
60944--- a/fs/nfsd/vfs.c
60945+++ b/fs/nfsd/vfs.c
60946@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
60947 } else {
60948 oldfs = get_fs();
60949 set_fs(KERNEL_DS);
60950- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
60951+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
60952 set_fs(oldfs);
60953 }
60954
60955@@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
60956
60957 /* Write the data. */
60958 oldfs = get_fs(); set_fs(KERNEL_DS);
60959- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
60960+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
60961 set_fs(oldfs);
60962 if (host_err < 0)
60963 goto out_nfserr;
60964@@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
60965 */
60966
60967 oldfs = get_fs(); set_fs(KERNEL_DS);
60968- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
60969+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
60970 set_fs(oldfs);
60971
60972 if (host_err < 0)
60973diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
60974index fea6bd5..8ee9d81 100644
60975--- a/fs/nls/nls_base.c
60976+++ b/fs/nls/nls_base.c
60977@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
60978
60979 int register_nls(struct nls_table * nls)
60980 {
60981- struct nls_table ** tmp = &tables;
60982+ struct nls_table *tmp = tables;
60983
60984 if (nls->next)
60985 return -EBUSY;
60986
60987 spin_lock(&nls_lock);
60988- while (*tmp) {
60989- if (nls == *tmp) {
60990+ while (tmp) {
60991+ if (nls == tmp) {
60992 spin_unlock(&nls_lock);
60993 return -EBUSY;
60994 }
60995- tmp = &(*tmp)->next;
60996+ tmp = tmp->next;
60997 }
60998- nls->next = tables;
60999+ pax_open_kernel();
61000+ *(struct nls_table **)&nls->next = tables;
61001+ pax_close_kernel();
61002 tables = nls;
61003 spin_unlock(&nls_lock);
61004 return 0;
61005@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
61006
61007 int unregister_nls(struct nls_table * nls)
61008 {
61009- struct nls_table ** tmp = &tables;
61010+ struct nls_table * const * tmp = &tables;
61011
61012 spin_lock(&nls_lock);
61013 while (*tmp) {
61014 if (nls == *tmp) {
61015- *tmp = nls->next;
61016+ pax_open_kernel();
61017+ *(struct nls_table **)tmp = nls->next;
61018+ pax_close_kernel();
61019 spin_unlock(&nls_lock);
61020 return 0;
61021 }
61022diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
61023index 7424929..35f6be5 100644
61024--- a/fs/nls/nls_euc-jp.c
61025+++ b/fs/nls/nls_euc-jp.c
61026@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
61027 p_nls = load_nls("cp932");
61028
61029 if (p_nls) {
61030- table.charset2upper = p_nls->charset2upper;
61031- table.charset2lower = p_nls->charset2lower;
61032+ pax_open_kernel();
61033+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61034+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61035+ pax_close_kernel();
61036 return register_nls(&table);
61037 }
61038
61039diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
61040index e7bc1d7..06bd4bb 100644
61041--- a/fs/nls/nls_koi8-ru.c
61042+++ b/fs/nls/nls_koi8-ru.c
61043@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
61044 p_nls = load_nls("koi8-u");
61045
61046 if (p_nls) {
61047- table.charset2upper = p_nls->charset2upper;
61048- table.charset2lower = p_nls->charset2lower;
61049+ pax_open_kernel();
61050+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61051+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61052+ pax_close_kernel();
61053 return register_nls(&table);
61054 }
61055
61056diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
61057index e44cb64..4807084 100644
61058--- a/fs/notify/fanotify/fanotify_user.c
61059+++ b/fs/notify/fanotify/fanotify_user.c
61060@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
61061
61062 fd = fanotify_event_metadata.fd;
61063 ret = -EFAULT;
61064- if (copy_to_user(buf, &fanotify_event_metadata,
61065- fanotify_event_metadata.event_len))
61066+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
61067+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
61068 goto out_close_fd;
61069
61070 ret = prepare_for_access_response(group, event, fd);
61071diff --git a/fs/notify/notification.c b/fs/notify/notification.c
61072index 7b51b05..5ea5ef6 100644
61073--- a/fs/notify/notification.c
61074+++ b/fs/notify/notification.c
61075@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
61076 * get set to 0 so it will never get 'freed'
61077 */
61078 static struct fsnotify_event *q_overflow_event;
61079-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61080+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61081
61082 /**
61083 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
61084@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61085 */
61086 u32 fsnotify_get_cookie(void)
61087 {
61088- return atomic_inc_return(&fsnotify_sync_cookie);
61089+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
61090 }
61091 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
61092
61093diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
61094index 9e38daf..5727cae 100644
61095--- a/fs/ntfs/dir.c
61096+++ b/fs/ntfs/dir.c
61097@@ -1310,7 +1310,7 @@ find_next_index_buffer:
61098 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
61099 ~(s64)(ndir->itype.index.block_size - 1)));
61100 /* Bounds checks. */
61101- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61102+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61103 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
61104 "inode 0x%lx or driver bug.", vdir->i_ino);
61105 goto err_out;
61106diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
61107index ea4ba9d..1e13d34 100644
61108--- a/fs/ntfs/file.c
61109+++ b/fs/ntfs/file.c
61110@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
61111 char *addr;
61112 size_t total = 0;
61113 unsigned len;
61114- int left;
61115+ unsigned left;
61116
61117 do {
61118 len = PAGE_CACHE_SIZE - ofs;
61119diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
61120index 82650d5..db37dcf 100644
61121--- a/fs/ntfs/super.c
61122+++ b/fs/ntfs/super.c
61123@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61124 if (!silent)
61125 ntfs_error(sb, "Primary boot sector is invalid.");
61126 } else if (!silent)
61127- ntfs_error(sb, read_err_str, "primary");
61128+ ntfs_error(sb, read_err_str, "%s", "primary");
61129 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
61130 if (bh_primary)
61131 brelse(bh_primary);
61132@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61133 goto hotfix_primary_boot_sector;
61134 brelse(bh_backup);
61135 } else if (!silent)
61136- ntfs_error(sb, read_err_str, "backup");
61137+ ntfs_error(sb, read_err_str, "%s", "backup");
61138 /* Try to read NT3.51- backup boot sector. */
61139 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
61140 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
61141@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61142 "sector.");
61143 brelse(bh_backup);
61144 } else if (!silent)
61145- ntfs_error(sb, read_err_str, "backup");
61146+ ntfs_error(sb, read_err_str, "%s", "backup");
61147 /* We failed. Cleanup and return. */
61148 if (bh_primary)
61149 brelse(bh_primary);
61150diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
61151index cd5496b..26a1055 100644
61152--- a/fs/ocfs2/localalloc.c
61153+++ b/fs/ocfs2/localalloc.c
61154@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
61155 goto bail;
61156 }
61157
61158- atomic_inc(&osb->alloc_stats.moves);
61159+ atomic_inc_unchecked(&osb->alloc_stats.moves);
61160
61161 bail:
61162 if (handle)
61163diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
61164index 3a90347..c40bef8 100644
61165--- a/fs/ocfs2/ocfs2.h
61166+++ b/fs/ocfs2/ocfs2.h
61167@@ -235,11 +235,11 @@ enum ocfs2_vol_state
61168
61169 struct ocfs2_alloc_stats
61170 {
61171- atomic_t moves;
61172- atomic_t local_data;
61173- atomic_t bitmap_data;
61174- atomic_t bg_allocs;
61175- atomic_t bg_extends;
61176+ atomic_unchecked_t moves;
61177+ atomic_unchecked_t local_data;
61178+ atomic_unchecked_t bitmap_data;
61179+ atomic_unchecked_t bg_allocs;
61180+ atomic_unchecked_t bg_extends;
61181 };
61182
61183 enum ocfs2_local_alloc_state
61184diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
61185index 2c91452..77a3cd2 100644
61186--- a/fs/ocfs2/suballoc.c
61187+++ b/fs/ocfs2/suballoc.c
61188@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
61189 mlog_errno(status);
61190 goto bail;
61191 }
61192- atomic_inc(&osb->alloc_stats.bg_extends);
61193+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
61194
61195 /* You should never ask for this much metadata */
61196 BUG_ON(bits_wanted >
61197@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
61198 mlog_errno(status);
61199 goto bail;
61200 }
61201- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61202+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61203
61204 *suballoc_loc = res.sr_bg_blkno;
61205 *suballoc_bit_start = res.sr_bit_offset;
61206@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
61207 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
61208 res->sr_bits);
61209
61210- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61211+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61212
61213 BUG_ON(res->sr_bits != 1);
61214
61215@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
61216 mlog_errno(status);
61217 goto bail;
61218 }
61219- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61220+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61221
61222 BUG_ON(res.sr_bits != 1);
61223
61224@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61225 cluster_start,
61226 num_clusters);
61227 if (!status)
61228- atomic_inc(&osb->alloc_stats.local_data);
61229+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
61230 } else {
61231 if (min_clusters > (osb->bitmap_cpg - 1)) {
61232 /* The only paths asking for contiguousness
61233@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61234 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
61235 res.sr_bg_blkno,
61236 res.sr_bit_offset);
61237- atomic_inc(&osb->alloc_stats.bitmap_data);
61238+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
61239 *num_clusters = res.sr_bits;
61240 }
61241 }
61242diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
61243index c414929..5c9ee542 100644
61244--- a/fs/ocfs2/super.c
61245+++ b/fs/ocfs2/super.c
61246@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
61247 "%10s => GlobalAllocs: %d LocalAllocs: %d "
61248 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
61249 "Stats",
61250- atomic_read(&osb->alloc_stats.bitmap_data),
61251- atomic_read(&osb->alloc_stats.local_data),
61252- atomic_read(&osb->alloc_stats.bg_allocs),
61253- atomic_read(&osb->alloc_stats.moves),
61254- atomic_read(&osb->alloc_stats.bg_extends));
61255+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
61256+ atomic_read_unchecked(&osb->alloc_stats.local_data),
61257+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
61258+ atomic_read_unchecked(&osb->alloc_stats.moves),
61259+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
61260
61261 out += snprintf(buf + out, len - out,
61262 "%10s => State: %u Descriptor: %llu Size: %u bits "
61263@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
61264 spin_lock_init(&osb->osb_xattr_lock);
61265 ocfs2_init_steal_slots(osb);
61266
61267- atomic_set(&osb->alloc_stats.moves, 0);
61268- atomic_set(&osb->alloc_stats.local_data, 0);
61269- atomic_set(&osb->alloc_stats.bitmap_data, 0);
61270- atomic_set(&osb->alloc_stats.bg_allocs, 0);
61271- atomic_set(&osb->alloc_stats.bg_extends, 0);
61272+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
61273+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
61274+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
61275+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
61276+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
61277
61278 /* Copy the blockcheck stats from the superblock probe */
61279 osb->osb_ecc_stats = *stats;
61280diff --git a/fs/open.c b/fs/open.c
61281index 4b3e1ed..1c84599 100644
61282--- a/fs/open.c
61283+++ b/fs/open.c
61284@@ -32,6 +32,8 @@
61285 #include <linux/dnotify.h>
61286 #include <linux/compat.h>
61287
61288+#define CREATE_TRACE_POINTS
61289+#include <trace/events/fs.h>
61290 #include "internal.h"
61291
61292 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
61293@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
61294 error = locks_verify_truncate(inode, NULL, length);
61295 if (!error)
61296 error = security_path_truncate(path);
61297+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
61298+ error = -EACCES;
61299 if (!error)
61300 error = do_truncate(path->dentry, length, 0, NULL);
61301
61302@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
61303 error = locks_verify_truncate(inode, f.file, length);
61304 if (!error)
61305 error = security_path_truncate(&f.file->f_path);
61306+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
61307+ error = -EACCES;
61308 if (!error)
61309 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
61310 sb_end_write(inode->i_sb);
61311@@ -361,6 +367,9 @@ retry:
61312 if (__mnt_is_readonly(path.mnt))
61313 res = -EROFS;
61314
61315+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
61316+ res = -EACCES;
61317+
61318 out_path_release:
61319 path_put(&path);
61320 if (retry_estale(res, lookup_flags)) {
61321@@ -392,6 +401,8 @@ retry:
61322 if (error)
61323 goto dput_and_out;
61324
61325+ gr_log_chdir(path.dentry, path.mnt);
61326+
61327 set_fs_pwd(current->fs, &path);
61328
61329 dput_and_out:
61330@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
61331 goto out_putf;
61332
61333 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
61334+
61335+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
61336+ error = -EPERM;
61337+
61338+ if (!error)
61339+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
61340+
61341 if (!error)
61342 set_fs_pwd(current->fs, &f.file->f_path);
61343 out_putf:
61344@@ -450,7 +468,13 @@ retry:
61345 if (error)
61346 goto dput_and_out;
61347
61348+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
61349+ goto dput_and_out;
61350+
61351 set_fs_root(current->fs, &path);
61352+
61353+ gr_handle_chroot_chdir(&path);
61354+
61355 error = 0;
61356 dput_and_out:
61357 path_put(&path);
61358@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
61359 return error;
61360 retry_deleg:
61361 mutex_lock(&inode->i_mutex);
61362+
61363+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
61364+ error = -EACCES;
61365+ goto out_unlock;
61366+ }
61367+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
61368+ error = -EACCES;
61369+ goto out_unlock;
61370+ }
61371+
61372 error = security_path_chmod(path, mode);
61373 if (error)
61374 goto out_unlock;
61375@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
61376 uid = make_kuid(current_user_ns(), user);
61377 gid = make_kgid(current_user_ns(), group);
61378
61379+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
61380+ return -EACCES;
61381+
61382 newattrs.ia_valid = ATTR_CTIME;
61383 if (user != (uid_t) -1) {
61384 if (!uid_valid(uid))
61385@@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
61386 } else {
61387 fsnotify_open(f);
61388 fd_install(fd, f);
61389+ trace_do_sys_open(tmp->name, flags, mode);
61390 }
61391 }
61392 putname(tmp);
61393diff --git a/fs/pipe.c b/fs/pipe.c
61394index 0e0752e..7cfdd50 100644
61395--- a/fs/pipe.c
61396+++ b/fs/pipe.c
61397@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
61398
61399 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
61400 {
61401- if (pipe->files)
61402+ if (atomic_read(&pipe->files))
61403 mutex_lock_nested(&pipe->mutex, subclass);
61404 }
61405
61406@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
61407
61408 void pipe_unlock(struct pipe_inode_info *pipe)
61409 {
61410- if (pipe->files)
61411+ if (atomic_read(&pipe->files))
61412 mutex_unlock(&pipe->mutex);
61413 }
61414 EXPORT_SYMBOL(pipe_unlock);
61415@@ -449,9 +449,9 @@ redo:
61416 }
61417 if (bufs) /* More to do? */
61418 continue;
61419- if (!pipe->writers)
61420+ if (!atomic_read(&pipe->writers))
61421 break;
61422- if (!pipe->waiting_writers) {
61423+ if (!atomic_read(&pipe->waiting_writers)) {
61424 /* syscall merging: Usually we must not sleep
61425 * if O_NONBLOCK is set, or if we got some data.
61426 * But if a writer sleeps in kernel space, then
61427@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
61428 ret = 0;
61429 __pipe_lock(pipe);
61430
61431- if (!pipe->readers) {
61432+ if (!atomic_read(&pipe->readers)) {
61433 send_sig(SIGPIPE, current, 0);
61434 ret = -EPIPE;
61435 goto out;
61436@@ -562,7 +562,7 @@ redo1:
61437 for (;;) {
61438 int bufs;
61439
61440- if (!pipe->readers) {
61441+ if (!atomic_read(&pipe->readers)) {
61442 send_sig(SIGPIPE, current, 0);
61443 if (!ret)
61444 ret = -EPIPE;
61445@@ -653,9 +653,9 @@ redo2:
61446 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61447 do_wakeup = 0;
61448 }
61449- pipe->waiting_writers++;
61450+ atomic_inc(&pipe->waiting_writers);
61451 pipe_wait(pipe);
61452- pipe->waiting_writers--;
61453+ atomic_dec(&pipe->waiting_writers);
61454 }
61455 out:
61456 __pipe_unlock(pipe);
61457@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61458 mask = 0;
61459 if (filp->f_mode & FMODE_READ) {
61460 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
61461- if (!pipe->writers && filp->f_version != pipe->w_counter)
61462+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
61463 mask |= POLLHUP;
61464 }
61465
61466@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61467 * Most Unices do not set POLLERR for FIFOs but on Linux they
61468 * behave exactly like pipes for poll().
61469 */
61470- if (!pipe->readers)
61471+ if (!atomic_read(&pipe->readers))
61472 mask |= POLLERR;
61473 }
61474
61475@@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
61476 int kill = 0;
61477
61478 spin_lock(&inode->i_lock);
61479- if (!--pipe->files) {
61480+ if (atomic_dec_and_test(&pipe->files)) {
61481 inode->i_pipe = NULL;
61482 kill = 1;
61483 }
61484@@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
61485
61486 __pipe_lock(pipe);
61487 if (file->f_mode & FMODE_READ)
61488- pipe->readers--;
61489+ atomic_dec(&pipe->readers);
61490 if (file->f_mode & FMODE_WRITE)
61491- pipe->writers--;
61492+ atomic_dec(&pipe->writers);
61493
61494- if (pipe->readers || pipe->writers) {
61495+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
61496 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
61497 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61498 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
61499@@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
61500 kfree(pipe);
61501 }
61502
61503-static struct vfsmount *pipe_mnt __read_mostly;
61504+struct vfsmount *pipe_mnt __read_mostly;
61505
61506 /*
61507 * pipefs_dname() is called from d_path().
61508@@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
61509 goto fail_iput;
61510
61511 inode->i_pipe = pipe;
61512- pipe->files = 2;
61513- pipe->readers = pipe->writers = 1;
61514+ atomic_set(&pipe->files, 2);
61515+ atomic_set(&pipe->readers, 1);
61516+ atomic_set(&pipe->writers, 1);
61517 inode->i_fop = &pipefifo_fops;
61518
61519 /*
61520@@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
61521 spin_lock(&inode->i_lock);
61522 if (inode->i_pipe) {
61523 pipe = inode->i_pipe;
61524- pipe->files++;
61525+ atomic_inc(&pipe->files);
61526 spin_unlock(&inode->i_lock);
61527 } else {
61528 spin_unlock(&inode->i_lock);
61529 pipe = alloc_pipe_info();
61530 if (!pipe)
61531 return -ENOMEM;
61532- pipe->files = 1;
61533+ atomic_set(&pipe->files, 1);
61534 spin_lock(&inode->i_lock);
61535 if (unlikely(inode->i_pipe)) {
61536- inode->i_pipe->files++;
61537+ atomic_inc(&inode->i_pipe->files);
61538 spin_unlock(&inode->i_lock);
61539 free_pipe_info(pipe);
61540 pipe = inode->i_pipe;
61541@@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
61542 * opened, even when there is no process writing the FIFO.
61543 */
61544 pipe->r_counter++;
61545- if (pipe->readers++ == 0)
61546+ if (atomic_inc_return(&pipe->readers) == 1)
61547 wake_up_partner(pipe);
61548
61549- if (!is_pipe && !pipe->writers) {
61550+ if (!is_pipe && !atomic_read(&pipe->writers)) {
61551 if ((filp->f_flags & O_NONBLOCK)) {
61552 /* suppress POLLHUP until we have
61553 * seen a writer */
61554@@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
61555 * errno=ENXIO when there is no process reading the FIFO.
61556 */
61557 ret = -ENXIO;
61558- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
61559+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
61560 goto err;
61561
61562 pipe->w_counter++;
61563- if (!pipe->writers++)
61564+ if (atomic_inc_return(&pipe->writers) == 1)
61565 wake_up_partner(pipe);
61566
61567- if (!is_pipe && !pipe->readers) {
61568+ if (!is_pipe && !atomic_read(&pipe->readers)) {
61569 if (wait_for_partner(pipe, &pipe->r_counter))
61570 goto err_wr;
61571 }
61572@@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
61573 * the process can at least talk to itself.
61574 */
61575
61576- pipe->readers++;
61577- pipe->writers++;
61578+ atomic_inc(&pipe->readers);
61579+ atomic_inc(&pipe->writers);
61580 pipe->r_counter++;
61581 pipe->w_counter++;
61582- if (pipe->readers == 1 || pipe->writers == 1)
61583+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
61584 wake_up_partner(pipe);
61585 break;
61586
61587@@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
61588 return 0;
61589
61590 err_rd:
61591- if (!--pipe->readers)
61592+ if (atomic_dec_and_test(&pipe->readers))
61593 wake_up_interruptible(&pipe->wait);
61594 ret = -ERESTARTSYS;
61595 goto err;
61596
61597 err_wr:
61598- if (!--pipe->writers)
61599+ if (atomic_dec_and_test(&pipe->writers))
61600 wake_up_interruptible(&pipe->wait);
61601 ret = -ERESTARTSYS;
61602 goto err;
61603diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
61604index 2183fcf..3c32a98 100644
61605--- a/fs/proc/Kconfig
61606+++ b/fs/proc/Kconfig
61607@@ -30,7 +30,7 @@ config PROC_FS
61608
61609 config PROC_KCORE
61610 bool "/proc/kcore support" if !ARM
61611- depends on PROC_FS && MMU
61612+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
61613 help
61614 Provides a virtual ELF core file of the live kernel. This can
61615 be read with gdb and other ELF tools. No modifications can be
61616@@ -38,8 +38,8 @@ config PROC_KCORE
61617
61618 config PROC_VMCORE
61619 bool "/proc/vmcore support"
61620- depends on PROC_FS && CRASH_DUMP
61621- default y
61622+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
61623+ default n
61624 help
61625 Exports the dump image of crashed kernel in ELF format.
61626
61627@@ -63,8 +63,8 @@ config PROC_SYSCTL
61628 limited in memory.
61629
61630 config PROC_PAGE_MONITOR
61631- default y
61632- depends on PROC_FS && MMU
61633+ default n
61634+ depends on PROC_FS && MMU && !GRKERNSEC
61635 bool "Enable /proc page monitoring" if EXPERT
61636 help
61637 Various /proc files exist to monitor process memory utilization:
61638diff --git a/fs/proc/array.c b/fs/proc/array.c
61639index 1bd2077..2f7cfd5 100644
61640--- a/fs/proc/array.c
61641+++ b/fs/proc/array.c
61642@@ -60,6 +60,7 @@
61643 #include <linux/tty.h>
61644 #include <linux/string.h>
61645 #include <linux/mman.h>
61646+#include <linux/grsecurity.h>
61647 #include <linux/proc_fs.h>
61648 #include <linux/ioport.h>
61649 #include <linux/uaccess.h>
61650@@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
61651 seq_putc(m, '\n');
61652 }
61653
61654+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61655+static inline void task_pax(struct seq_file *m, struct task_struct *p)
61656+{
61657+ if (p->mm)
61658+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
61659+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
61660+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
61661+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
61662+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
61663+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
61664+ else
61665+ seq_printf(m, "PaX:\t-----\n");
61666+}
61667+#endif
61668+
61669 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61670 struct pid *pid, struct task_struct *task)
61671 {
61672@@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61673 task_cpus_allowed(m, task);
61674 cpuset_task_status_allowed(m, task);
61675 task_context_switch_counts(m, task);
61676+
61677+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61678+ task_pax(m, task);
61679+#endif
61680+
61681+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
61682+ task_grsec_rbac(m, task);
61683+#endif
61684+
61685 return 0;
61686 }
61687
61688+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61689+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61690+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61691+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61692+#endif
61693+
61694 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61695 struct pid *pid, struct task_struct *task, int whole)
61696 {
61697@@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61698 char tcomm[sizeof(task->comm)];
61699 unsigned long flags;
61700
61701+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61702+ if (current->exec_id != m->exec_id) {
61703+ gr_log_badprocpid("stat");
61704+ return 0;
61705+ }
61706+#endif
61707+
61708 state = *get_task_state(task);
61709 vsize = eip = esp = 0;
61710 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61711@@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61712 gtime = task_gtime(task);
61713 }
61714
61715+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61716+ if (PAX_RAND_FLAGS(mm)) {
61717+ eip = 0;
61718+ esp = 0;
61719+ wchan = 0;
61720+ }
61721+#endif
61722+#ifdef CONFIG_GRKERNSEC_HIDESYM
61723+ wchan = 0;
61724+ eip =0;
61725+ esp =0;
61726+#endif
61727+
61728 /* scale priority and nice values from timeslices to -20..20 */
61729 /* to make it look like a "normal" Unix priority/nice value */
61730 priority = task_prio(task);
61731@@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61732 seq_put_decimal_ull(m, ' ', vsize);
61733 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
61734 seq_put_decimal_ull(m, ' ', rsslim);
61735+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61736+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
61737+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
61738+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
61739+#else
61740 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
61741 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
61742 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
61743+#endif
61744 seq_put_decimal_ull(m, ' ', esp);
61745 seq_put_decimal_ull(m, ' ', eip);
61746 /* The signal information here is obsolete.
61747@@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61748 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
61749 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
61750
61751- if (mm && permitted) {
61752+ if (mm && permitted
61753+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61754+ && !PAX_RAND_FLAGS(mm)
61755+#endif
61756+ ) {
61757 seq_put_decimal_ull(m, ' ', mm->start_data);
61758 seq_put_decimal_ull(m, ' ', mm->end_data);
61759 seq_put_decimal_ull(m, ' ', mm->start_brk);
61760@@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61761 struct pid *pid, struct task_struct *task)
61762 {
61763 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
61764- struct mm_struct *mm = get_task_mm(task);
61765+ struct mm_struct *mm;
61766
61767+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61768+ if (current->exec_id != m->exec_id) {
61769+ gr_log_badprocpid("statm");
61770+ return 0;
61771+ }
61772+#endif
61773+ mm = get_task_mm(task);
61774 if (mm) {
61775 size = task_statm(mm, &shared, &text, &data, &resident);
61776 mmput(mm);
61777@@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61778 return 0;
61779 }
61780
61781+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
61782+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
61783+{
61784+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
61785+}
61786+#endif
61787+
61788 #ifdef CONFIG_CHECKPOINT_RESTORE
61789 static struct pid *
61790 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
61791diff --git a/fs/proc/base.c b/fs/proc/base.c
61792index 03c8d74..4efb575 100644
61793--- a/fs/proc/base.c
61794+++ b/fs/proc/base.c
61795@@ -113,6 +113,14 @@ struct pid_entry {
61796 union proc_op op;
61797 };
61798
61799+struct getdents_callback {
61800+ struct linux_dirent __user * current_dir;
61801+ struct linux_dirent __user * previous;
61802+ struct file * file;
61803+ int count;
61804+ int error;
61805+};
61806+
61807 #define NOD(NAME, MODE, IOP, FOP, OP) { \
61808 .name = (NAME), \
61809 .len = sizeof(NAME) - 1, \
61810@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
61811 if (!mm->arg_end)
61812 goto out_mm; /* Shh! No looking before we're done */
61813
61814+ if (gr_acl_handle_procpidmem(task))
61815+ goto out_mm;
61816+
61817 len = mm->arg_end - mm->arg_start;
61818
61819 if (len > PAGE_SIZE)
61820@@ -237,12 +248,28 @@ out:
61821 return res;
61822 }
61823
61824+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61825+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61826+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61827+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61828+#endif
61829+
61830 static int proc_pid_auxv(struct task_struct *task, char *buffer)
61831 {
61832 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
61833 int res = PTR_ERR(mm);
61834 if (mm && !IS_ERR(mm)) {
61835 unsigned int nwords = 0;
61836+
61837+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61838+ /* allow if we're currently ptracing this task */
61839+ if (PAX_RAND_FLAGS(mm) &&
61840+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
61841+ mmput(mm);
61842+ return 0;
61843+ }
61844+#endif
61845+
61846 do {
61847 nwords += 2;
61848 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
61849@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
61850 }
61851
61852
61853-#ifdef CONFIG_KALLSYMS
61854+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61855 /*
61856 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
61857 * Returns the resolved symbol. If that fails, simply return the address.
61858@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
61859 mutex_unlock(&task->signal->cred_guard_mutex);
61860 }
61861
61862-#ifdef CONFIG_STACKTRACE
61863+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61864
61865 #define MAX_STACK_TRACE_DEPTH 64
61866
61867@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
61868 return count;
61869 }
61870
61871-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
61872+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
61873 static int proc_pid_syscall(struct task_struct *task, char *buffer)
61874 {
61875 long nr;
61876@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
61877 /************************************************************************/
61878
61879 /* permission checks */
61880-static int proc_fd_access_allowed(struct inode *inode)
61881+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
61882 {
61883 struct task_struct *task;
61884 int allowed = 0;
61885@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
61886 */
61887 task = get_proc_task(inode);
61888 if (task) {
61889- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
61890+ if (log)
61891+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
61892+ else
61893+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61894 put_task_struct(task);
61895 }
61896 return allowed;
61897@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
61898 struct task_struct *task,
61899 int hide_pid_min)
61900 {
61901+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
61902+ return false;
61903+
61904+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61905+ rcu_read_lock();
61906+ {
61907+ const struct cred *tmpcred = current_cred();
61908+ const struct cred *cred = __task_cred(task);
61909+
61910+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
61911+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
61912+ || in_group_p(grsec_proc_gid)
61913+#endif
61914+ ) {
61915+ rcu_read_unlock();
61916+ return true;
61917+ }
61918+ }
61919+ rcu_read_unlock();
61920+
61921+ if (!pid->hide_pid)
61922+ return false;
61923+#endif
61924+
61925 if (pid->hide_pid < hide_pid_min)
61926 return true;
61927 if (in_group_p(pid->pid_gid))
61928 return true;
61929+
61930 return ptrace_may_access(task, PTRACE_MODE_READ);
61931 }
61932
61933@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
61934 put_task_struct(task);
61935
61936 if (!has_perms) {
61937+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61938+ {
61939+#else
61940 if (pid->hide_pid == 2) {
61941+#endif
61942 /*
61943 * Let's make getdents(), stat(), and open()
61944 * consistent with each other. If a process
61945@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
61946 if (!task)
61947 return -ESRCH;
61948
61949+ if (gr_acl_handle_procpidmem(task)) {
61950+ put_task_struct(task);
61951+ return -EPERM;
61952+ }
61953+
61954 mm = mm_access(task, mode);
61955 put_task_struct(task);
61956
61957@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
61958
61959 file->private_data = mm;
61960
61961+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61962+ file->f_version = current->exec_id;
61963+#endif
61964+
61965 return 0;
61966 }
61967
61968@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
61969 ssize_t copied;
61970 char *page;
61971
61972+#ifdef CONFIG_GRKERNSEC
61973+ if (write)
61974+ return -EPERM;
61975+#endif
61976+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61977+ if (file->f_version != current->exec_id) {
61978+ gr_log_badprocpid("mem");
61979+ return 0;
61980+ }
61981+#endif
61982+
61983 if (!mm)
61984 return 0;
61985
61986@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
61987 goto free;
61988
61989 while (count > 0) {
61990- int this_len = min_t(int, count, PAGE_SIZE);
61991+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
61992
61993 if (write && copy_from_user(page, buf, this_len)) {
61994 copied = -EFAULT;
61995@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
61996 if (!mm)
61997 return 0;
61998
61999+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62000+ if (file->f_version != current->exec_id) {
62001+ gr_log_badprocpid("environ");
62002+ return 0;
62003+ }
62004+#endif
62005+
62006 page = (char *)__get_free_page(GFP_TEMPORARY);
62007 if (!page)
62008 return -ENOMEM;
62009@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62010 goto free;
62011 while (count > 0) {
62012 size_t this_len, max_len;
62013- int retval;
62014+ ssize_t retval;
62015
62016 if (src >= (mm->env_end - mm->env_start))
62017 break;
62018@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
62019 int error = -EACCES;
62020
62021 /* Are we allowed to snoop on the tasks file descriptors? */
62022- if (!proc_fd_access_allowed(inode))
62023+ if (!proc_fd_access_allowed(inode, 0))
62024 goto out;
62025
62026 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62027@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
62028 struct path path;
62029
62030 /* Are we allowed to snoop on the tasks file descriptors? */
62031- if (!proc_fd_access_allowed(inode))
62032- goto out;
62033+ /* logging this is needed for learning on chromium to work properly,
62034+ but we don't want to flood the logs from 'ps' which does a readlink
62035+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
62036+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
62037+ */
62038+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
62039+ if (!proc_fd_access_allowed(inode,0))
62040+ goto out;
62041+ } else {
62042+ if (!proc_fd_access_allowed(inode,1))
62043+ goto out;
62044+ }
62045
62046 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62047 if (error)
62048@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
62049 rcu_read_lock();
62050 cred = __task_cred(task);
62051 inode->i_uid = cred->euid;
62052+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62053+ inode->i_gid = grsec_proc_gid;
62054+#else
62055 inode->i_gid = cred->egid;
62056+#endif
62057 rcu_read_unlock();
62058 }
62059 security_task_to_inode(task, inode);
62060@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
62061 return -ENOENT;
62062 }
62063 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62064+#ifdef CONFIG_GRKERNSEC_PROC_USER
62065+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62066+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62067+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62068+#endif
62069 task_dumpable(task)) {
62070 cred = __task_cred(task);
62071 stat->uid = cred->euid;
62072+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62073+ stat->gid = grsec_proc_gid;
62074+#else
62075 stat->gid = cred->egid;
62076+#endif
62077 }
62078 }
62079 rcu_read_unlock();
62080@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
62081
62082 if (task) {
62083 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62084+#ifdef CONFIG_GRKERNSEC_PROC_USER
62085+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62086+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62087+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62088+#endif
62089 task_dumpable(task)) {
62090 rcu_read_lock();
62091 cred = __task_cred(task);
62092 inode->i_uid = cred->euid;
62093+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62094+ inode->i_gid = grsec_proc_gid;
62095+#else
62096 inode->i_gid = cred->egid;
62097+#endif
62098 rcu_read_unlock();
62099 } else {
62100 inode->i_uid = GLOBAL_ROOT_UID;
62101@@ -2172,6 +2290,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
62102 if (!task)
62103 goto out_no_task;
62104
62105+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62106+ goto out;
62107+
62108 /*
62109 * Yes, it does not scale. And it should not. Don't add
62110 * new entries into /proc/<tgid>/ without very good reasons.
62111@@ -2202,6 +2323,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
62112 if (!task)
62113 return -ENOENT;
62114
62115+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62116+ goto out;
62117+
62118 if (!dir_emit_dots(file, ctx))
62119 goto out;
62120
62121@@ -2591,7 +2715,7 @@ static const struct pid_entry tgid_base_stuff[] = {
62122 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
62123 #endif
62124 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62125-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62126+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62127 INF("syscall", S_IRUGO, proc_pid_syscall),
62128 #endif
62129 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62130@@ -2616,10 +2740,10 @@ static const struct pid_entry tgid_base_stuff[] = {
62131 #ifdef CONFIG_SECURITY
62132 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62133 #endif
62134-#ifdef CONFIG_KALLSYMS
62135+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62136 INF("wchan", S_IRUGO, proc_pid_wchan),
62137 #endif
62138-#ifdef CONFIG_STACKTRACE
62139+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62140 ONE("stack", S_IRUGO, proc_pid_stack),
62141 #endif
62142 #ifdef CONFIG_SCHEDSTATS
62143@@ -2653,6 +2777,9 @@ static const struct pid_entry tgid_base_stuff[] = {
62144 #ifdef CONFIG_HARDWALL
62145 INF("hardwall", S_IRUGO, proc_pid_hardwall),
62146 #endif
62147+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62148+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
62149+#endif
62150 #ifdef CONFIG_USER_NS
62151 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
62152 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
62153@@ -2783,7 +2910,14 @@ static int proc_pid_instantiate(struct inode *dir,
62154 if (!inode)
62155 goto out;
62156
62157+#ifdef CONFIG_GRKERNSEC_PROC_USER
62158+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
62159+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62160+ inode->i_gid = grsec_proc_gid;
62161+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
62162+#else
62163 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
62164+#endif
62165 inode->i_op = &proc_tgid_base_inode_operations;
62166 inode->i_fop = &proc_tgid_base_operations;
62167 inode->i_flags|=S_IMMUTABLE;
62168@@ -2821,7 +2955,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
62169 if (!task)
62170 goto out;
62171
62172+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62173+ goto out_put_task;
62174+
62175 result = proc_pid_instantiate(dir, dentry, task, NULL);
62176+out_put_task:
62177 put_task_struct(task);
62178 out:
62179 return ERR_PTR(result);
62180@@ -2927,7 +3065,7 @@ static const struct pid_entry tid_base_stuff[] = {
62181 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
62182 #endif
62183 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62184-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62185+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62186 INF("syscall", S_IRUGO, proc_pid_syscall),
62187 #endif
62188 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62189@@ -2954,10 +3092,10 @@ static const struct pid_entry tid_base_stuff[] = {
62190 #ifdef CONFIG_SECURITY
62191 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62192 #endif
62193-#ifdef CONFIG_KALLSYMS
62194+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62195 INF("wchan", S_IRUGO, proc_pid_wchan),
62196 #endif
62197-#ifdef CONFIG_STACKTRACE
62198+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62199 ONE("stack", S_IRUGO, proc_pid_stack),
62200 #endif
62201 #ifdef CONFIG_SCHEDSTATS
62202diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
62203index 82676e3..5f8518a 100644
62204--- a/fs/proc/cmdline.c
62205+++ b/fs/proc/cmdline.c
62206@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
62207
62208 static int __init proc_cmdline_init(void)
62209 {
62210+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62211+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
62212+#else
62213 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
62214+#endif
62215 return 0;
62216 }
62217 module_init(proc_cmdline_init);
62218diff --git a/fs/proc/devices.c b/fs/proc/devices.c
62219index b143471..bb105e5 100644
62220--- a/fs/proc/devices.c
62221+++ b/fs/proc/devices.c
62222@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
62223
62224 static int __init proc_devices_init(void)
62225 {
62226+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62227+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
62228+#else
62229 proc_create("devices", 0, NULL, &proc_devinfo_operations);
62230+#endif
62231 return 0;
62232 }
62233 module_init(proc_devices_init);
62234diff --git a/fs/proc/fd.c b/fs/proc/fd.c
62235index 985ea88..d118a0a 100644
62236--- a/fs/proc/fd.c
62237+++ b/fs/proc/fd.c
62238@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
62239 if (!task)
62240 return -ENOENT;
62241
62242- files = get_files_struct(task);
62243+ if (!gr_acl_handle_procpidmem(task))
62244+ files = get_files_struct(task);
62245 put_task_struct(task);
62246
62247 if (files) {
62248@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
62249 */
62250 int proc_fd_permission(struct inode *inode, int mask)
62251 {
62252+ struct task_struct *task;
62253 int rv = generic_permission(inode, mask);
62254- if (rv == 0)
62255- return 0;
62256+
62257 if (task_tgid(current) == proc_pid(inode))
62258 rv = 0;
62259+
62260+ task = get_proc_task(inode);
62261+ if (task == NULL)
62262+ return rv;
62263+
62264+ if (gr_acl_handle_procpidmem(task))
62265+ rv = -EACCES;
62266+
62267+ put_task_struct(task);
62268+
62269 return rv;
62270 }
62271
62272diff --git a/fs/proc/inode.c b/fs/proc/inode.c
62273index 124fc43..8afbb02 100644
62274--- a/fs/proc/inode.c
62275+++ b/fs/proc/inode.c
62276@@ -23,11 +23,17 @@
62277 #include <linux/slab.h>
62278 #include <linux/mount.h>
62279 #include <linux/magic.h>
62280+#include <linux/grsecurity.h>
62281
62282 #include <asm/uaccess.h>
62283
62284 #include "internal.h"
62285
62286+#ifdef CONFIG_PROC_SYSCTL
62287+extern const struct inode_operations proc_sys_inode_operations;
62288+extern const struct inode_operations proc_sys_dir_operations;
62289+#endif
62290+
62291 static void proc_evict_inode(struct inode *inode)
62292 {
62293 struct proc_dir_entry *de;
62294@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
62295 ns = PROC_I(inode)->ns.ns;
62296 if (ns_ops && ns)
62297 ns_ops->put(ns);
62298+
62299+#ifdef CONFIG_PROC_SYSCTL
62300+ if (inode->i_op == &proc_sys_inode_operations ||
62301+ inode->i_op == &proc_sys_dir_operations)
62302+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
62303+#endif
62304+
62305 }
62306
62307 static struct kmem_cache * proc_inode_cachep;
62308@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
62309 if (de->mode) {
62310 inode->i_mode = de->mode;
62311 inode->i_uid = de->uid;
62312+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62313+ inode->i_gid = grsec_proc_gid;
62314+#else
62315 inode->i_gid = de->gid;
62316+#endif
62317 }
62318 if (de->size)
62319 inode->i_size = de->size;
62320diff --git a/fs/proc/internal.h b/fs/proc/internal.h
62321index 651d09a..3d7f0bf 100644
62322--- a/fs/proc/internal.h
62323+++ b/fs/proc/internal.h
62324@@ -48,7 +48,7 @@ struct proc_dir_entry {
62325 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
62326 u8 namelen;
62327 char name[];
62328-};
62329+} __randomize_layout;
62330
62331 union proc_op {
62332 int (*proc_get_link)(struct dentry *, struct path *);
62333@@ -67,7 +67,7 @@ struct proc_inode {
62334 struct ctl_table *sysctl_entry;
62335 struct proc_ns ns;
62336 struct inode vfs_inode;
62337-};
62338+} __randomize_layout;
62339
62340 /*
62341 * General functions
62342@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
62343 struct pid *, struct task_struct *);
62344 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
62345 struct pid *, struct task_struct *);
62346+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62347+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
62348+#endif
62349
62350 /*
62351 * base.c
62352diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
62353index 05029c0..7ea1987 100644
62354--- a/fs/proc/interrupts.c
62355+++ b/fs/proc/interrupts.c
62356@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
62357
62358 static int __init proc_interrupts_init(void)
62359 {
62360+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62361+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
62362+#else
62363 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
62364+#endif
62365 return 0;
62366 }
62367 module_init(proc_interrupts_init);
62368diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
62369index 5ed0e52..a1c1f2e 100644
62370--- a/fs/proc/kcore.c
62371+++ b/fs/proc/kcore.c
62372@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62373 * the addresses in the elf_phdr on our list.
62374 */
62375 start = kc_offset_to_vaddr(*fpos - elf_buflen);
62376- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
62377+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
62378+ if (tsz > buflen)
62379 tsz = buflen;
62380-
62381+
62382 while (buflen) {
62383 struct kcore_list *m;
62384
62385@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62386 kfree(elf_buf);
62387 } else {
62388 if (kern_addr_valid(start)) {
62389- unsigned long n;
62390+ char *elf_buf;
62391+ mm_segment_t oldfs;
62392
62393- n = copy_to_user(buffer, (char *)start, tsz);
62394- /*
62395- * We cannot distinguish between fault on source
62396- * and fault on destination. When this happens
62397- * we clear too and hope it will trigger the
62398- * EFAULT again.
62399- */
62400- if (n) {
62401- if (clear_user(buffer + tsz - n,
62402- n))
62403+ elf_buf = kmalloc(tsz, GFP_KERNEL);
62404+ if (!elf_buf)
62405+ return -ENOMEM;
62406+ oldfs = get_fs();
62407+ set_fs(KERNEL_DS);
62408+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
62409+ set_fs(oldfs);
62410+ if (copy_to_user(buffer, elf_buf, tsz)) {
62411+ kfree(elf_buf);
62412 return -EFAULT;
62413+ }
62414 }
62415+ set_fs(oldfs);
62416+ kfree(elf_buf);
62417 } else {
62418 if (clear_user(buffer, tsz))
62419 return -EFAULT;
62420@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62421
62422 static int open_kcore(struct inode *inode, struct file *filp)
62423 {
62424+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62425+ return -EPERM;
62426+#endif
62427 if (!capable(CAP_SYS_RAWIO))
62428 return -EPERM;
62429 if (kcore_need_update)
62430diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
62431index a77d2b2..a9153f0 100644
62432--- a/fs/proc/meminfo.c
62433+++ b/fs/proc/meminfo.c
62434@@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
62435 vmi.used >> 10,
62436 vmi.largest_chunk >> 10
62437 #ifdef CONFIG_MEMORY_FAILURE
62438- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62439+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62440 #endif
62441 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
62442 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
62443diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
62444index 5f9bc8a..5c35f08 100644
62445--- a/fs/proc/nommu.c
62446+++ b/fs/proc/nommu.c
62447@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
62448
62449 if (file) {
62450 seq_pad(m, ' ');
62451- seq_path(m, &file->f_path, "");
62452+ seq_path(m, &file->f_path, "\n\\");
62453 }
62454
62455 seq_putc(m, '\n');
62456diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
62457index 4677bb7..408e936 100644
62458--- a/fs/proc/proc_net.c
62459+++ b/fs/proc/proc_net.c
62460@@ -23,6 +23,7 @@
62461 #include <linux/nsproxy.h>
62462 #include <net/net_namespace.h>
62463 #include <linux/seq_file.h>
62464+#include <linux/grsecurity.h>
62465
62466 #include "internal.h"
62467
62468@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
62469 struct task_struct *task;
62470 struct nsproxy *ns;
62471 struct net *net = NULL;
62472+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62473+ const struct cred *cred = current_cred();
62474+#endif
62475+
62476+#ifdef CONFIG_GRKERNSEC_PROC_USER
62477+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
62478+ return net;
62479+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62480+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
62481+ return net;
62482+#endif
62483
62484 rcu_read_lock();
62485 task = pid_task(proc_pid(dir), PIDTYPE_PID);
62486diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
62487index 7129046..6914844 100644
62488--- a/fs/proc/proc_sysctl.c
62489+++ b/fs/proc/proc_sysctl.c
62490@@ -11,13 +11,21 @@
62491 #include <linux/namei.h>
62492 #include <linux/mm.h>
62493 #include <linux/module.h>
62494+#include <linux/nsproxy.h>
62495+#ifdef CONFIG_GRKERNSEC
62496+#include <net/net_namespace.h>
62497+#endif
62498 #include "internal.h"
62499
62500+extern int gr_handle_chroot_sysctl(const int op);
62501+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
62502+ const int op);
62503+
62504 static const struct dentry_operations proc_sys_dentry_operations;
62505 static const struct file_operations proc_sys_file_operations;
62506-static const struct inode_operations proc_sys_inode_operations;
62507+const struct inode_operations proc_sys_inode_operations;
62508 static const struct file_operations proc_sys_dir_file_operations;
62509-static const struct inode_operations proc_sys_dir_operations;
62510+const struct inode_operations proc_sys_dir_operations;
62511
62512 void proc_sys_poll_notify(struct ctl_table_poll *poll)
62513 {
62514@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
62515
62516 err = NULL;
62517 d_set_d_op(dentry, &proc_sys_dentry_operations);
62518+
62519+ gr_handle_proc_create(dentry, inode);
62520+
62521 d_add(dentry, inode);
62522
62523 out:
62524@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62525 struct inode *inode = file_inode(filp);
62526 struct ctl_table_header *head = grab_header(inode);
62527 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
62528+ int op = write ? MAY_WRITE : MAY_READ;
62529 ssize_t error;
62530 size_t res;
62531
62532@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62533 * and won't be until we finish.
62534 */
62535 error = -EPERM;
62536- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
62537+ if (sysctl_perm(head, table, op))
62538 goto out;
62539
62540 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
62541@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62542 if (!table->proc_handler)
62543 goto out;
62544
62545+#ifdef CONFIG_GRKERNSEC
62546+ error = -EPERM;
62547+ if (gr_handle_chroot_sysctl(op))
62548+ goto out;
62549+ dget(filp->f_path.dentry);
62550+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
62551+ dput(filp->f_path.dentry);
62552+ goto out;
62553+ }
62554+ dput(filp->f_path.dentry);
62555+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
62556+ goto out;
62557+ if (write) {
62558+ if (current->nsproxy->net_ns != table->extra2) {
62559+ if (!capable(CAP_SYS_ADMIN))
62560+ goto out;
62561+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
62562+ goto out;
62563+ }
62564+#endif
62565+
62566 /* careful: calling conventions are nasty here */
62567 res = count;
62568 error = table->proc_handler(table, write, buf, &res, ppos);
62569@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
62570 return false;
62571 } else {
62572 d_set_d_op(child, &proc_sys_dentry_operations);
62573+
62574+ gr_handle_proc_create(child, inode);
62575+
62576 d_add(child, inode);
62577 }
62578 } else {
62579@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
62580 if ((*pos)++ < ctx->pos)
62581 return true;
62582
62583+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
62584+ return 0;
62585+
62586 if (unlikely(S_ISLNK(table->mode)))
62587 res = proc_sys_link_fill_cache(file, ctx, head, table);
62588 else
62589@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
62590 if (IS_ERR(head))
62591 return PTR_ERR(head);
62592
62593+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
62594+ return -ENOENT;
62595+
62596 generic_fillattr(inode, stat);
62597 if (table)
62598 stat->mode = (stat->mode & S_IFMT) | table->mode;
62599@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
62600 .llseek = generic_file_llseek,
62601 };
62602
62603-static const struct inode_operations proc_sys_inode_operations = {
62604+const struct inode_operations proc_sys_inode_operations = {
62605 .permission = proc_sys_permission,
62606 .setattr = proc_sys_setattr,
62607 .getattr = proc_sys_getattr,
62608 };
62609
62610-static const struct inode_operations proc_sys_dir_operations = {
62611+const struct inode_operations proc_sys_dir_operations = {
62612 .lookup = proc_sys_lookup,
62613 .permission = proc_sys_permission,
62614 .setattr = proc_sys_setattr,
62615@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
62616 static struct ctl_dir *new_dir(struct ctl_table_set *set,
62617 const char *name, int namelen)
62618 {
62619- struct ctl_table *table;
62620+ ctl_table_no_const *table;
62621 struct ctl_dir *new;
62622 struct ctl_node *node;
62623 char *new_name;
62624@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
62625 return NULL;
62626
62627 node = (struct ctl_node *)(new + 1);
62628- table = (struct ctl_table *)(node + 1);
62629+ table = (ctl_table_no_const *)(node + 1);
62630 new_name = (char *)(table + 2);
62631 memcpy(new_name, name, namelen);
62632 new_name[namelen] = '\0';
62633@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
62634 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
62635 struct ctl_table_root *link_root)
62636 {
62637- struct ctl_table *link_table, *entry, *link;
62638+ ctl_table_no_const *link_table, *link;
62639+ struct ctl_table *entry;
62640 struct ctl_table_header *links;
62641 struct ctl_node *node;
62642 char *link_name;
62643@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
62644 return NULL;
62645
62646 node = (struct ctl_node *)(links + 1);
62647- link_table = (struct ctl_table *)(node + nr_entries);
62648+ link_table = (ctl_table_no_const *)(node + nr_entries);
62649 link_name = (char *)&link_table[nr_entries + 1];
62650
62651 for (link = link_table, entry = table; entry->procname; link++, entry++) {
62652@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62653 struct ctl_table_header ***subheader, struct ctl_table_set *set,
62654 struct ctl_table *table)
62655 {
62656- struct ctl_table *ctl_table_arg = NULL;
62657- struct ctl_table *entry, *files;
62658+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
62659+ struct ctl_table *entry;
62660 int nr_files = 0;
62661 int nr_dirs = 0;
62662 int err = -ENOMEM;
62663@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62664 nr_files++;
62665 }
62666
62667- files = table;
62668 /* If there are mixed files and directories we need a new table */
62669 if (nr_dirs && nr_files) {
62670- struct ctl_table *new;
62671+ ctl_table_no_const *new;
62672 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
62673 GFP_KERNEL);
62674 if (!files)
62675@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62676 /* Register everything except a directory full of subdirectories */
62677 if (nr_files || !nr_dirs) {
62678 struct ctl_table_header *header;
62679- header = __register_sysctl_table(set, path, files);
62680+ header = __register_sysctl_table(set, path, files ? files : table);
62681 if (!header) {
62682 kfree(ctl_table_arg);
62683 goto out;
62684diff --git a/fs/proc/root.c b/fs/proc/root.c
62685index 87dbcbe..55e1b4d 100644
62686--- a/fs/proc/root.c
62687+++ b/fs/proc/root.c
62688@@ -186,7 +186,15 @@ void __init proc_root_init(void)
62689 #ifdef CONFIG_PROC_DEVICETREE
62690 proc_device_tree_init();
62691 #endif
62692+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62693+#ifdef CONFIG_GRKERNSEC_PROC_USER
62694+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
62695+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62696+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
62697+#endif
62698+#else
62699 proc_mkdir("bus", NULL);
62700+#endif
62701 proc_sys_init();
62702 }
62703
62704diff --git a/fs/proc/stat.c b/fs/proc/stat.c
62705index 1cf86c0..0ee1ca5 100644
62706--- a/fs/proc/stat.c
62707+++ b/fs/proc/stat.c
62708@@ -11,6 +11,7 @@
62709 #include <linux/irqnr.h>
62710 #include <asm/cputime.h>
62711 #include <linux/tick.h>
62712+#include <linux/grsecurity.h>
62713
62714 #ifndef arch_irq_stat_cpu
62715 #define arch_irq_stat_cpu(cpu) 0
62716@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
62717 u64 sum_softirq = 0;
62718 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
62719 struct timespec boottime;
62720+ int unrestricted = 1;
62721+
62722+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62723+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62724+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
62725+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62726+ && !in_group_p(grsec_proc_gid)
62727+#endif
62728+ )
62729+ unrestricted = 0;
62730+#endif
62731+#endif
62732
62733 user = nice = system = idle = iowait =
62734 irq = softirq = steal = 0;
62735@@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
62736 getboottime(&boottime);
62737 jif = boottime.tv_sec;
62738
62739+ if (unrestricted) {
62740 for_each_possible_cpu(i) {
62741 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
62742 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62743@@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
62744 }
62745 }
62746 sum += arch_irq_stat();
62747+ }
62748
62749 seq_puts(p, "cpu ");
62750 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62751@@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
62752 seq_putc(p, '\n');
62753
62754 for_each_online_cpu(i) {
62755+ if (unrestricted) {
62756 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
62757 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
62758 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62759@@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
62760 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
62761 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
62762 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
62763+ }
62764 seq_printf(p, "cpu%d", i);
62765 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62766 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
62767@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
62768
62769 /* sum again ? it could be updated? */
62770 for_each_irq_nr(j)
62771- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
62772+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
62773
62774 seq_printf(p,
62775 "\nctxt %llu\n"
62776@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
62777 "processes %lu\n"
62778 "procs_running %lu\n"
62779 "procs_blocked %lu\n",
62780- nr_context_switches(),
62781+ unrestricted ? nr_context_switches() : 0ULL,
62782 (unsigned long)jif,
62783- total_forks,
62784- nr_running(),
62785- nr_iowait());
62786+ unrestricted ? total_forks : 0UL,
62787+ unrestricted ? nr_running() : 0UL,
62788+ unrestricted ? nr_iowait() : 0UL);
62789
62790 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
62791
62792diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
62793index fb52b54..5fc7c14 100644
62794--- a/fs/proc/task_mmu.c
62795+++ b/fs/proc/task_mmu.c
62796@@ -12,12 +12,19 @@
62797 #include <linux/swap.h>
62798 #include <linux/swapops.h>
62799 #include <linux/mmu_notifier.h>
62800+#include <linux/grsecurity.h>
62801
62802 #include <asm/elf.h>
62803 #include <asm/uaccess.h>
62804 #include <asm/tlbflush.h>
62805 #include "internal.h"
62806
62807+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62808+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62809+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62810+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62811+#endif
62812+
62813 void task_mem(struct seq_file *m, struct mm_struct *mm)
62814 {
62815 unsigned long data, text, lib, swap;
62816@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62817 "VmExe:\t%8lu kB\n"
62818 "VmLib:\t%8lu kB\n"
62819 "VmPTE:\t%8lu kB\n"
62820- "VmSwap:\t%8lu kB\n",
62821- hiwater_vm << (PAGE_SHIFT-10),
62822+ "VmSwap:\t%8lu kB\n"
62823+
62824+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62825+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
62826+#endif
62827+
62828+ ,hiwater_vm << (PAGE_SHIFT-10),
62829 total_vm << (PAGE_SHIFT-10),
62830 mm->locked_vm << (PAGE_SHIFT-10),
62831 mm->pinned_vm << (PAGE_SHIFT-10),
62832@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62833 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
62834 (PTRS_PER_PTE * sizeof(pte_t) *
62835 atomic_long_read(&mm->nr_ptes)) >> 10,
62836- swap << (PAGE_SHIFT-10));
62837+ swap << (PAGE_SHIFT-10)
62838+
62839+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62840+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62841+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
62842+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
62843+#else
62844+ , mm->context.user_cs_base
62845+ , mm->context.user_cs_limit
62846+#endif
62847+#endif
62848+
62849+ );
62850 }
62851
62852 unsigned long task_vsize(struct mm_struct *mm)
62853@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62854 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
62855 }
62856
62857- /* We don't show the stack guard page in /proc/maps */
62858+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62859+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
62860+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
62861+#else
62862 start = vma->vm_start;
62863- if (stack_guard_page_start(vma, start))
62864- start += PAGE_SIZE;
62865 end = vma->vm_end;
62866- if (stack_guard_page_end(vma, end))
62867- end -= PAGE_SIZE;
62868+#endif
62869
62870 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
62871 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
62872@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62873 flags & VM_WRITE ? 'w' : '-',
62874 flags & VM_EXEC ? 'x' : '-',
62875 flags & VM_MAYSHARE ? 's' : 'p',
62876+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62877+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
62878+#else
62879 pgoff,
62880+#endif
62881 MAJOR(dev), MINOR(dev), ino);
62882
62883 /*
62884@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62885 */
62886 if (file) {
62887 seq_pad(m, ' ');
62888- seq_path(m, &file->f_path, "\n");
62889+ seq_path(m, &file->f_path, "\n\\");
62890 goto done;
62891 }
62892
62893@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62894 * Thread stack in /proc/PID/task/TID/maps or
62895 * the main process stack.
62896 */
62897- if (!is_pid || (vma->vm_start <= mm->start_stack &&
62898- vma->vm_end >= mm->start_stack)) {
62899+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
62900+ (vma->vm_start <= mm->start_stack &&
62901+ vma->vm_end >= mm->start_stack)) {
62902 name = "[stack]";
62903 } else {
62904 /* Thread stack in /proc/PID/maps */
62905@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
62906 struct proc_maps_private *priv = m->private;
62907 struct task_struct *task = priv->task;
62908
62909+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62910+ if (current->exec_id != m->exec_id) {
62911+ gr_log_badprocpid("maps");
62912+ return 0;
62913+ }
62914+#endif
62915+
62916 show_map_vma(m, vma, is_pid);
62917
62918 if (m->count < m->size) /* vma is copied successfully */
62919@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
62920 .private = &mss,
62921 };
62922
62923+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62924+ if (current->exec_id != m->exec_id) {
62925+ gr_log_badprocpid("smaps");
62926+ return 0;
62927+ }
62928+#endif
62929 memset(&mss, 0, sizeof mss);
62930- mss.vma = vma;
62931- /* mmap_sem is held in m_start */
62932- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
62933- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
62934-
62935+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62936+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
62937+#endif
62938+ mss.vma = vma;
62939+ /* mmap_sem is held in m_start */
62940+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
62941+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
62942+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62943+ }
62944+#endif
62945 show_map_vma(m, vma, is_pid);
62946
62947 seq_printf(m,
62948@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
62949 "KernelPageSize: %8lu kB\n"
62950 "MMUPageSize: %8lu kB\n"
62951 "Locked: %8lu kB\n",
62952+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62953+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
62954+#else
62955 (vma->vm_end - vma->vm_start) >> 10,
62956+#endif
62957 mss.resident >> 10,
62958 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
62959 mss.shared_clean >> 10,
62960@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
62961 char buffer[64];
62962 int nid;
62963
62964+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62965+ if (current->exec_id != m->exec_id) {
62966+ gr_log_badprocpid("numa_maps");
62967+ return 0;
62968+ }
62969+#endif
62970+
62971 if (!mm)
62972 return 0;
62973
62974@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
62975 mpol_to_str(buffer, sizeof(buffer), pol);
62976 mpol_cond_put(pol);
62977
62978+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62979+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
62980+#else
62981 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
62982+#endif
62983
62984 if (file) {
62985 seq_printf(m, " file=");
62986- seq_path(m, &file->f_path, "\n\t= ");
62987+ seq_path(m, &file->f_path, "\n\t\\= ");
62988 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
62989 seq_printf(m, " heap");
62990 } else {
62991diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
62992index 678455d..ebd3245 100644
62993--- a/fs/proc/task_nommu.c
62994+++ b/fs/proc/task_nommu.c
62995@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62996 else
62997 bytes += kobjsize(mm);
62998
62999- if (current->fs && current->fs->users > 1)
63000+ if (current->fs && atomic_read(&current->fs->users) > 1)
63001 sbytes += kobjsize(current->fs);
63002 else
63003 bytes += kobjsize(current->fs);
63004@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
63005
63006 if (file) {
63007 seq_pad(m, ' ');
63008- seq_path(m, &file->f_path, "");
63009+ seq_path(m, &file->f_path, "\n\\");
63010 } else if (mm) {
63011 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
63012
63013diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
63014index 9100d69..51cd925 100644
63015--- a/fs/proc/vmcore.c
63016+++ b/fs/proc/vmcore.c
63017@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
63018 nr_bytes = count;
63019
63020 /* If pfn is not ram, return zeros for sparse dump files */
63021- if (pfn_is_ram(pfn) == 0)
63022- memset(buf, 0, nr_bytes);
63023- else {
63024+ if (pfn_is_ram(pfn) == 0) {
63025+ if (userbuf) {
63026+ if (clear_user((char __force_user *)buf, nr_bytes))
63027+ return -EFAULT;
63028+ } else
63029+ memset(buf, 0, nr_bytes);
63030+ } else {
63031 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
63032 offset, userbuf);
63033 if (tmp < 0)
63034@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
63035 static int copy_to(void *target, void *src, size_t size, int userbuf)
63036 {
63037 if (userbuf) {
63038- if (copy_to_user((char __user *) target, src, size))
63039+ if (copy_to_user((char __force_user *) target, src, size))
63040 return -EFAULT;
63041 } else {
63042 memcpy(target, src, size);
63043@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63044 if (*fpos < m->offset + m->size) {
63045 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
63046 start = m->paddr + *fpos - m->offset;
63047- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
63048+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
63049 if (tmp < 0)
63050 return tmp;
63051 buflen -= tsz;
63052@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63053 static ssize_t read_vmcore(struct file *file, char __user *buffer,
63054 size_t buflen, loff_t *fpos)
63055 {
63056- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
63057+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
63058 }
63059
63060 /*
63061diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
63062index b00fcc9..e0c6381 100644
63063--- a/fs/qnx6/qnx6.h
63064+++ b/fs/qnx6/qnx6.h
63065@@ -74,7 +74,7 @@ enum {
63066 BYTESEX_BE,
63067 };
63068
63069-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63070+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63071 {
63072 if (sbi->s_bytesex == BYTESEX_LE)
63073 return le64_to_cpu((__force __le64)n);
63074@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
63075 return (__force __fs64)cpu_to_be64(n);
63076 }
63077
63078-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63079+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63080 {
63081 if (sbi->s_bytesex == BYTESEX_LE)
63082 return le32_to_cpu((__force __le32)n);
63083diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
63084index 72d2917..c917c12 100644
63085--- a/fs/quota/netlink.c
63086+++ b/fs/quota/netlink.c
63087@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
63088 void quota_send_warning(struct kqid qid, dev_t dev,
63089 const char warntype)
63090 {
63091- static atomic_t seq;
63092+ static atomic_unchecked_t seq;
63093 struct sk_buff *skb;
63094 void *msg_head;
63095 int ret;
63096@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
63097 "VFS: Not enough memory to send quota warning.\n");
63098 return;
63099 }
63100- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
63101+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
63102 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
63103 if (!msg_head) {
63104 printk(KERN_ERR
63105diff --git a/fs/read_write.c b/fs/read_write.c
63106index 58e440d..8ec2838 100644
63107--- a/fs/read_write.c
63108+++ b/fs/read_write.c
63109@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
63110
63111 old_fs = get_fs();
63112 set_fs(get_ds());
63113- p = (__force const char __user *)buf;
63114+ p = (const char __force_user *)buf;
63115 if (count > MAX_RW_COUNT)
63116 count = MAX_RW_COUNT;
63117 if (file->f_op->write)
63118diff --git a/fs/readdir.c b/fs/readdir.c
63119index 5b53d99..a6c3049 100644
63120--- a/fs/readdir.c
63121+++ b/fs/readdir.c
63122@@ -17,6 +17,7 @@
63123 #include <linux/security.h>
63124 #include <linux/syscalls.h>
63125 #include <linux/unistd.h>
63126+#include <linux/namei.h>
63127
63128 #include <asm/uaccess.h>
63129
63130@@ -69,6 +70,7 @@ struct old_linux_dirent {
63131 struct readdir_callback {
63132 struct dir_context ctx;
63133 struct old_linux_dirent __user * dirent;
63134+ struct file * file;
63135 int result;
63136 };
63137
63138@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
63139 buf->result = -EOVERFLOW;
63140 return -EOVERFLOW;
63141 }
63142+
63143+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63144+ return 0;
63145+
63146 buf->result++;
63147 dirent = buf->dirent;
63148 if (!access_ok(VERIFY_WRITE, dirent,
63149@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
63150 if (!f.file)
63151 return -EBADF;
63152
63153+ buf.file = f.file;
63154 error = iterate_dir(f.file, &buf.ctx);
63155 if (buf.result)
63156 error = buf.result;
63157@@ -142,6 +149,7 @@ struct getdents_callback {
63158 struct dir_context ctx;
63159 struct linux_dirent __user * current_dir;
63160 struct linux_dirent __user * previous;
63161+ struct file * file;
63162 int count;
63163 int error;
63164 };
63165@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
63166 buf->error = -EOVERFLOW;
63167 return -EOVERFLOW;
63168 }
63169+
63170+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63171+ return 0;
63172+
63173 dirent = buf->previous;
63174 if (dirent) {
63175 if (__put_user(offset, &dirent->d_off))
63176@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
63177 if (!f.file)
63178 return -EBADF;
63179
63180+ buf.file = f.file;
63181 error = iterate_dir(f.file, &buf.ctx);
63182 if (error >= 0)
63183 error = buf.error;
63184@@ -226,6 +239,7 @@ struct getdents_callback64 {
63185 struct dir_context ctx;
63186 struct linux_dirent64 __user * current_dir;
63187 struct linux_dirent64 __user * previous;
63188+ struct file *file;
63189 int count;
63190 int error;
63191 };
63192@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
63193 buf->error = -EINVAL; /* only used if we fail.. */
63194 if (reclen > buf->count)
63195 return -EINVAL;
63196+
63197+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63198+ return 0;
63199+
63200 dirent = buf->previous;
63201 if (dirent) {
63202 if (__put_user(offset, &dirent->d_off))
63203@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
63204 if (!f.file)
63205 return -EBADF;
63206
63207+ buf.file = f.file;
63208 error = iterate_dir(f.file, &buf.ctx);
63209 if (error >= 0)
63210 error = buf.error;
63211diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
63212index 2b7882b..1c5ef48 100644
63213--- a/fs/reiserfs/do_balan.c
63214+++ b/fs/reiserfs/do_balan.c
63215@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
63216 return;
63217 }
63218
63219- atomic_inc(&(fs_generation(tb->tb_sb)));
63220+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
63221 do_balance_starts(tb);
63222
63223 /* balance leaf returns 0 except if combining L R and S into
63224diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
63225index ee382ef..f4eb6eb5 100644
63226--- a/fs/reiserfs/item_ops.c
63227+++ b/fs/reiserfs/item_ops.c
63228@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
63229 }
63230
63231 static struct item_operations errcatch_ops = {
63232- errcatch_bytes_number,
63233- errcatch_decrement_key,
63234- errcatch_is_left_mergeable,
63235- errcatch_print_item,
63236- errcatch_check_item,
63237+ .bytes_number = errcatch_bytes_number,
63238+ .decrement_key = errcatch_decrement_key,
63239+ .is_left_mergeable = errcatch_is_left_mergeable,
63240+ .print_item = errcatch_print_item,
63241+ .check_item = errcatch_check_item,
63242
63243- errcatch_create_vi,
63244- errcatch_check_left,
63245- errcatch_check_right,
63246- errcatch_part_size,
63247- errcatch_unit_num,
63248- errcatch_print_vi
63249+ .create_vi = errcatch_create_vi,
63250+ .check_left = errcatch_check_left,
63251+ .check_right = errcatch_check_right,
63252+ .part_size = errcatch_part_size,
63253+ .unit_num = errcatch_unit_num,
63254+ .print_vi = errcatch_print_vi
63255 };
63256
63257 //////////////////////////////////////////////////////////////////////////////
63258diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
63259index a958444..42b2323 100644
63260--- a/fs/reiserfs/procfs.c
63261+++ b/fs/reiserfs/procfs.c
63262@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
63263 "SMALL_TAILS " : "NO_TAILS ",
63264 replay_only(sb) ? "REPLAY_ONLY " : "",
63265 convert_reiserfs(sb) ? "CONV " : "",
63266- atomic_read(&r->s_generation_counter),
63267+ atomic_read_unchecked(&r->s_generation_counter),
63268 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
63269 SF(s_do_balance), SF(s_unneeded_left_neighbor),
63270 SF(s_good_search_by_key_reada), SF(s_bmaps),
63271diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
63272index f8adaee..0eeeeca 100644
63273--- a/fs/reiserfs/reiserfs.h
63274+++ b/fs/reiserfs/reiserfs.h
63275@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
63276 /* Comment? -Hans */
63277 wait_queue_head_t s_wait;
63278 /* To be obsoleted soon by per buffer seals.. -Hans */
63279- atomic_t s_generation_counter; // increased by one every time the
63280+ atomic_unchecked_t s_generation_counter; // increased by one every time the
63281 // tree gets re-balanced
63282 unsigned long s_properties; /* File system properties. Currently holds
63283 on-disk FS format */
63284@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63285 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63286
63287 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63288-#define get_generation(s) atomic_read (&fs_generation(s))
63289+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63290 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63291 #define __fs_changed(gen,s) (gen != get_generation (s))
63292 #define fs_changed(gen,s) \
63293diff --git a/fs/select.c b/fs/select.c
63294index 467bb1c..cf9d65a 100644
63295--- a/fs/select.c
63296+++ b/fs/select.c
63297@@ -20,6 +20,7 @@
63298 #include <linux/export.h>
63299 #include <linux/slab.h>
63300 #include <linux/poll.h>
63301+#include <linux/security.h>
63302 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
63303 #include <linux/file.h>
63304 #include <linux/fdtable.h>
63305@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
63306 struct poll_list *walk = head;
63307 unsigned long todo = nfds;
63308
63309+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
63310 if (nfds > rlimit(RLIMIT_NOFILE))
63311 return -EINVAL;
63312
63313diff --git a/fs/seq_file.c b/fs/seq_file.c
63314index 1d641bb..e600623 100644
63315--- a/fs/seq_file.c
63316+++ b/fs/seq_file.c
63317@@ -10,6 +10,7 @@
63318 #include <linux/seq_file.h>
63319 #include <linux/slab.h>
63320 #include <linux/cred.h>
63321+#include <linux/sched.h>
63322
63323 #include <asm/uaccess.h>
63324 #include <asm/page.h>
63325@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
63326 #ifdef CONFIG_USER_NS
63327 p->user_ns = file->f_cred->user_ns;
63328 #endif
63329+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63330+ p->exec_id = current->exec_id;
63331+#endif
63332
63333 /*
63334 * Wrappers around seq_open(e.g. swaps_open) need to be
63335@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
63336 return 0;
63337 }
63338 if (!m->buf) {
63339- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63340+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63341 if (!m->buf)
63342 return -ENOMEM;
63343 }
63344@@ -137,7 +141,7 @@ Eoverflow:
63345 m->op->stop(m, p);
63346 kfree(m->buf);
63347 m->count = 0;
63348- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63349+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63350 return !m->buf ? -ENOMEM : -EAGAIN;
63351 }
63352
63353@@ -153,7 +157,7 @@ Eoverflow:
63354 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63355 {
63356 struct seq_file *m = file->private_data;
63357- size_t copied = 0;
63358+ ssize_t copied = 0;
63359 loff_t pos;
63360 size_t n;
63361 void *p;
63362@@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63363
63364 /* grab buffer if we didn't have one */
63365 if (!m->buf) {
63366- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63367+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63368 if (!m->buf)
63369 goto Enomem;
63370 }
63371@@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63372 m->op->stop(m, p);
63373 kfree(m->buf);
63374 m->count = 0;
63375- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63376+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63377 if (!m->buf)
63378 goto Enomem;
63379 m->version = 0;
63380@@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
63381 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
63382 void *data)
63383 {
63384- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
63385+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
63386 int res = -ENOMEM;
63387
63388 if (op) {
63389diff --git a/fs/splice.c b/fs/splice.c
63390index 46a08f7..bb163cc 100644
63391--- a/fs/splice.c
63392+++ b/fs/splice.c
63393@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63394 pipe_lock(pipe);
63395
63396 for (;;) {
63397- if (!pipe->readers) {
63398+ if (!atomic_read(&pipe->readers)) {
63399 send_sig(SIGPIPE, current, 0);
63400 if (!ret)
63401 ret = -EPIPE;
63402@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63403 page_nr++;
63404 ret += buf->len;
63405
63406- if (pipe->files)
63407+ if (atomic_read(&pipe->files))
63408 do_wakeup = 1;
63409
63410 if (!--spd->nr_pages)
63411@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63412 do_wakeup = 0;
63413 }
63414
63415- pipe->waiting_writers++;
63416+ atomic_inc(&pipe->waiting_writers);
63417 pipe_wait(pipe);
63418- pipe->waiting_writers--;
63419+ atomic_dec(&pipe->waiting_writers);
63420 }
63421
63422 pipe_unlock(pipe);
63423@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
63424 old_fs = get_fs();
63425 set_fs(get_ds());
63426 /* The cast to a user pointer is valid due to the set_fs() */
63427- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
63428+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
63429 set_fs(old_fs);
63430
63431 return res;
63432@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
63433 old_fs = get_fs();
63434 set_fs(get_ds());
63435 /* The cast to a user pointer is valid due to the set_fs() */
63436- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
63437+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
63438 set_fs(old_fs);
63439
63440 return res;
63441@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
63442 goto err;
63443
63444 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
63445- vec[i].iov_base = (void __user *) page_address(page);
63446+ vec[i].iov_base = (void __force_user *) page_address(page);
63447 vec[i].iov_len = this_len;
63448 spd.pages[i] = page;
63449 spd.nr_pages++;
63450@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
63451 ops->release(pipe, buf);
63452 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
63453 pipe->nrbufs--;
63454- if (pipe->files)
63455+ if (atomic_read(&pipe->files))
63456 sd->need_wakeup = true;
63457 }
63458
63459@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
63460 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
63461 {
63462 while (!pipe->nrbufs) {
63463- if (!pipe->writers)
63464+ if (!atomic_read(&pipe->writers))
63465 return 0;
63466
63467- if (!pipe->waiting_writers && sd->num_spliced)
63468+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
63469 return 0;
63470
63471 if (sd->flags & SPLICE_F_NONBLOCK)
63472@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
63473 * out of the pipe right after the splice_to_pipe(). So set
63474 * PIPE_READERS appropriately.
63475 */
63476- pipe->readers = 1;
63477+ atomic_set(&pipe->readers, 1);
63478
63479 current->splice_pipe = pipe;
63480 }
63481@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
63482
63483 partial[buffers].offset = off;
63484 partial[buffers].len = plen;
63485+ partial[buffers].private = 0;
63486
63487 off = 0;
63488 len -= plen;
63489@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63490 ret = -ERESTARTSYS;
63491 break;
63492 }
63493- if (!pipe->writers)
63494+ if (!atomic_read(&pipe->writers))
63495 break;
63496- if (!pipe->waiting_writers) {
63497+ if (!atomic_read(&pipe->waiting_writers)) {
63498 if (flags & SPLICE_F_NONBLOCK) {
63499 ret = -EAGAIN;
63500 break;
63501@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63502 pipe_lock(pipe);
63503
63504 while (pipe->nrbufs >= pipe->buffers) {
63505- if (!pipe->readers) {
63506+ if (!atomic_read(&pipe->readers)) {
63507 send_sig(SIGPIPE, current, 0);
63508 ret = -EPIPE;
63509 break;
63510@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63511 ret = -ERESTARTSYS;
63512 break;
63513 }
63514- pipe->waiting_writers++;
63515+ atomic_inc(&pipe->waiting_writers);
63516 pipe_wait(pipe);
63517- pipe->waiting_writers--;
63518+ atomic_dec(&pipe->waiting_writers);
63519 }
63520
63521 pipe_unlock(pipe);
63522@@ -1862,14 +1863,14 @@ retry:
63523 pipe_double_lock(ipipe, opipe);
63524
63525 do {
63526- if (!opipe->readers) {
63527+ if (!atomic_read(&opipe->readers)) {
63528 send_sig(SIGPIPE, current, 0);
63529 if (!ret)
63530 ret = -EPIPE;
63531 break;
63532 }
63533
63534- if (!ipipe->nrbufs && !ipipe->writers)
63535+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
63536 break;
63537
63538 /*
63539@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63540 pipe_double_lock(ipipe, opipe);
63541
63542 do {
63543- if (!opipe->readers) {
63544+ if (!atomic_read(&opipe->readers)) {
63545 send_sig(SIGPIPE, current, 0);
63546 if (!ret)
63547 ret = -EPIPE;
63548@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63549 * return EAGAIN if we have the potential of some data in the
63550 * future, otherwise just return 0
63551 */
63552- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
63553+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
63554 ret = -EAGAIN;
63555
63556 pipe_unlock(ipipe);
63557diff --git a/fs/stat.c b/fs/stat.c
63558index ae0c3ce..9ee641c 100644
63559--- a/fs/stat.c
63560+++ b/fs/stat.c
63561@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
63562 stat->gid = inode->i_gid;
63563 stat->rdev = inode->i_rdev;
63564 stat->size = i_size_read(inode);
63565- stat->atime = inode->i_atime;
63566- stat->mtime = inode->i_mtime;
63567+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63568+ stat->atime = inode->i_ctime;
63569+ stat->mtime = inode->i_ctime;
63570+ } else {
63571+ stat->atime = inode->i_atime;
63572+ stat->mtime = inode->i_mtime;
63573+ }
63574 stat->ctime = inode->i_ctime;
63575 stat->blksize = (1 << inode->i_blkbits);
63576 stat->blocks = inode->i_blocks;
63577@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
63578 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
63579 {
63580 struct inode *inode = path->dentry->d_inode;
63581+ int retval;
63582
63583- if (inode->i_op->getattr)
63584- return inode->i_op->getattr(path->mnt, path->dentry, stat);
63585+ if (inode->i_op->getattr) {
63586+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
63587+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63588+ stat->atime = stat->ctime;
63589+ stat->mtime = stat->ctime;
63590+ }
63591+ return retval;
63592+ }
63593
63594 generic_fillattr(inode, stat);
63595 return 0;
63596diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
63597index 5e73d66..4f165fd 100644
63598--- a/fs/sysfs/dir.c
63599+++ b/fs/sysfs/dir.c
63600@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
63601 *
63602 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63603 */
63604-static unsigned int sysfs_name_hash(const char *name, const void *ns)
63605+static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
63606 {
63607 unsigned long hash = init_name_hash();
63608 unsigned int len = strlen(name);
63609@@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
63610 struct sysfs_dirent *sd;
63611 int rc;
63612
63613+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
63614+ const char *parent_name = parent_sd->s_name;
63615+
63616+ mode = S_IFDIR | S_IRWXU;
63617+
63618+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
63619+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
63620+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
63621+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
63622+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
63623+#endif
63624+
63625 /* allocate */
63626 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
63627 if (!sd)
63628diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
63629index 35e7d08..4d6e676 100644
63630--- a/fs/sysfs/file.c
63631+++ b/fs/sysfs/file.c
63632@@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
63633
63634 struct sysfs_open_dirent {
63635 atomic_t refcnt;
63636- atomic_t event;
63637+ atomic_unchecked_t event;
63638 wait_queue_head_t poll;
63639 struct list_head files; /* goes through sysfs_open_file.list */
63640 };
63641@@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
63642 return -ENODEV;
63643 }
63644
63645- of->event = atomic_read(&of->sd->s_attr.open->event);
63646+ of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
63647
63648 /*
63649 * Lookup @ops and invoke show(). Control may reach here via seq
63650@@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
63651 return ret;
63652 }
63653
63654-static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63655- void *buf, int len, int write)
63656+static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63657+ void *buf, size_t len, int write)
63658 {
63659 struct file *file = vma->vm_file;
63660 struct sysfs_open_file *of = sysfs_of(file);
63661- int ret;
63662+ ssize_t ret;
63663
63664 if (!of->vm_ops)
63665 return -EINVAL;
63666@@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
63667 return -ENOMEM;
63668
63669 atomic_set(&new_od->refcnt, 0);
63670- atomic_set(&new_od->event, 1);
63671+ atomic_set_unchecked(&new_od->event, 1);
63672 init_waitqueue_head(&new_od->poll);
63673 INIT_LIST_HEAD(&new_od->files);
63674 goto retry;
63675@@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
63676
63677 sysfs_put_active(attr_sd);
63678
63679- if (of->event != atomic_read(&od->event))
63680+ if (of->event != atomic_read_unchecked(&od->event))
63681 goto trigger;
63682
63683 return DEFAULT_POLLMASK;
63684@@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
63685 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
63686 od = sd->s_attr.open;
63687 if (od) {
63688- atomic_inc(&od->event);
63689+ atomic_inc_unchecked(&od->event);
63690 wake_up_interruptible(&od->poll);
63691 }
63692 }
63693diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
63694index 3ae3f1b..081a26c 100644
63695--- a/fs/sysfs/symlink.c
63696+++ b/fs/sysfs/symlink.c
63697@@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63698 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
63699 void *cookie)
63700 {
63701- char *page = nd_get_link(nd);
63702+ const char *page = nd_get_link(nd);
63703 if (!IS_ERR(page))
63704 free_page((unsigned long)page);
63705 }
63706diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
63707index 69d4889..a810bd4 100644
63708--- a/fs/sysv/sysv.h
63709+++ b/fs/sysv/sysv.h
63710@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
63711 #endif
63712 }
63713
63714-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63715+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63716 {
63717 if (sbi->s_bytesex == BYTESEX_PDP)
63718 return PDP_swab((__force __u32)n);
63719diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
63720index e18b988..f1d4ad0f 100644
63721--- a/fs/ubifs/io.c
63722+++ b/fs/ubifs/io.c
63723@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
63724 return err;
63725 }
63726
63727-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63728+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63729 {
63730 int err;
63731
63732diff --git a/fs/udf/misc.c b/fs/udf/misc.c
63733index c175b4d..8f36a16 100644
63734--- a/fs/udf/misc.c
63735+++ b/fs/udf/misc.c
63736@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
63737
63738 u8 udf_tag_checksum(const struct tag *t)
63739 {
63740- u8 *data = (u8 *)t;
63741+ const u8 *data = (const u8 *)t;
63742 u8 checksum = 0;
63743 int i;
63744 for (i = 0; i < sizeof(struct tag); ++i)
63745diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
63746index 8d974c4..b82f6ec 100644
63747--- a/fs/ufs/swab.h
63748+++ b/fs/ufs/swab.h
63749@@ -22,7 +22,7 @@ enum {
63750 BYTESEX_BE
63751 };
63752
63753-static inline u64
63754+static inline u64 __intentional_overflow(-1)
63755 fs64_to_cpu(struct super_block *sbp, __fs64 n)
63756 {
63757 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63758@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
63759 return (__force __fs64)cpu_to_be64(n);
63760 }
63761
63762-static inline u32
63763+static inline u32 __intentional_overflow(-1)
63764 fs32_to_cpu(struct super_block *sbp, __fs32 n)
63765 {
63766 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63767diff --git a/fs/utimes.c b/fs/utimes.c
63768index aa138d6..5f3a811 100644
63769--- a/fs/utimes.c
63770+++ b/fs/utimes.c
63771@@ -1,6 +1,7 @@
63772 #include <linux/compiler.h>
63773 #include <linux/file.h>
63774 #include <linux/fs.h>
63775+#include <linux/security.h>
63776 #include <linux/linkage.h>
63777 #include <linux/mount.h>
63778 #include <linux/namei.h>
63779@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
63780 }
63781 }
63782 retry_deleg:
63783+
63784+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
63785+ error = -EACCES;
63786+ goto mnt_drop_write_and_out;
63787+ }
63788+
63789 mutex_lock(&inode->i_mutex);
63790 error = notify_change(path->dentry, &newattrs, &delegated_inode);
63791 mutex_unlock(&inode->i_mutex);
63792diff --git a/fs/xattr.c b/fs/xattr.c
63793index 3377dff..f394815 100644
63794--- a/fs/xattr.c
63795+++ b/fs/xattr.c
63796@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
63797 return rc;
63798 }
63799
63800+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
63801+ssize_t
63802+pax_getxattr(struct dentry *dentry, void *value, size_t size)
63803+{
63804+ struct inode *inode = dentry->d_inode;
63805+ ssize_t error;
63806+
63807+ error = inode_permission(inode, MAY_EXEC);
63808+ if (error)
63809+ return error;
63810+
63811+ if (inode->i_op->getxattr)
63812+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
63813+ else
63814+ error = -EOPNOTSUPP;
63815+
63816+ return error;
63817+}
63818+EXPORT_SYMBOL(pax_getxattr);
63819+#endif
63820+
63821 ssize_t
63822 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
63823 {
63824@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
63825 * Extended attribute SET operations
63826 */
63827 static long
63828-setxattr(struct dentry *d, const char __user *name, const void __user *value,
63829+setxattr(struct path *path, const char __user *name, const void __user *value,
63830 size_t size, int flags)
63831 {
63832 int error;
63833@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
63834 posix_acl_fix_xattr_from_user(kvalue, size);
63835 }
63836
63837- error = vfs_setxattr(d, kname, kvalue, size, flags);
63838+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
63839+ error = -EACCES;
63840+ goto out;
63841+ }
63842+
63843+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
63844 out:
63845 if (vvalue)
63846 vfree(vvalue);
63847@@ -377,7 +403,7 @@ retry:
63848 return error;
63849 error = mnt_want_write(path.mnt);
63850 if (!error) {
63851- error = setxattr(path.dentry, name, value, size, flags);
63852+ error = setxattr(&path, name, value, size, flags);
63853 mnt_drop_write(path.mnt);
63854 }
63855 path_put(&path);
63856@@ -401,7 +427,7 @@ retry:
63857 return error;
63858 error = mnt_want_write(path.mnt);
63859 if (!error) {
63860- error = setxattr(path.dentry, name, value, size, flags);
63861+ error = setxattr(&path, name, value, size, flags);
63862 mnt_drop_write(path.mnt);
63863 }
63864 path_put(&path);
63865@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
63866 const void __user *,value, size_t, size, int, flags)
63867 {
63868 struct fd f = fdget(fd);
63869- struct dentry *dentry;
63870 int error = -EBADF;
63871
63872 if (!f.file)
63873 return error;
63874- dentry = f.file->f_path.dentry;
63875- audit_inode(NULL, dentry, 0);
63876+ audit_inode(NULL, f.file->f_path.dentry, 0);
63877 error = mnt_want_write_file(f.file);
63878 if (!error) {
63879- error = setxattr(dentry, name, value, size, flags);
63880+ error = setxattr(&f.file->f_path, name, value, size, flags);
63881 mnt_drop_write_file(f.file);
63882 }
63883 fdput(f);
63884@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
63885 * Extended attribute REMOVE operations
63886 */
63887 static long
63888-removexattr(struct dentry *d, const char __user *name)
63889+removexattr(struct path *path, const char __user *name)
63890 {
63891 int error;
63892 char kname[XATTR_NAME_MAX + 1];
63893@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
63894 if (error < 0)
63895 return error;
63896
63897- return vfs_removexattr(d, kname);
63898+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
63899+ return -EACCES;
63900+
63901+ return vfs_removexattr(path->dentry, kname);
63902 }
63903
63904 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
63905@@ -652,7 +679,7 @@ retry:
63906 return error;
63907 error = mnt_want_write(path.mnt);
63908 if (!error) {
63909- error = removexattr(path.dentry, name);
63910+ error = removexattr(&path, name);
63911 mnt_drop_write(path.mnt);
63912 }
63913 path_put(&path);
63914@@ -675,7 +702,7 @@ retry:
63915 return error;
63916 error = mnt_want_write(path.mnt);
63917 if (!error) {
63918- error = removexattr(path.dentry, name);
63919+ error = removexattr(&path, name);
63920 mnt_drop_write(path.mnt);
63921 }
63922 path_put(&path);
63923@@ -689,16 +716,16 @@ retry:
63924 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
63925 {
63926 struct fd f = fdget(fd);
63927- struct dentry *dentry;
63928+ struct path *path;
63929 int error = -EBADF;
63930
63931 if (!f.file)
63932 return error;
63933- dentry = f.file->f_path.dentry;
63934- audit_inode(NULL, dentry, 0);
63935+ path = &f.file->f_path;
63936+ audit_inode(NULL, path->dentry, 0);
63937 error = mnt_want_write_file(f.file);
63938 if (!error) {
63939- error = removexattr(dentry, name);
63940+ error = removexattr(path, name);
63941 mnt_drop_write_file(f.file);
63942 }
63943 fdput(f);
63944diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
63945index 9fbea87..6b19972 100644
63946--- a/fs/xattr_acl.c
63947+++ b/fs/xattr_acl.c
63948@@ -76,8 +76,8 @@ struct posix_acl *
63949 posix_acl_from_xattr(struct user_namespace *user_ns,
63950 const void *value, size_t size)
63951 {
63952- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63953- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63954+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63955+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63956 int count;
63957 struct posix_acl *acl;
63958 struct posix_acl_entry *acl_e;
63959diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
63960index 3b2c14b..de031fe 100644
63961--- a/fs/xfs/xfs_bmap.c
63962+++ b/fs/xfs/xfs_bmap.c
63963@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
63964
63965 #else
63966 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
63967-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
63968+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
63969 #endif /* DEBUG */
63970
63971 /*
63972diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
63973index c4e50c6..8ba93e3 100644
63974--- a/fs/xfs/xfs_dir2_readdir.c
63975+++ b/fs/xfs/xfs_dir2_readdir.c
63976@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
63977 ino = dp->d_ops->sf_get_ino(sfp, sfep);
63978 filetype = dp->d_ops->sf_get_ftype(sfep);
63979 ctx->pos = off & 0x7fffffff;
63980- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
63981+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
63982+ char name[sfep->namelen];
63983+ memcpy(name, sfep->name, sfep->namelen);
63984+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
63985+ return 0;
63986+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
63987 xfs_dir3_get_dtype(mp, filetype)))
63988 return 0;
63989 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
63990diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
63991index 33ad9a7..82c18ba 100644
63992--- a/fs/xfs/xfs_ioctl.c
63993+++ b/fs/xfs/xfs_ioctl.c
63994@@ -126,7 +126,7 @@ xfs_find_handle(
63995 }
63996
63997 error = -EFAULT;
63998- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
63999+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
64000 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
64001 goto out_put;
64002
64003diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
64004index 104455b..764c512 100644
64005--- a/fs/xfs/xfs_iops.c
64006+++ b/fs/xfs/xfs_iops.c
64007@@ -397,7 +397,7 @@ xfs_vn_put_link(
64008 struct nameidata *nd,
64009 void *p)
64010 {
64011- char *s = nd_get_link(nd);
64012+ const char *s = nd_get_link(nd);
64013
64014 if (!IS_ERR(s))
64015 kfree(s);
64016diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
64017new file mode 100644
64018index 0000000..c2c7f17
64019--- /dev/null
64020+++ b/grsecurity/Kconfig
64021@@ -0,0 +1,1146 @@
64022+#
64023+# grecurity configuration
64024+#
64025+menu "Memory Protections"
64026+depends on GRKERNSEC
64027+
64028+config GRKERNSEC_KMEM
64029+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
64030+ default y if GRKERNSEC_CONFIG_AUTO
64031+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
64032+ help
64033+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
64034+ be written to or read from to modify or leak the contents of the running
64035+ kernel. /dev/port will also not be allowed to be opened, and support
64036+ for /dev/cpu/*/msr and kexec will be removed. If you have module
64037+ support disabled, enabling this will close up six ways that are
64038+ currently used to insert malicious code into the running kernel.
64039+
64040+ Even with this feature enabled, we still highly recommend that
64041+ you use the RBAC system, as it is still possible for an attacker to
64042+ modify the running kernel through other more obscure methods.
64043+
64044+ Enabling this feature will prevent the "cpupower" and "powertop" tools
64045+ from working.
64046+
64047+ It is highly recommended that you say Y here if you meet all the
64048+ conditions above.
64049+
64050+config GRKERNSEC_VM86
64051+ bool "Restrict VM86 mode"
64052+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64053+ depends on X86_32
64054+
64055+ help
64056+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
64057+ make use of a special execution mode on 32bit x86 processors called
64058+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
64059+ video cards and will still work with this option enabled. The purpose
64060+ of the option is to prevent exploitation of emulation errors in
64061+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
64062+ Nearly all users should be able to enable this option.
64063+
64064+config GRKERNSEC_IO
64065+ bool "Disable privileged I/O"
64066+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64067+ depends on X86
64068+ select RTC_CLASS
64069+ select RTC_INTF_DEV
64070+ select RTC_DRV_CMOS
64071+
64072+ help
64073+ If you say Y here, all ioperm and iopl calls will return an error.
64074+ Ioperm and iopl can be used to modify the running kernel.
64075+ Unfortunately, some programs need this access to operate properly,
64076+ the most notable of which are XFree86 and hwclock. hwclock can be
64077+ remedied by having RTC support in the kernel, so real-time
64078+ clock support is enabled if this option is enabled, to ensure
64079+ that hwclock operates correctly.
64080+
64081+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
64082+ you may not be able to boot into a graphical environment with this
64083+ option enabled. In this case, you should use the RBAC system instead.
64084+
64085+config GRKERNSEC_JIT_HARDEN
64086+ bool "Harden BPF JIT against spray attacks"
64087+ default y if GRKERNSEC_CONFIG_AUTO
64088+ depends on BPF_JIT && X86
64089+ help
64090+ If you say Y here, the native code generated by the kernel's Berkeley
64091+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
64092+ attacks that attempt to fit attacker-beneficial instructions in
64093+ 32bit immediate fields of JIT-generated native instructions. The
64094+ attacker will generally aim to cause an unintended instruction sequence
64095+ of JIT-generated native code to execute by jumping into the middle of
64096+ a generated instruction. This feature effectively randomizes the 32bit
64097+ immediate constants present in the generated code to thwart such attacks.
64098+
64099+ If you're using KERNEXEC, it's recommended that you enable this option
64100+ to supplement the hardening of the kernel.
64101+
64102+config GRKERNSEC_PERF_HARDEN
64103+ bool "Disable unprivileged PERF_EVENTS usage by default"
64104+ default y if GRKERNSEC_CONFIG_AUTO
64105+ depends on PERF_EVENTS
64106+ help
64107+ If you say Y here, the range of acceptable values for the
64108+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
64109+ default to a new value: 3. When the sysctl is set to this value, no
64110+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
64111+
64112+ Though PERF_EVENTS can be used legitimately for performance monitoring
64113+ and low-level application profiling, it is forced on regardless of
64114+ configuration, has been at fault for several vulnerabilities, and
64115+ creates new opportunities for side channels and other information leaks.
64116+
64117+ This feature puts PERF_EVENTS into a secure default state and permits
64118+ the administrator to change out of it temporarily if unprivileged
64119+ application profiling is needed.
64120+
64121+config GRKERNSEC_RAND_THREADSTACK
64122+ bool "Insert random gaps between thread stacks"
64123+ default y if GRKERNSEC_CONFIG_AUTO
64124+ depends on PAX_RANDMMAP && !PPC
64125+ help
64126+ If you say Y here, a random-sized gap will be enforced between allocated
64127+ thread stacks. Glibc's NPTL and other threading libraries that
64128+ pass MAP_STACK to the kernel for thread stack allocation are supported.
64129+ The implementation currently provides 8 bits of entropy for the gap.
64130+
64131+ Many distributions do not compile threaded remote services with the
64132+ -fstack-check argument to GCC, causing the variable-sized stack-based
64133+ allocator, alloca(), to not probe the stack on allocation. This
64134+ permits an unbounded alloca() to skip over any guard page and potentially
64135+ modify another thread's stack reliably. An enforced random gap
64136+ reduces the reliability of such an attack and increases the chance
64137+ that such a read/write to another thread's stack instead lands in
64138+ an unmapped area, causing a crash and triggering grsecurity's
64139+ anti-bruteforcing logic.
64140+
64141+config GRKERNSEC_PROC_MEMMAP
64142+ bool "Harden ASLR against information leaks and entropy reduction"
64143+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
64144+ depends on PAX_NOEXEC || PAX_ASLR
64145+ help
64146+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
64147+ give no information about the addresses of its mappings if
64148+ PaX features that rely on random addresses are enabled on the task.
64149+ In addition to sanitizing this information and disabling other
64150+ dangerous sources of information, this option causes reads of sensitive
64151+ /proc/<pid> entries where the file descriptor was opened in a different
64152+ task than the one performing the read. Such attempts are logged.
64153+ This option also limits argv/env strings for suid/sgid binaries
64154+ to 512KB to prevent a complete exhaustion of the stack entropy provided
64155+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
64156+ binaries to prevent alternative mmap layouts from being abused.
64157+
64158+ If you use PaX it is essential that you say Y here as it closes up
64159+ several holes that make full ASLR useless locally.
64160+
64161+config GRKERNSEC_BRUTE
64162+ bool "Deter exploit bruteforcing"
64163+ default y if GRKERNSEC_CONFIG_AUTO
64164+ help
64165+ If you say Y here, attempts to bruteforce exploits against forking
64166+ daemons such as apache or sshd, as well as against suid/sgid binaries
64167+ will be deterred. When a child of a forking daemon is killed by PaX
64168+ or crashes due to an illegal instruction or other suspicious signal,
64169+ the parent process will be delayed 30 seconds upon every subsequent
64170+ fork until the administrator is able to assess the situation and
64171+ restart the daemon.
64172+ In the suid/sgid case, the attempt is logged, the user has all their
64173+ existing instances of the suid/sgid binary terminated and will
64174+ be unable to execute any suid/sgid binaries for 15 minutes.
64175+
64176+ It is recommended that you also enable signal logging in the auditing
64177+ section so that logs are generated when a process triggers a suspicious
64178+ signal.
64179+ If the sysctl option is enabled, a sysctl option with name
64180+ "deter_bruteforce" is created.
64181+
64182+config GRKERNSEC_MODHARDEN
64183+ bool "Harden module auto-loading"
64184+ default y if GRKERNSEC_CONFIG_AUTO
64185+ depends on MODULES
64186+ help
64187+ If you say Y here, module auto-loading in response to use of some
64188+ feature implemented by an unloaded module will be restricted to
64189+ root users. Enabling this option helps defend against attacks
64190+ by unprivileged users who abuse the auto-loading behavior to
64191+ cause a vulnerable module to load that is then exploited.
64192+
64193+ If this option prevents a legitimate use of auto-loading for a
64194+ non-root user, the administrator can execute modprobe manually
64195+ with the exact name of the module mentioned in the alert log.
64196+ Alternatively, the administrator can add the module to the list
64197+ of modules loaded at boot by modifying init scripts.
64198+
64199+ Modification of init scripts will most likely be needed on
64200+ Ubuntu servers with encrypted home directory support enabled,
64201+ as the first non-root user logging in will cause the ecb(aes),
64202+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
64203+
64204+config GRKERNSEC_HIDESYM
64205+ bool "Hide kernel symbols"
64206+ default y if GRKERNSEC_CONFIG_AUTO
64207+ select PAX_USERCOPY_SLABS
64208+ help
64209+ If you say Y here, getting information on loaded modules, and
64210+ displaying all kernel symbols through a syscall will be restricted
64211+ to users with CAP_SYS_MODULE. For software compatibility reasons,
64212+ /proc/kallsyms will be restricted to the root user. The RBAC
64213+ system can hide that entry even from root.
64214+
64215+ This option also prevents leaking of kernel addresses through
64216+ several /proc entries.
64217+
64218+ Note that this option is only effective provided the following
64219+ conditions are met:
64220+ 1) The kernel using grsecurity is not precompiled by some distribution
64221+ 2) You have also enabled GRKERNSEC_DMESG
64222+ 3) You are using the RBAC system and hiding other files such as your
64223+ kernel image and System.map. Alternatively, enabling this option
64224+ causes the permissions on /boot, /lib/modules, and the kernel
64225+ source directory to change at compile time to prevent
64226+ reading by non-root users.
64227+ If the above conditions are met, this option will aid in providing a
64228+ useful protection against local kernel exploitation of overflows
64229+ and arbitrary read/write vulnerabilities.
64230+
64231+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
64232+ in addition to this feature.
64233+
64234+config GRKERNSEC_RANDSTRUCT
64235+ bool "Randomize layout of sensitive kernel structures"
64236+ default y if GRKERNSEC_CONFIG_AUTO
64237+ select GRKERNSEC_HIDESYM
64238+ help
64239+ If you say Y here, the layouts of a number of sensitive kernel
64240+ structures (task, fs, cred, etc) and all structures composed entirely
64241+ of function pointers (aka "ops" structs) will be randomized at compile-time.
64242+ This can introduce the requirement of an additional infoleak
64243+ vulnerability for exploits targeting these structure types.
64244+
64245+ Enabling this feature will introduce some performance impact, slightly
64246+ increase memory usage, and prevent the use of forensic tools like
64247+ Volatility against the system (unless the kernel source tree isn't
64248+ cleaned after kernel installation).
64249+
64250+ The seed used for compilation is located at tools/gcc/randstruct.seed.
64251+ It remains after a make clean to allow for external modules to be compiled
64252+ with the existing seed and will be removed by a make mrproper or
64253+ make distclean.
64254+
64255+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
64256+ bool "Use cacheline-aware structure randomization"
64257+ depends on GRKERNSEC_RANDSTRUCT
64258+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
64259+ help
64260+ If you say Y here, the RANDSTRUCT randomization will make a best effort
64261+ at restricting randomization to cacheline-sized groups of elements. It
64262+ will further not randomize bitfields in structures. This reduces the
64263+ performance hit of RANDSTRUCT at the cost of weakened randomization.
64264+
64265+config GRKERNSEC_KERN_LOCKOUT
64266+ bool "Active kernel exploit response"
64267+ default y if GRKERNSEC_CONFIG_AUTO
64268+ depends on X86 || ARM || PPC || SPARC
64269+ help
64270+ If you say Y here, when a PaX alert is triggered due to suspicious
64271+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
64272+ or an OOPS occurs due to bad memory accesses, instead of just
64273+ terminating the offending process (and potentially allowing
64274+ a subsequent exploit from the same user), we will take one of two
64275+ actions:
64276+ If the user was root, we will panic the system
64277+ If the user was non-root, we will log the attempt, terminate
64278+ all processes owned by the user, then prevent them from creating
64279+ any new processes until the system is restarted
64280+ This deters repeated kernel exploitation/bruteforcing attempts
64281+ and is useful for later forensics.
64282+
64283+config GRKERNSEC_OLD_ARM_USERLAND
64284+ bool "Old ARM userland compatibility"
64285+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
64286+ help
64287+ If you say Y here, stubs of executable code to perform such operations
64288+ as "compare-exchange" will be placed at fixed locations in the ARM vector
64289+ table. This is unfortunately needed for old ARM userland meant to run
64290+ across a wide range of processors. Without this option enabled,
64291+ the get_tls and data memory barrier stubs will be emulated by the kernel,
64292+ which is enough for Linaro userlands or other userlands designed for v6
64293+ and newer ARM CPUs. It's recommended that you try without this option enabled
64294+ first, and only enable it if your userland does not boot (it will likely fail
64295+ at init time).
64296+
64297+endmenu
64298+menu "Role Based Access Control Options"
64299+depends on GRKERNSEC
64300+
64301+config GRKERNSEC_RBAC_DEBUG
64302+ bool
64303+
64304+config GRKERNSEC_NO_RBAC
64305+ bool "Disable RBAC system"
64306+ help
64307+ If you say Y here, the /dev/grsec device will be removed from the kernel,
64308+ preventing the RBAC system from being enabled. You should only say Y
64309+ here if you have no intention of using the RBAC system, so as to prevent
64310+ an attacker with root access from misusing the RBAC system to hide files
64311+ and processes when loadable module support and /dev/[k]mem have been
64312+ locked down.
64313+
64314+config GRKERNSEC_ACL_HIDEKERN
64315+ bool "Hide kernel processes"
64316+ help
64317+ If you say Y here, all kernel threads will be hidden to all
64318+ processes but those whose subject has the "view hidden processes"
64319+ flag.
64320+
64321+config GRKERNSEC_ACL_MAXTRIES
64322+ int "Maximum tries before password lockout"
64323+ default 3
64324+ help
64325+ This option enforces the maximum number of times a user can attempt
64326+ to authorize themselves with the grsecurity RBAC system before being
64327+ denied the ability to attempt authorization again for a specified time.
64328+ The lower the number, the harder it will be to brute-force a password.
64329+
64330+config GRKERNSEC_ACL_TIMEOUT
64331+ int "Time to wait after max password tries, in seconds"
64332+ default 30
64333+ help
64334+ This option specifies the time the user must wait after attempting to
64335+ authorize to the RBAC system with the maximum number of invalid
64336+ passwords. The higher the number, the harder it will be to brute-force
64337+ a password.
64338+
64339+endmenu
64340+menu "Filesystem Protections"
64341+depends on GRKERNSEC
64342+
64343+config GRKERNSEC_PROC
64344+ bool "Proc restrictions"
64345+ default y if GRKERNSEC_CONFIG_AUTO
64346+ help
64347+ If you say Y here, the permissions of the /proc filesystem
64348+ will be altered to enhance system security and privacy. You MUST
64349+ choose either a user only restriction or a user and group restriction.
64350+ Depending upon the option you choose, you can either restrict users to
64351+ see only the processes they themselves run, or choose a group that can
64352+ view all processes and files normally restricted to root if you choose
64353+ the "restrict to user only" option. NOTE: If you're running identd or
64354+ ntpd as a non-root user, you will have to run it as the group you
64355+ specify here.
64356+
64357+config GRKERNSEC_PROC_USER
64358+ bool "Restrict /proc to user only"
64359+ depends on GRKERNSEC_PROC
64360+ help
64361+ If you say Y here, non-root users will only be able to view their own
64362+ processes, and restricts them from viewing network-related information,
64363+ and viewing kernel symbol and module information.
64364+
64365+config GRKERNSEC_PROC_USERGROUP
64366+ bool "Allow special group"
64367+ default y if GRKERNSEC_CONFIG_AUTO
64368+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
64369+ help
64370+ If you say Y here, you will be able to select a group that will be
64371+ able to view all processes and network-related information. If you've
64372+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
64373+ remain hidden. This option is useful if you want to run identd as
64374+ a non-root user. The group you select may also be chosen at boot time
64375+ via "grsec_proc_gid=" on the kernel commandline.
64376+
64377+config GRKERNSEC_PROC_GID
64378+ int "GID for special group"
64379+ depends on GRKERNSEC_PROC_USERGROUP
64380+ default 1001
64381+
64382+config GRKERNSEC_PROC_ADD
64383+ bool "Additional restrictions"
64384+ default y if GRKERNSEC_CONFIG_AUTO
64385+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
64386+ help
64387+ If you say Y here, additional restrictions will be placed on
64388+ /proc that keep normal users from viewing device information and
64389+ slabinfo information that could be useful for exploits.
64390+
64391+config GRKERNSEC_LINK
64392+ bool "Linking restrictions"
64393+ default y if GRKERNSEC_CONFIG_AUTO
64394+ help
64395+ If you say Y here, /tmp race exploits will be prevented, since users
64396+ will no longer be able to follow symlinks owned by other users in
64397+ world-writable +t directories (e.g. /tmp), unless the owner of the
64398+ symlink is the owner of the directory. users will also not be
64399+ able to hardlink to files they do not own. If the sysctl option is
64400+ enabled, a sysctl option with name "linking_restrictions" is created.
64401+
64402+config GRKERNSEC_SYMLINKOWN
64403+ bool "Kernel-enforced SymlinksIfOwnerMatch"
64404+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64405+ help
64406+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
64407+ that prevents it from being used as a security feature. As Apache
64408+ verifies the symlink by performing a stat() against the target of
64409+ the symlink before it is followed, an attacker can setup a symlink
64410+ to point to a same-owned file, then replace the symlink with one
64411+ that targets another user's file just after Apache "validates" the
64412+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
64413+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
64414+ will be in place for the group you specify. If the sysctl option
64415+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
64416+ created.
64417+
64418+config GRKERNSEC_SYMLINKOWN_GID
64419+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
64420+ depends on GRKERNSEC_SYMLINKOWN
64421+ default 1006
64422+ help
64423+ Setting this GID determines what group kernel-enforced
64424+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
64425+ is enabled, a sysctl option with name "symlinkown_gid" is created.
64426+
64427+config GRKERNSEC_FIFO
64428+ bool "FIFO restrictions"
64429+ default y if GRKERNSEC_CONFIG_AUTO
64430+ help
64431+ If you say Y here, users will not be able to write to FIFOs they don't
64432+ own in world-writable +t directories (e.g. /tmp), unless the owner of
64433+ the FIFO is the same owner of the directory it's held in. If the sysctl
64434+ option is enabled, a sysctl option with name "fifo_restrictions" is
64435+ created.
64436+
64437+config GRKERNSEC_SYSFS_RESTRICT
64438+ bool "Sysfs/debugfs restriction"
64439+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64440+ depends on SYSFS
64441+ help
64442+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
64443+ any filesystem normally mounted under it (e.g. debugfs) will be
64444+ mostly accessible only by root. These filesystems generally provide access
64445+ to hardware and debug information that isn't appropriate for unprivileged
64446+ users of the system. Sysfs and debugfs have also become a large source
64447+ of new vulnerabilities, ranging from infoleaks to local compromise.
64448+ There has been very little oversight with an eye toward security involved
64449+ in adding new exporters of information to these filesystems, so their
64450+ use is discouraged.
64451+ For reasons of compatibility, a few directories have been whitelisted
64452+ for access by non-root users:
64453+ /sys/fs/selinux
64454+ /sys/fs/fuse
64455+ /sys/devices/system/cpu
64456+
64457+config GRKERNSEC_ROFS
64458+ bool "Runtime read-only mount protection"
64459+ depends on SYSCTL
64460+ help
64461+ If you say Y here, a sysctl option with name "romount_protect" will
64462+ be created. By setting this option to 1 at runtime, filesystems
64463+ will be protected in the following ways:
64464+ * No new writable mounts will be allowed
64465+ * Existing read-only mounts won't be able to be remounted read/write
64466+ * Write operations will be denied on all block devices
64467+ This option acts independently of grsec_lock: once it is set to 1,
64468+ it cannot be turned off. Therefore, please be mindful of the resulting
64469+ behavior if this option is enabled in an init script on a read-only
64470+ filesystem.
64471+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
64472+ and GRKERNSEC_IO should be enabled and module loading disabled via
64473+ config or at runtime.
64474+ This feature is mainly intended for secure embedded systems.
64475+
64476+
64477+config GRKERNSEC_DEVICE_SIDECHANNEL
64478+ bool "Eliminate stat/notify-based device sidechannels"
64479+ default y if GRKERNSEC_CONFIG_AUTO
64480+ help
64481+ If you say Y here, timing analyses on block or character
64482+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
64483+ will be thwarted for unprivileged users. If a process without
64484+ CAP_MKNOD stats such a device, the last access and last modify times
64485+ will match the device's create time. No access or modify events
64486+ will be triggered through inotify/dnotify/fanotify for such devices.
64487+ This feature will prevent attacks that may at a minimum
64488+ allow an attacker to determine the administrator's password length.
64489+
64490+config GRKERNSEC_CHROOT
64491+ bool "Chroot jail restrictions"
64492+ default y if GRKERNSEC_CONFIG_AUTO
64493+ help
64494+ If you say Y here, you will be able to choose several options that will
64495+ make breaking out of a chrooted jail much more difficult. If you
64496+ encounter no software incompatibilities with the following options, it
64497+ is recommended that you enable each one.
64498+
64499+config GRKERNSEC_CHROOT_MOUNT
64500+ bool "Deny mounts"
64501+ default y if GRKERNSEC_CONFIG_AUTO
64502+ depends on GRKERNSEC_CHROOT
64503+ help
64504+ If you say Y here, processes inside a chroot will not be able to
64505+ mount or remount filesystems. If the sysctl option is enabled, a
64506+ sysctl option with name "chroot_deny_mount" is created.
64507+
64508+config GRKERNSEC_CHROOT_DOUBLE
64509+ bool "Deny double-chroots"
64510+ default y if GRKERNSEC_CONFIG_AUTO
64511+ depends on GRKERNSEC_CHROOT
64512+ help
64513+ If you say Y here, processes inside a chroot will not be able to chroot
64514+ again outside the chroot. This is a widely used method of breaking
64515+ out of a chroot jail and should not be allowed. If the sysctl
64516+ option is enabled, a sysctl option with name
64517+ "chroot_deny_chroot" is created.
64518+
64519+config GRKERNSEC_CHROOT_PIVOT
64520+ bool "Deny pivot_root in chroot"
64521+ default y if GRKERNSEC_CONFIG_AUTO
64522+ depends on GRKERNSEC_CHROOT
64523+ help
64524+ If you say Y here, processes inside a chroot will not be able to use
64525+ a function called pivot_root() that was introduced in Linux 2.3.41. It
64526+ works similar to chroot in that it changes the root filesystem. This
64527+ function could be misused in a chrooted process to attempt to break out
64528+ of the chroot, and therefore should not be allowed. If the sysctl
64529+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
64530+ created.
64531+
64532+config GRKERNSEC_CHROOT_CHDIR
64533+ bool "Enforce chdir(\"/\") on all chroots"
64534+ default y if GRKERNSEC_CONFIG_AUTO
64535+ depends on GRKERNSEC_CHROOT
64536+ help
64537+ If you say Y here, the current working directory of all newly-chrooted
64538+ applications will be set to the the root directory of the chroot.
64539+ The man page on chroot(2) states:
64540+ Note that this call does not change the current working
64541+ directory, so that `.' can be outside the tree rooted at
64542+ `/'. In particular, the super-user can escape from a
64543+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
64544+
64545+ It is recommended that you say Y here, since it's not known to break
64546+ any software. If the sysctl option is enabled, a sysctl option with
64547+ name "chroot_enforce_chdir" is created.
64548+
64549+config GRKERNSEC_CHROOT_CHMOD
64550+ bool "Deny (f)chmod +s"
64551+ default y if GRKERNSEC_CONFIG_AUTO
64552+ depends on GRKERNSEC_CHROOT
64553+ help
64554+ If you say Y here, processes inside a chroot will not be able to chmod
64555+ or fchmod files to make them have suid or sgid bits. This protects
64556+ against another published method of breaking a chroot. If the sysctl
64557+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
64558+ created.
64559+
64560+config GRKERNSEC_CHROOT_FCHDIR
64561+ bool "Deny fchdir out of chroot"
64562+ default y if GRKERNSEC_CONFIG_AUTO
64563+ depends on GRKERNSEC_CHROOT
64564+ help
64565+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
64566+ to a file descriptor of the chrooting process that points to a directory
64567+ outside the filesystem will be stopped. If the sysctl option
64568+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
64569+
64570+config GRKERNSEC_CHROOT_MKNOD
64571+ bool "Deny mknod"
64572+ default y if GRKERNSEC_CONFIG_AUTO
64573+ depends on GRKERNSEC_CHROOT
64574+ help
64575+ If you say Y here, processes inside a chroot will not be allowed to
64576+ mknod. The problem with using mknod inside a chroot is that it
64577+ would allow an attacker to create a device entry that is the same
64578+ as one on the physical root of your system, which could range from
64579+ anything from the console device to a device for your harddrive (which
64580+ they could then use to wipe the drive or steal data). It is recommended
64581+ that you say Y here, unless you run into software incompatibilities.
64582+ If the sysctl option is enabled, a sysctl option with name
64583+ "chroot_deny_mknod" is created.
64584+
64585+config GRKERNSEC_CHROOT_SHMAT
64586+ bool "Deny shmat() out of chroot"
64587+ default y if GRKERNSEC_CONFIG_AUTO
64588+ depends on GRKERNSEC_CHROOT
64589+ help
64590+ If you say Y here, processes inside a chroot will not be able to attach
64591+ to shared memory segments that were created outside of the chroot jail.
64592+ It is recommended that you say Y here. If the sysctl option is enabled,
64593+ a sysctl option with name "chroot_deny_shmat" is created.
64594+
64595+config GRKERNSEC_CHROOT_UNIX
64596+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
64597+ default y if GRKERNSEC_CONFIG_AUTO
64598+ depends on GRKERNSEC_CHROOT
64599+ help
64600+ If you say Y here, processes inside a chroot will not be able to
64601+ connect to abstract (meaning not belonging to a filesystem) Unix
64602+ domain sockets that were bound outside of a chroot. It is recommended
64603+ that you say Y here. If the sysctl option is enabled, a sysctl option
64604+ with name "chroot_deny_unix" is created.
64605+
64606+config GRKERNSEC_CHROOT_FINDTASK
64607+ bool "Protect outside processes"
64608+ default y if GRKERNSEC_CONFIG_AUTO
64609+ depends on GRKERNSEC_CHROOT
64610+ help
64611+ If you say Y here, processes inside a chroot will not be able to
64612+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
64613+ getsid, or view any process outside of the chroot. If the sysctl
64614+ option is enabled, a sysctl option with name "chroot_findtask" is
64615+ created.
64616+
64617+config GRKERNSEC_CHROOT_NICE
64618+ bool "Restrict priority changes"
64619+ default y if GRKERNSEC_CONFIG_AUTO
64620+ depends on GRKERNSEC_CHROOT
64621+ help
64622+ If you say Y here, processes inside a chroot will not be able to raise
64623+ the priority of processes in the chroot, or alter the priority of
64624+ processes outside the chroot. This provides more security than simply
64625+ removing CAP_SYS_NICE from the process' capability set. If the
64626+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
64627+ is created.
64628+
64629+config GRKERNSEC_CHROOT_SYSCTL
64630+ bool "Deny sysctl writes"
64631+ default y if GRKERNSEC_CONFIG_AUTO
64632+ depends on GRKERNSEC_CHROOT
64633+ help
64634+ If you say Y here, an attacker in a chroot will not be able to
64635+ write to sysctl entries, either by sysctl(2) or through a /proc
64636+ interface. It is strongly recommended that you say Y here. If the
64637+ sysctl option is enabled, a sysctl option with name
64638+ "chroot_deny_sysctl" is created.
64639+
64640+config GRKERNSEC_CHROOT_CAPS
64641+ bool "Capability restrictions"
64642+ default y if GRKERNSEC_CONFIG_AUTO
64643+ depends on GRKERNSEC_CHROOT
64644+ help
64645+ If you say Y here, the capabilities on all processes within a
64646+ chroot jail will be lowered to stop module insertion, raw i/o,
64647+ system and net admin tasks, rebooting the system, modifying immutable
64648+ files, modifying IPC owned by another, and changing the system time.
64649+ This is left an option because it can break some apps. Disable this
64650+ if your chrooted apps are having problems performing those kinds of
64651+ tasks. If the sysctl option is enabled, a sysctl option with
64652+ name "chroot_caps" is created.
64653+
64654+config GRKERNSEC_CHROOT_INITRD
64655+ bool "Exempt initrd tasks from restrictions"
64656+ default y if GRKERNSEC_CONFIG_AUTO
64657+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
64658+ help
64659+ If you say Y here, tasks started prior to init will be exempted from
64660+ grsecurity's chroot restrictions. This option is mainly meant to
64661+ resolve Plymouth's performing privileged operations unnecessarily
64662+ in a chroot.
64663+
64664+endmenu
64665+menu "Kernel Auditing"
64666+depends on GRKERNSEC
64667+
64668+config GRKERNSEC_AUDIT_GROUP
64669+ bool "Single group for auditing"
64670+ help
64671+ If you say Y here, the exec and chdir logging features will only operate
64672+ on a group you specify. This option is recommended if you only want to
64673+ watch certain users instead of having a large amount of logs from the
64674+ entire system. If the sysctl option is enabled, a sysctl option with
64675+ name "audit_group" is created.
64676+
64677+config GRKERNSEC_AUDIT_GID
64678+ int "GID for auditing"
64679+ depends on GRKERNSEC_AUDIT_GROUP
64680+ default 1007
64681+
64682+config GRKERNSEC_EXECLOG
64683+ bool "Exec logging"
64684+ help
64685+ If you say Y here, all execve() calls will be logged (since the
64686+ other exec*() calls are frontends to execve(), all execution
64687+ will be logged). Useful for shell-servers that like to keep track
64688+ of their users. If the sysctl option is enabled, a sysctl option with
64689+ name "exec_logging" is created.
64690+ WARNING: This option when enabled will produce a LOT of logs, especially
64691+ on an active system.
64692+
64693+config GRKERNSEC_RESLOG
64694+ bool "Resource logging"
64695+ default y if GRKERNSEC_CONFIG_AUTO
64696+ help
64697+ If you say Y here, all attempts to overstep resource limits will
64698+ be logged with the resource name, the requested size, and the current
64699+ limit. It is highly recommended that you say Y here. If the sysctl
64700+ option is enabled, a sysctl option with name "resource_logging" is
64701+ created. If the RBAC system is enabled, the sysctl value is ignored.
64702+
64703+config GRKERNSEC_CHROOT_EXECLOG
64704+ bool "Log execs within chroot"
64705+ help
64706+ If you say Y here, all executions inside a chroot jail will be logged
64707+ to syslog. This can cause a large amount of logs if certain
64708+ applications (eg. djb's daemontools) are installed on the system, and
64709+ is therefore left as an option. If the sysctl option is enabled, a
64710+ sysctl option with name "chroot_execlog" is created.
64711+
64712+config GRKERNSEC_AUDIT_PTRACE
64713+ bool "Ptrace logging"
64714+ help
64715+ If you say Y here, all attempts to attach to a process via ptrace
64716+ will be logged. If the sysctl option is enabled, a sysctl option
64717+ with name "audit_ptrace" is created.
64718+
64719+config GRKERNSEC_AUDIT_CHDIR
64720+ bool "Chdir logging"
64721+ help
64722+ If you say Y here, all chdir() calls will be logged. If the sysctl
64723+ option is enabled, a sysctl option with name "audit_chdir" is created.
64724+
64725+config GRKERNSEC_AUDIT_MOUNT
64726+ bool "(Un)Mount logging"
64727+ help
64728+ If you say Y here, all mounts and unmounts will be logged. If the
64729+ sysctl option is enabled, a sysctl option with name "audit_mount" is
64730+ created.
64731+
64732+config GRKERNSEC_SIGNAL
64733+ bool "Signal logging"
64734+ default y if GRKERNSEC_CONFIG_AUTO
64735+ help
64736+ If you say Y here, certain important signals will be logged, such as
64737+ SIGSEGV, which will as a result inform you of when a error in a program
64738+ occurred, which in some cases could mean a possible exploit attempt.
64739+ If the sysctl option is enabled, a sysctl option with name
64740+ "signal_logging" is created.
64741+
64742+config GRKERNSEC_FORKFAIL
64743+ bool "Fork failure logging"
64744+ help
64745+ If you say Y here, all failed fork() attempts will be logged.
64746+ This could suggest a fork bomb, or someone attempting to overstep
64747+ their process limit. If the sysctl option is enabled, a sysctl option
64748+ with name "forkfail_logging" is created.
64749+
64750+config GRKERNSEC_TIME
64751+ bool "Time change logging"
64752+ default y if GRKERNSEC_CONFIG_AUTO
64753+ help
64754+ If you say Y here, any changes of the system clock will be logged.
64755+ If the sysctl option is enabled, a sysctl option with name
64756+ "timechange_logging" is created.
64757+
64758+config GRKERNSEC_PROC_IPADDR
64759+ bool "/proc/<pid>/ipaddr support"
64760+ default y if GRKERNSEC_CONFIG_AUTO
64761+ help
64762+ If you say Y here, a new entry will be added to each /proc/<pid>
64763+ directory that contains the IP address of the person using the task.
64764+ The IP is carried across local TCP and AF_UNIX stream sockets.
64765+ This information can be useful for IDS/IPSes to perform remote response
64766+ to a local attack. The entry is readable by only the owner of the
64767+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
64768+ the RBAC system), and thus does not create privacy concerns.
64769+
64770+config GRKERNSEC_RWXMAP_LOG
64771+ bool 'Denied RWX mmap/mprotect logging'
64772+ default y if GRKERNSEC_CONFIG_AUTO
64773+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
64774+ help
64775+ If you say Y here, calls to mmap() and mprotect() with explicit
64776+ usage of PROT_WRITE and PROT_EXEC together will be logged when
64777+ denied by the PAX_MPROTECT feature. This feature will also
64778+ log other problematic scenarios that can occur when PAX_MPROTECT
64779+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
64780+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
64781+ is created.
64782+
64783+endmenu
64784+
64785+menu "Executable Protections"
64786+depends on GRKERNSEC
64787+
64788+config GRKERNSEC_DMESG
64789+ bool "Dmesg(8) restriction"
64790+ default y if GRKERNSEC_CONFIG_AUTO
64791+ help
64792+ If you say Y here, non-root users will not be able to use dmesg(8)
64793+ to view the contents of the kernel's circular log buffer.
64794+ The kernel's log buffer often contains kernel addresses and other
64795+ identifying information useful to an attacker in fingerprinting a
64796+ system for a targeted exploit.
64797+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
64798+ created.
64799+
64800+config GRKERNSEC_HARDEN_PTRACE
64801+ bool "Deter ptrace-based process snooping"
64802+ default y if GRKERNSEC_CONFIG_AUTO
64803+ help
64804+ If you say Y here, TTY sniffers and other malicious monitoring
64805+ programs implemented through ptrace will be defeated. If you
64806+ have been using the RBAC system, this option has already been
64807+ enabled for several years for all users, with the ability to make
64808+ fine-grained exceptions.
64809+
64810+ This option only affects the ability of non-root users to ptrace
64811+ processes that are not a descendent of the ptracing process.
64812+ This means that strace ./binary and gdb ./binary will still work,
64813+ but attaching to arbitrary processes will not. If the sysctl
64814+ option is enabled, a sysctl option with name "harden_ptrace" is
64815+ created.
64816+
64817+config GRKERNSEC_PTRACE_READEXEC
64818+ bool "Require read access to ptrace sensitive binaries"
64819+ default y if GRKERNSEC_CONFIG_AUTO
64820+ help
64821+ If you say Y here, unprivileged users will not be able to ptrace unreadable
64822+ binaries. This option is useful in environments that
64823+ remove the read bits (e.g. file mode 4711) from suid binaries to
64824+ prevent infoleaking of their contents. This option adds
64825+ consistency to the use of that file mode, as the binary could normally
64826+ be read out when run without privileges while ptracing.
64827+
64828+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
64829+ is created.
64830+
64831+config GRKERNSEC_SETXID
64832+ bool "Enforce consistent multithreaded privileges"
64833+ default y if GRKERNSEC_CONFIG_AUTO
64834+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
64835+ help
64836+ If you say Y here, a change from a root uid to a non-root uid
64837+ in a multithreaded application will cause the resulting uids,
64838+ gids, supplementary groups, and capabilities in that thread
64839+ to be propagated to the other threads of the process. In most
64840+ cases this is unnecessary, as glibc will emulate this behavior
64841+ on behalf of the application. Other libcs do not act in the
64842+ same way, allowing the other threads of the process to continue
64843+ running with root privileges. If the sysctl option is enabled,
64844+ a sysctl option with name "consistent_setxid" is created.
64845+
64846+config GRKERNSEC_HARDEN_IPC
64847+ bool "Disallow access to overly-permissive IPC objects"
64848+ default y if GRKERNSEC_CONFIG_AUTO
64849+ depends on SYSVIPC
64850+ help
64851+ If you say Y here, access to overly-permissive IPC objects (shared
64852+ memory, message queues, and semaphores) will be denied for processes
64853+ given the following criteria beyond normal permission checks:
64854+ 1) If the IPC object is world-accessible and the euid doesn't match
64855+ that of the creator or current uid for the IPC object
64856+ 2) If the IPC object is group-accessible and the egid doesn't
64857+ match that of the creator or current gid for the IPC object
64858+ It's a common error to grant too much permission to these objects,
64859+ with impact ranging from denial of service and information leaking to
64860+ privilege escalation. This feature was developed in response to
64861+ research by Tim Brown:
64862+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
64863+ who found hundreds of such insecure usages. Processes with
64864+ CAP_IPC_OWNER are still permitted to access these IPC objects.
64865+ If the sysctl option is enabled, a sysctl option with name
64866+ "harden_ipc" is created.
64867+
64868+config GRKERNSEC_TPE
64869+ bool "Trusted Path Execution (TPE)"
64870+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64871+ help
64872+ If you say Y here, you will be able to choose a gid to add to the
64873+ supplementary groups of users you want to mark as "untrusted."
64874+ These users will not be able to execute any files that are not in
64875+ root-owned directories writable only by root. If the sysctl option
64876+ is enabled, a sysctl option with name "tpe" is created.
64877+
64878+config GRKERNSEC_TPE_ALL
64879+ bool "Partially restrict all non-root users"
64880+ depends on GRKERNSEC_TPE
64881+ help
64882+ If you say Y here, all non-root users will be covered under
64883+ a weaker TPE restriction. This is separate from, and in addition to,
64884+ the main TPE options that you have selected elsewhere. Thus, if a
64885+ "trusted" GID is chosen, this restriction applies to even that GID.
64886+ Under this restriction, all non-root users will only be allowed to
64887+ execute files in directories they own that are not group or
64888+ world-writable, or in directories owned by root and writable only by
64889+ root. If the sysctl option is enabled, a sysctl option with name
64890+ "tpe_restrict_all" is created.
64891+
64892+config GRKERNSEC_TPE_INVERT
64893+ bool "Invert GID option"
64894+ depends on GRKERNSEC_TPE
64895+ help
64896+ If you say Y here, the group you specify in the TPE configuration will
64897+ decide what group TPE restrictions will be *disabled* for. This
64898+ option is useful if you want TPE restrictions to be applied to most
64899+ users on the system. If the sysctl option is enabled, a sysctl option
64900+ with name "tpe_invert" is created. Unlike other sysctl options, this
64901+ entry will default to on for backward-compatibility.
64902+
64903+config GRKERNSEC_TPE_GID
64904+ int
64905+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
64906+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
64907+
64908+config GRKERNSEC_TPE_UNTRUSTED_GID
64909+ int "GID for TPE-untrusted users"
64910+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
64911+ default 1005
64912+ help
64913+ Setting this GID determines what group TPE restrictions will be
64914+ *enabled* for. If the sysctl option is enabled, a sysctl option
64915+ with name "tpe_gid" is created.
64916+
64917+config GRKERNSEC_TPE_TRUSTED_GID
64918+ int "GID for TPE-trusted users"
64919+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
64920+ default 1005
64921+ help
64922+ Setting this GID determines what group TPE restrictions will be
64923+ *disabled* for. If the sysctl option is enabled, a sysctl option
64924+ with name "tpe_gid" is created.
64925+
64926+endmenu
64927+menu "Network Protections"
64928+depends on GRKERNSEC
64929+
64930+config GRKERNSEC_RANDNET
64931+ bool "Larger entropy pools"
64932+ default y if GRKERNSEC_CONFIG_AUTO
64933+ help
64934+ If you say Y here, the entropy pools used for many features of Linux
64935+ and grsecurity will be doubled in size. Since several grsecurity
64936+ features use additional randomness, it is recommended that you say Y
64937+ here. Saying Y here has a similar effect as modifying
64938+ /proc/sys/kernel/random/poolsize.
64939+
64940+config GRKERNSEC_BLACKHOLE
64941+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
64942+ default y if GRKERNSEC_CONFIG_AUTO
64943+ depends on NET
64944+ help
64945+ If you say Y here, neither TCP resets nor ICMP
64946+ destination-unreachable packets will be sent in response to packets
64947+ sent to ports for which no associated listening process exists.
64948+ This feature supports both IPV4 and IPV6 and exempts the
64949+ loopback interface from blackholing. Enabling this feature
64950+ makes a host more resilient to DoS attacks and reduces network
64951+ visibility against scanners.
64952+
64953+ The blackhole feature as-implemented is equivalent to the FreeBSD
64954+ blackhole feature, as it prevents RST responses to all packets, not
64955+ just SYNs. Under most application behavior this causes no
64956+ problems, but applications (like haproxy) may not close certain
64957+ connections in a way that cleanly terminates them on the remote
64958+ end, leaving the remote host in LAST_ACK state. Because of this
64959+ side-effect and to prevent intentional LAST_ACK DoSes, this
64960+ feature also adds automatic mitigation against such attacks.
64961+ The mitigation drastically reduces the amount of time a socket
64962+ can spend in LAST_ACK state. If you're using haproxy and not
64963+ all servers it connects to have this option enabled, consider
64964+ disabling this feature on the haproxy host.
64965+
64966+ If the sysctl option is enabled, two sysctl options with names
64967+ "ip_blackhole" and "lastack_retries" will be created.
64968+ While "ip_blackhole" takes the standard zero/non-zero on/off
64969+ toggle, "lastack_retries" uses the same kinds of values as
64970+ "tcp_retries1" and "tcp_retries2". The default value of 4
64971+ prevents a socket from lasting more than 45 seconds in LAST_ACK
64972+ state.
64973+
64974+config GRKERNSEC_NO_SIMULT_CONNECT
64975+ bool "Disable TCP Simultaneous Connect"
64976+ default y if GRKERNSEC_CONFIG_AUTO
64977+ depends on NET
64978+ help
64979+ If you say Y here, a feature by Willy Tarreau will be enabled that
64980+ removes a weakness in Linux's strict implementation of TCP that
64981+ allows two clients to connect to each other without either entering
64982+ a listening state. The weakness allows an attacker to easily prevent
64983+ a client from connecting to a known server provided the source port
64984+ for the connection is guessed correctly.
64985+
64986+ As the weakness could be used to prevent an antivirus or IPS from
64987+ fetching updates, or prevent an SSL gateway from fetching a CRL,
64988+ it should be eliminated by enabling this option. Though Linux is
64989+ one of few operating systems supporting simultaneous connect, it
64990+ has no legitimate use in practice and is rarely supported by firewalls.
64991+
64992+config GRKERNSEC_SOCKET
64993+ bool "Socket restrictions"
64994+ depends on NET
64995+ help
64996+ If you say Y here, you will be able to choose from several options.
64997+ If you assign a GID on your system and add it to the supplementary
64998+ groups of users you want to restrict socket access to, this patch
64999+ will perform up to three things, based on the option(s) you choose.
65000+
65001+config GRKERNSEC_SOCKET_ALL
65002+ bool "Deny any sockets to group"
65003+ depends on GRKERNSEC_SOCKET
65004+ help
65005+ If you say Y here, you will be able to choose a GID of whose users will
65006+ be unable to connect to other hosts from your machine or run server
65007+ applications from your machine. If the sysctl option is enabled, a
65008+ sysctl option with name "socket_all" is created.
65009+
65010+config GRKERNSEC_SOCKET_ALL_GID
65011+ int "GID to deny all sockets for"
65012+ depends on GRKERNSEC_SOCKET_ALL
65013+ default 1004
65014+ help
65015+ Here you can choose the GID to disable socket access for. Remember to
65016+ add the users you want socket access disabled for to the GID
65017+ specified here. If the sysctl option is enabled, a sysctl option
65018+ with name "socket_all_gid" is created.
65019+
65020+config GRKERNSEC_SOCKET_CLIENT
65021+ bool "Deny client sockets to group"
65022+ depends on GRKERNSEC_SOCKET
65023+ help
65024+ If you say Y here, you will be able to choose a GID of whose users will
65025+ be unable to connect to other hosts from your machine, but will be
65026+ able to run servers. If this option is enabled, all users in the group
65027+ you specify will have to use passive mode when initiating ftp transfers
65028+ from the shell on your machine. If the sysctl option is enabled, a
65029+ sysctl option with name "socket_client" is created.
65030+
65031+config GRKERNSEC_SOCKET_CLIENT_GID
65032+ int "GID to deny client sockets for"
65033+ depends on GRKERNSEC_SOCKET_CLIENT
65034+ default 1003
65035+ help
65036+ Here you can choose the GID to disable client socket access for.
65037+ Remember to add the users you want client socket access disabled for to
65038+ the GID specified here. If the sysctl option is enabled, a sysctl
65039+ option with name "socket_client_gid" is created.
65040+
65041+config GRKERNSEC_SOCKET_SERVER
65042+ bool "Deny server sockets to group"
65043+ depends on GRKERNSEC_SOCKET
65044+ help
65045+ If you say Y here, you will be able to choose a GID of whose users will
65046+ be unable to run server applications from your machine. If the sysctl
65047+ option is enabled, a sysctl option with name "socket_server" is created.
65048+
65049+config GRKERNSEC_SOCKET_SERVER_GID
65050+ int "GID to deny server sockets for"
65051+ depends on GRKERNSEC_SOCKET_SERVER
65052+ default 1002
65053+ help
65054+ Here you can choose the GID to disable server socket access for.
65055+ Remember to add the users you want server socket access disabled for to
65056+ the GID specified here. If the sysctl option is enabled, a sysctl
65057+ option with name "socket_server_gid" is created.
65058+
65059+endmenu
65060+
65061+menu "Physical Protections"
65062+depends on GRKERNSEC
65063+
65064+config GRKERNSEC_DENYUSB
65065+ bool "Deny new USB connections after toggle"
65066+ default y if GRKERNSEC_CONFIG_AUTO
65067+ depends on SYSCTL && USB_SUPPORT
65068+ help
65069+ If you say Y here, a new sysctl option with name "deny_new_usb"
65070+ will be created. Setting its value to 1 will prevent any new
65071+ USB devices from being recognized by the OS. Any attempted USB
65072+ device insertion will be logged. This option is intended to be
65073+ used against custom USB devices designed to exploit vulnerabilities
65074+ in various USB device drivers.
65075+
65076+ For greatest effectiveness, this sysctl should be set after any
65077+ relevant init scripts. This option is safe to enable in distros
65078+ as each user can choose whether or not to toggle the sysctl.
65079+
65080+config GRKERNSEC_DENYUSB_FORCE
65081+ bool "Reject all USB devices not connected at boot"
65082+ select USB
65083+ depends on GRKERNSEC_DENYUSB
65084+ help
65085+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
65086+ that doesn't involve a sysctl entry. This option should only be
65087+ enabled if you're sure you want to deny all new USB connections
65088+ at runtime and don't want to modify init scripts. This should not
65089+ be enabled by distros. It forces the core USB code to be built
65090+ into the kernel image so that all devices connected at boot time
65091+ can be recognized and new USB device connections can be prevented
65092+ prior to init running.
65093+
65094+endmenu
65095+
65096+menu "Sysctl Support"
65097+depends on GRKERNSEC && SYSCTL
65098+
65099+config GRKERNSEC_SYSCTL
65100+ bool "Sysctl support"
65101+ default y if GRKERNSEC_CONFIG_AUTO
65102+ help
65103+ If you say Y here, you will be able to change the options that
65104+ grsecurity runs with at bootup, without having to recompile your
65105+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
65106+ to enable (1) or disable (0) various features. All the sysctl entries
65107+ are mutable until the "grsec_lock" entry is set to a non-zero value.
65108+ All features enabled in the kernel configuration are disabled at boot
65109+ if you do not say Y to the "Turn on features by default" option.
65110+ All options should be set at startup, and the grsec_lock entry should
65111+ be set to a non-zero value after all the options are set.
65112+ *THIS IS EXTREMELY IMPORTANT*
65113+
65114+config GRKERNSEC_SYSCTL_DISTRO
65115+ bool "Extra sysctl support for distro makers (READ HELP)"
65116+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
65117+ help
65118+ If you say Y here, additional sysctl options will be created
65119+ for features that affect processes running as root. Therefore,
65120+ it is critical when using this option that the grsec_lock entry be
65121+ enabled after boot. Only distros with prebuilt kernel packages
65122+ with this option enabled that can ensure grsec_lock is enabled
65123+ after boot should use this option.
65124+ *Failure to set grsec_lock after boot makes all grsec features
65125+ this option covers useless*
65126+
65127+ Currently this option creates the following sysctl entries:
65128+ "Disable Privileged I/O": "disable_priv_io"
65129+
65130+config GRKERNSEC_SYSCTL_ON
65131+ bool "Turn on features by default"
65132+ default y if GRKERNSEC_CONFIG_AUTO
65133+ depends on GRKERNSEC_SYSCTL
65134+ help
65135+ If you say Y here, instead of having all features enabled in the
65136+ kernel configuration disabled at boot time, the features will be
65137+ enabled at boot time. It is recommended you say Y here unless
65138+ there is some reason you would want all sysctl-tunable features to
65139+ be disabled by default. As mentioned elsewhere, it is important
65140+ to enable the grsec_lock entry once you have finished modifying
65141+ the sysctl entries.
65142+
65143+endmenu
65144+menu "Logging Options"
65145+depends on GRKERNSEC
65146+
65147+config GRKERNSEC_FLOODTIME
65148+ int "Seconds in between log messages (minimum)"
65149+ default 10
65150+ help
65151+ This option allows you to enforce the number of seconds between
65152+ grsecurity log messages. The default should be suitable for most
65153+ people, however, if you choose to change it, choose a value small enough
65154+ to allow informative logs to be produced, but large enough to
65155+ prevent flooding.
65156+
65157+config GRKERNSEC_FLOODBURST
65158+ int "Number of messages in a burst (maximum)"
65159+ default 6
65160+ help
65161+ This option allows you to choose the maximum number of messages allowed
65162+ within the flood time interval you chose in a separate option. The
65163+ default should be suitable for most people, however if you find that
65164+ many of your logs are being interpreted as flooding, you may want to
65165+ raise this value.
65166+
65167+endmenu
65168diff --git a/grsecurity/Makefile b/grsecurity/Makefile
65169new file mode 100644
65170index 0000000..d1344d2
65171--- /dev/null
65172+++ b/grsecurity/Makefile
65173@@ -0,0 +1,43 @@
65174+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
65175+# during 2001-2009 it has been completely redesigned by Brad Spengler
65176+# into an RBAC system
65177+#
65178+# All code in this directory and various hooks inserted throughout the kernel
65179+# are copyright Brad Spengler - Open Source Security, Inc., and released
65180+# under the GPL v2
65181+
65182+KBUILD_CFLAGS += -Werror
65183+
65184+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
65185+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
65186+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
65187+ grsec_usb.o grsec_ipc.o
65188+
65189+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
65190+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
65191+ gracl_learn.o grsec_log.o gracl_policy.o
65192+ifdef CONFIG_COMPAT
65193+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
65194+endif
65195+
65196+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
65197+
65198+ifdef CONFIG_NET
65199+obj-y += grsec_sock.o
65200+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
65201+endif
65202+
65203+ifndef CONFIG_GRKERNSEC
65204+obj-y += grsec_disabled.o
65205+endif
65206+
65207+ifdef CONFIG_GRKERNSEC_HIDESYM
65208+extra-y := grsec_hidesym.o
65209+$(obj)/grsec_hidesym.o:
65210+ @-chmod -f 500 /boot
65211+ @-chmod -f 500 /lib/modules
65212+ @-chmod -f 500 /lib64/modules
65213+ @-chmod -f 500 /lib32/modules
65214+ @-chmod -f 700 .
65215+ @echo ' grsec: protected kernel image paths'
65216+endif
65217diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
65218new file mode 100644
65219index 0000000..7232a45
65220--- /dev/null
65221+++ b/grsecurity/gracl.c
65222@@ -0,0 +1,2677 @@
65223+#include <linux/kernel.h>
65224+#include <linux/module.h>
65225+#include <linux/sched.h>
65226+#include <linux/mm.h>
65227+#include <linux/file.h>
65228+#include <linux/fs.h>
65229+#include <linux/namei.h>
65230+#include <linux/mount.h>
65231+#include <linux/tty.h>
65232+#include <linux/proc_fs.h>
65233+#include <linux/lglock.h>
65234+#include <linux/slab.h>
65235+#include <linux/vmalloc.h>
65236+#include <linux/types.h>
65237+#include <linux/sysctl.h>
65238+#include <linux/netdevice.h>
65239+#include <linux/ptrace.h>
65240+#include <linux/gracl.h>
65241+#include <linux/gralloc.h>
65242+#include <linux/security.h>
65243+#include <linux/grinternal.h>
65244+#include <linux/pid_namespace.h>
65245+#include <linux/stop_machine.h>
65246+#include <linux/fdtable.h>
65247+#include <linux/percpu.h>
65248+#include <linux/lglock.h>
65249+#include <linux/hugetlb.h>
65250+#include <linux/posix-timers.h>
65251+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65252+#include <linux/magic.h>
65253+#include <linux/pagemap.h>
65254+#include "../fs/btrfs/async-thread.h"
65255+#include "../fs/btrfs/ctree.h"
65256+#include "../fs/btrfs/btrfs_inode.h"
65257+#endif
65258+#include "../fs/mount.h"
65259+
65260+#include <asm/uaccess.h>
65261+#include <asm/errno.h>
65262+#include <asm/mman.h>
65263+
65264+#define FOR_EACH_ROLE_START(role) \
65265+ role = running_polstate.role_list; \
65266+ while (role) {
65267+
65268+#define FOR_EACH_ROLE_END(role) \
65269+ role = role->prev; \
65270+ }
65271+
65272+extern struct path gr_real_root;
65273+
65274+static struct gr_policy_state running_polstate;
65275+struct gr_policy_state *polstate = &running_polstate;
65276+extern struct gr_alloc_state *current_alloc_state;
65277+
65278+extern char *gr_shared_page[4];
65279+DEFINE_RWLOCK(gr_inode_lock);
65280+
65281+static unsigned int gr_status __read_only = GR_STATUS_INIT;
65282+
65283+#ifdef CONFIG_NET
65284+extern struct vfsmount *sock_mnt;
65285+#endif
65286+
65287+extern struct vfsmount *pipe_mnt;
65288+extern struct vfsmount *shm_mnt;
65289+
65290+#ifdef CONFIG_HUGETLBFS
65291+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65292+#endif
65293+
65294+extern u16 acl_sp_role_value;
65295+extern struct acl_object_label *fakefs_obj_rw;
65296+extern struct acl_object_label *fakefs_obj_rwx;
65297+
65298+int gr_acl_is_enabled(void)
65299+{
65300+ return (gr_status & GR_READY);
65301+}
65302+
65303+void gr_enable_rbac_system(void)
65304+{
65305+ pax_open_kernel();
65306+ gr_status |= GR_READY;
65307+ pax_close_kernel();
65308+}
65309+
65310+int gr_rbac_disable(void *unused)
65311+{
65312+ pax_open_kernel();
65313+ gr_status &= ~GR_READY;
65314+ pax_close_kernel();
65315+
65316+ return 0;
65317+}
65318+
65319+static inline dev_t __get_dev(const struct dentry *dentry)
65320+{
65321+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65322+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
65323+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
65324+ else
65325+#endif
65326+ return dentry->d_sb->s_dev;
65327+}
65328+
65329+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65330+{
65331+ return __get_dev(dentry);
65332+}
65333+
65334+static char gr_task_roletype_to_char(struct task_struct *task)
65335+{
65336+ switch (task->role->roletype &
65337+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
65338+ GR_ROLE_SPECIAL)) {
65339+ case GR_ROLE_DEFAULT:
65340+ return 'D';
65341+ case GR_ROLE_USER:
65342+ return 'U';
65343+ case GR_ROLE_GROUP:
65344+ return 'G';
65345+ case GR_ROLE_SPECIAL:
65346+ return 'S';
65347+ }
65348+
65349+ return 'X';
65350+}
65351+
65352+char gr_roletype_to_char(void)
65353+{
65354+ return gr_task_roletype_to_char(current);
65355+}
65356+
65357+__inline__ int
65358+gr_acl_tpe_check(void)
65359+{
65360+ if (unlikely(!(gr_status & GR_READY)))
65361+ return 0;
65362+ if (current->role->roletype & GR_ROLE_TPE)
65363+ return 1;
65364+ else
65365+ return 0;
65366+}
65367+
65368+int
65369+gr_handle_rawio(const struct inode *inode)
65370+{
65371+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65372+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
65373+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
65374+ !capable(CAP_SYS_RAWIO))
65375+ return 1;
65376+#endif
65377+ return 0;
65378+}
65379+
65380+int
65381+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
65382+{
65383+ if (likely(lena != lenb))
65384+ return 0;
65385+
65386+ return !memcmp(a, b, lena);
65387+}
65388+
65389+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
65390+{
65391+ *buflen -= namelen;
65392+ if (*buflen < 0)
65393+ return -ENAMETOOLONG;
65394+ *buffer -= namelen;
65395+ memcpy(*buffer, str, namelen);
65396+ return 0;
65397+}
65398+
65399+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
65400+{
65401+ return prepend(buffer, buflen, name->name, name->len);
65402+}
65403+
65404+static int prepend_path(const struct path *path, struct path *root,
65405+ char **buffer, int *buflen)
65406+{
65407+ struct dentry *dentry = path->dentry;
65408+ struct vfsmount *vfsmnt = path->mnt;
65409+ struct mount *mnt = real_mount(vfsmnt);
65410+ bool slash = false;
65411+ int error = 0;
65412+
65413+ while (dentry != root->dentry || vfsmnt != root->mnt) {
65414+ struct dentry * parent;
65415+
65416+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
65417+ /* Global root? */
65418+ if (!mnt_has_parent(mnt)) {
65419+ goto out;
65420+ }
65421+ dentry = mnt->mnt_mountpoint;
65422+ mnt = mnt->mnt_parent;
65423+ vfsmnt = &mnt->mnt;
65424+ continue;
65425+ }
65426+ parent = dentry->d_parent;
65427+ prefetch(parent);
65428+ spin_lock(&dentry->d_lock);
65429+ error = prepend_name(buffer, buflen, &dentry->d_name);
65430+ spin_unlock(&dentry->d_lock);
65431+ if (!error)
65432+ error = prepend(buffer, buflen, "/", 1);
65433+ if (error)
65434+ break;
65435+
65436+ slash = true;
65437+ dentry = parent;
65438+ }
65439+
65440+out:
65441+ if (!error && !slash)
65442+ error = prepend(buffer, buflen, "/", 1);
65443+
65444+ return error;
65445+}
65446+
65447+/* this must be called with mount_lock and rename_lock held */
65448+
65449+static char *__our_d_path(const struct path *path, struct path *root,
65450+ char *buf, int buflen)
65451+{
65452+ char *res = buf + buflen;
65453+ int error;
65454+
65455+ prepend(&res, &buflen, "\0", 1);
65456+ error = prepend_path(path, root, &res, &buflen);
65457+ if (error)
65458+ return ERR_PTR(error);
65459+
65460+ return res;
65461+}
65462+
65463+static char *
65464+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
65465+{
65466+ char *retval;
65467+
65468+ retval = __our_d_path(path, root, buf, buflen);
65469+ if (unlikely(IS_ERR(retval)))
65470+ retval = strcpy(buf, "<path too long>");
65471+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
65472+ retval[1] = '\0';
65473+
65474+ return retval;
65475+}
65476+
65477+static char *
65478+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65479+ char *buf, int buflen)
65480+{
65481+ struct path path;
65482+ char *res;
65483+
65484+ path.dentry = (struct dentry *)dentry;
65485+ path.mnt = (struct vfsmount *)vfsmnt;
65486+
65487+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
65488+ by the RBAC system */
65489+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
65490+
65491+ return res;
65492+}
65493+
65494+static char *
65495+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65496+ char *buf, int buflen)
65497+{
65498+ char *res;
65499+ struct path path;
65500+ struct path root;
65501+ struct task_struct *reaper = init_pid_ns.child_reaper;
65502+
65503+ path.dentry = (struct dentry *)dentry;
65504+ path.mnt = (struct vfsmount *)vfsmnt;
65505+
65506+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
65507+ get_fs_root(reaper->fs, &root);
65508+
65509+ read_seqlock_excl(&mount_lock);
65510+ write_seqlock(&rename_lock);
65511+ res = gen_full_path(&path, &root, buf, buflen);
65512+ write_sequnlock(&rename_lock);
65513+ read_sequnlock_excl(&mount_lock);
65514+
65515+ path_put(&root);
65516+ return res;
65517+}
65518+
65519+char *
65520+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65521+{
65522+ char *ret;
65523+ read_seqlock_excl(&mount_lock);
65524+ write_seqlock(&rename_lock);
65525+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65526+ PAGE_SIZE);
65527+ write_sequnlock(&rename_lock);
65528+ read_sequnlock_excl(&mount_lock);
65529+ return ret;
65530+}
65531+
65532+static char *
65533+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65534+{
65535+ char *ret;
65536+ char *buf;
65537+ int buflen;
65538+
65539+ read_seqlock_excl(&mount_lock);
65540+ write_seqlock(&rename_lock);
65541+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
65542+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
65543+ buflen = (int)(ret - buf);
65544+ if (buflen >= 5)
65545+ prepend(&ret, &buflen, "/proc", 5);
65546+ else
65547+ ret = strcpy(buf, "<path too long>");
65548+ write_sequnlock(&rename_lock);
65549+ read_sequnlock_excl(&mount_lock);
65550+ return ret;
65551+}
65552+
65553+char *
65554+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
65555+{
65556+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65557+ PAGE_SIZE);
65558+}
65559+
65560+char *
65561+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
65562+{
65563+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65564+ PAGE_SIZE);
65565+}
65566+
65567+char *
65568+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
65569+{
65570+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
65571+ PAGE_SIZE);
65572+}
65573+
65574+char *
65575+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
65576+{
65577+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
65578+ PAGE_SIZE);
65579+}
65580+
65581+char *
65582+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
65583+{
65584+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
65585+ PAGE_SIZE);
65586+}
65587+
65588+__inline__ __u32
65589+to_gr_audit(const __u32 reqmode)
65590+{
65591+ /* masks off auditable permission flags, then shifts them to create
65592+ auditing flags, and adds the special case of append auditing if
65593+ we're requesting write */
65594+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
65595+}
65596+
65597+struct acl_role_label *
65598+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
65599+ const gid_t gid)
65600+{
65601+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
65602+ struct acl_role_label *match;
65603+ struct role_allowed_ip *ipp;
65604+ unsigned int x;
65605+ u32 curr_ip = task->signal->saved_ip;
65606+
65607+ match = state->acl_role_set.r_hash[index];
65608+
65609+ while (match) {
65610+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
65611+ for (x = 0; x < match->domain_child_num; x++) {
65612+ if (match->domain_children[x] == uid)
65613+ goto found;
65614+ }
65615+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
65616+ break;
65617+ match = match->next;
65618+ }
65619+found:
65620+ if (match == NULL) {
65621+ try_group:
65622+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
65623+ match = state->acl_role_set.r_hash[index];
65624+
65625+ while (match) {
65626+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
65627+ for (x = 0; x < match->domain_child_num; x++) {
65628+ if (match->domain_children[x] == gid)
65629+ goto found2;
65630+ }
65631+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
65632+ break;
65633+ match = match->next;
65634+ }
65635+found2:
65636+ if (match == NULL)
65637+ match = state->default_role;
65638+ if (match->allowed_ips == NULL)
65639+ return match;
65640+ else {
65641+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65642+ if (likely
65643+ ((ntohl(curr_ip) & ipp->netmask) ==
65644+ (ntohl(ipp->addr) & ipp->netmask)))
65645+ return match;
65646+ }
65647+ match = state->default_role;
65648+ }
65649+ } else if (match->allowed_ips == NULL) {
65650+ return match;
65651+ } else {
65652+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65653+ if (likely
65654+ ((ntohl(curr_ip) & ipp->netmask) ==
65655+ (ntohl(ipp->addr) & ipp->netmask)))
65656+ return match;
65657+ }
65658+ goto try_group;
65659+ }
65660+
65661+ return match;
65662+}
65663+
65664+static struct acl_role_label *
65665+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
65666+ const gid_t gid)
65667+{
65668+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
65669+}
65670+
65671+struct acl_subject_label *
65672+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
65673+ const struct acl_role_label *role)
65674+{
65675+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65676+ struct acl_subject_label *match;
65677+
65678+ match = role->subj_hash[index];
65679+
65680+ while (match && (match->inode != ino || match->device != dev ||
65681+ (match->mode & GR_DELETED))) {
65682+ match = match->next;
65683+ }
65684+
65685+ if (match && !(match->mode & GR_DELETED))
65686+ return match;
65687+ else
65688+ return NULL;
65689+}
65690+
65691+struct acl_subject_label *
65692+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
65693+ const struct acl_role_label *role)
65694+{
65695+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65696+ struct acl_subject_label *match;
65697+
65698+ match = role->subj_hash[index];
65699+
65700+ while (match && (match->inode != ino || match->device != dev ||
65701+ !(match->mode & GR_DELETED))) {
65702+ match = match->next;
65703+ }
65704+
65705+ if (match && (match->mode & GR_DELETED))
65706+ return match;
65707+ else
65708+ return NULL;
65709+}
65710+
65711+static struct acl_object_label *
65712+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
65713+ const struct acl_subject_label *subj)
65714+{
65715+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65716+ struct acl_object_label *match;
65717+
65718+ match = subj->obj_hash[index];
65719+
65720+ while (match && (match->inode != ino || match->device != dev ||
65721+ (match->mode & GR_DELETED))) {
65722+ match = match->next;
65723+ }
65724+
65725+ if (match && !(match->mode & GR_DELETED))
65726+ return match;
65727+ else
65728+ return NULL;
65729+}
65730+
65731+static struct acl_object_label *
65732+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
65733+ const struct acl_subject_label *subj)
65734+{
65735+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65736+ struct acl_object_label *match;
65737+
65738+ match = subj->obj_hash[index];
65739+
65740+ while (match && (match->inode != ino || match->device != dev ||
65741+ !(match->mode & GR_DELETED))) {
65742+ match = match->next;
65743+ }
65744+
65745+ if (match && (match->mode & GR_DELETED))
65746+ return match;
65747+
65748+ match = subj->obj_hash[index];
65749+
65750+ while (match && (match->inode != ino || match->device != dev ||
65751+ (match->mode & GR_DELETED))) {
65752+ match = match->next;
65753+ }
65754+
65755+ if (match && !(match->mode & GR_DELETED))
65756+ return match;
65757+ else
65758+ return NULL;
65759+}
65760+
65761+struct name_entry *
65762+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
65763+{
65764+ unsigned int len = strlen(name);
65765+ unsigned int key = full_name_hash(name, len);
65766+ unsigned int index = key % state->name_set.n_size;
65767+ struct name_entry *match;
65768+
65769+ match = state->name_set.n_hash[index];
65770+
65771+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
65772+ match = match->next;
65773+
65774+ return match;
65775+}
65776+
65777+static struct name_entry *
65778+lookup_name_entry(const char *name)
65779+{
65780+ return __lookup_name_entry(&running_polstate, name);
65781+}
65782+
65783+static struct name_entry *
65784+lookup_name_entry_create(const char *name)
65785+{
65786+ unsigned int len = strlen(name);
65787+ unsigned int key = full_name_hash(name, len);
65788+ unsigned int index = key % running_polstate.name_set.n_size;
65789+ struct name_entry *match;
65790+
65791+ match = running_polstate.name_set.n_hash[index];
65792+
65793+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65794+ !match->deleted))
65795+ match = match->next;
65796+
65797+ if (match && match->deleted)
65798+ return match;
65799+
65800+ match = running_polstate.name_set.n_hash[index];
65801+
65802+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65803+ match->deleted))
65804+ match = match->next;
65805+
65806+ if (match && !match->deleted)
65807+ return match;
65808+ else
65809+ return NULL;
65810+}
65811+
65812+static struct inodev_entry *
65813+lookup_inodev_entry(const ino_t ino, const dev_t dev)
65814+{
65815+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
65816+ struct inodev_entry *match;
65817+
65818+ match = running_polstate.inodev_set.i_hash[index];
65819+
65820+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
65821+ match = match->next;
65822+
65823+ return match;
65824+}
65825+
65826+void
65827+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
65828+{
65829+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
65830+ state->inodev_set.i_size);
65831+ struct inodev_entry **curr;
65832+
65833+ entry->prev = NULL;
65834+
65835+ curr = &state->inodev_set.i_hash[index];
65836+ if (*curr != NULL)
65837+ (*curr)->prev = entry;
65838+
65839+ entry->next = *curr;
65840+ *curr = entry;
65841+
65842+ return;
65843+}
65844+
65845+static void
65846+insert_inodev_entry(struct inodev_entry *entry)
65847+{
65848+ __insert_inodev_entry(&running_polstate, entry);
65849+}
65850+
65851+void
65852+insert_acl_obj_label(struct acl_object_label *obj,
65853+ struct acl_subject_label *subj)
65854+{
65855+ unsigned int index =
65856+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
65857+ struct acl_object_label **curr;
65858+
65859+ obj->prev = NULL;
65860+
65861+ curr = &subj->obj_hash[index];
65862+ if (*curr != NULL)
65863+ (*curr)->prev = obj;
65864+
65865+ obj->next = *curr;
65866+ *curr = obj;
65867+
65868+ return;
65869+}
65870+
65871+void
65872+insert_acl_subj_label(struct acl_subject_label *obj,
65873+ struct acl_role_label *role)
65874+{
65875+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
65876+ struct acl_subject_label **curr;
65877+
65878+ obj->prev = NULL;
65879+
65880+ curr = &role->subj_hash[index];
65881+ if (*curr != NULL)
65882+ (*curr)->prev = obj;
65883+
65884+ obj->next = *curr;
65885+ *curr = obj;
65886+
65887+ return;
65888+}
65889+
65890+/* derived from glibc fnmatch() 0: match, 1: no match*/
65891+
65892+static int
65893+glob_match(const char *p, const char *n)
65894+{
65895+ char c;
65896+
65897+ while ((c = *p++) != '\0') {
65898+ switch (c) {
65899+ case '?':
65900+ if (*n == '\0')
65901+ return 1;
65902+ else if (*n == '/')
65903+ return 1;
65904+ break;
65905+ case '\\':
65906+ if (*n != c)
65907+ return 1;
65908+ break;
65909+ case '*':
65910+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
65911+ if (*n == '/')
65912+ return 1;
65913+ else if (c == '?') {
65914+ if (*n == '\0')
65915+ return 1;
65916+ else
65917+ ++n;
65918+ }
65919+ }
65920+ if (c == '\0') {
65921+ return 0;
65922+ } else {
65923+ const char *endp;
65924+
65925+ if ((endp = strchr(n, '/')) == NULL)
65926+ endp = n + strlen(n);
65927+
65928+ if (c == '[') {
65929+ for (--p; n < endp; ++n)
65930+ if (!glob_match(p, n))
65931+ return 0;
65932+ } else if (c == '/') {
65933+ while (*n != '\0' && *n != '/')
65934+ ++n;
65935+ if (*n == '/' && !glob_match(p, n + 1))
65936+ return 0;
65937+ } else {
65938+ for (--p; n < endp; ++n)
65939+ if (*n == c && !glob_match(p, n))
65940+ return 0;
65941+ }
65942+
65943+ return 1;
65944+ }
65945+ case '[':
65946+ {
65947+ int not;
65948+ char cold;
65949+
65950+ if (*n == '\0' || *n == '/')
65951+ return 1;
65952+
65953+ not = (*p == '!' || *p == '^');
65954+ if (not)
65955+ ++p;
65956+
65957+ c = *p++;
65958+ for (;;) {
65959+ unsigned char fn = (unsigned char)*n;
65960+
65961+ if (c == '\0')
65962+ return 1;
65963+ else {
65964+ if (c == fn)
65965+ goto matched;
65966+ cold = c;
65967+ c = *p++;
65968+
65969+ if (c == '-' && *p != ']') {
65970+ unsigned char cend = *p++;
65971+
65972+ if (cend == '\0')
65973+ return 1;
65974+
65975+ if (cold <= fn && fn <= cend)
65976+ goto matched;
65977+
65978+ c = *p++;
65979+ }
65980+ }
65981+
65982+ if (c == ']')
65983+ break;
65984+ }
65985+ if (!not)
65986+ return 1;
65987+ break;
65988+ matched:
65989+ while (c != ']') {
65990+ if (c == '\0')
65991+ return 1;
65992+
65993+ c = *p++;
65994+ }
65995+ if (not)
65996+ return 1;
65997+ }
65998+ break;
65999+ default:
66000+ if (c != *n)
66001+ return 1;
66002+ }
66003+
66004+ ++n;
66005+ }
66006+
66007+ if (*n == '\0')
66008+ return 0;
66009+
66010+ if (*n == '/')
66011+ return 0;
66012+
66013+ return 1;
66014+}
66015+
66016+static struct acl_object_label *
66017+chk_glob_label(struct acl_object_label *globbed,
66018+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
66019+{
66020+ struct acl_object_label *tmp;
66021+
66022+ if (*path == NULL)
66023+ *path = gr_to_filename_nolock(dentry, mnt);
66024+
66025+ tmp = globbed;
66026+
66027+ while (tmp) {
66028+ if (!glob_match(tmp->filename, *path))
66029+ return tmp;
66030+ tmp = tmp->next;
66031+ }
66032+
66033+ return NULL;
66034+}
66035+
66036+static struct acl_object_label *
66037+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66038+ const ino_t curr_ino, const dev_t curr_dev,
66039+ const struct acl_subject_label *subj, char **path, const int checkglob)
66040+{
66041+ struct acl_subject_label *tmpsubj;
66042+ struct acl_object_label *retval;
66043+ struct acl_object_label *retval2;
66044+
66045+ tmpsubj = (struct acl_subject_label *) subj;
66046+ read_lock(&gr_inode_lock);
66047+ do {
66048+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
66049+ if (retval) {
66050+ if (checkglob && retval->globbed) {
66051+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
66052+ if (retval2)
66053+ retval = retval2;
66054+ }
66055+ break;
66056+ }
66057+ } while ((tmpsubj = tmpsubj->parent_subject));
66058+ read_unlock(&gr_inode_lock);
66059+
66060+ return retval;
66061+}
66062+
66063+static __inline__ struct acl_object_label *
66064+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66065+ struct dentry *curr_dentry,
66066+ const struct acl_subject_label *subj, char **path, const int checkglob)
66067+{
66068+ int newglob = checkglob;
66069+ ino_t inode;
66070+ dev_t device;
66071+
66072+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
66073+ as we don't want a / * rule to match instead of the / object
66074+ don't do this for create lookups that call this function though, since they're looking up
66075+ on the parent and thus need globbing checks on all paths
66076+ */
66077+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
66078+ newglob = GR_NO_GLOB;
66079+
66080+ spin_lock(&curr_dentry->d_lock);
66081+ inode = curr_dentry->d_inode->i_ino;
66082+ device = __get_dev(curr_dentry);
66083+ spin_unlock(&curr_dentry->d_lock);
66084+
66085+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
66086+}
66087+
66088+#ifdef CONFIG_HUGETLBFS
66089+static inline bool
66090+is_hugetlbfs_mnt(const struct vfsmount *mnt)
66091+{
66092+ int i;
66093+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
66094+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
66095+ return true;
66096+ }
66097+
66098+ return false;
66099+}
66100+#endif
66101+
66102+static struct acl_object_label *
66103+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66104+ const struct acl_subject_label *subj, char *path, const int checkglob)
66105+{
66106+ struct dentry *dentry = (struct dentry *) l_dentry;
66107+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66108+ struct mount *real_mnt = real_mount(mnt);
66109+ struct acl_object_label *retval;
66110+ struct dentry *parent;
66111+
66112+ read_seqlock_excl(&mount_lock);
66113+ write_seqlock(&rename_lock);
66114+
66115+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
66116+#ifdef CONFIG_NET
66117+ mnt == sock_mnt ||
66118+#endif
66119+#ifdef CONFIG_HUGETLBFS
66120+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
66121+#endif
66122+ /* ignore Eric Biederman */
66123+ IS_PRIVATE(l_dentry->d_inode))) {
66124+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
66125+ goto out;
66126+ }
66127+
66128+ for (;;) {
66129+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66130+ break;
66131+
66132+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66133+ if (!mnt_has_parent(real_mnt))
66134+ break;
66135+
66136+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66137+ if (retval != NULL)
66138+ goto out;
66139+
66140+ dentry = real_mnt->mnt_mountpoint;
66141+ real_mnt = real_mnt->mnt_parent;
66142+ mnt = &real_mnt->mnt;
66143+ continue;
66144+ }
66145+
66146+ parent = dentry->d_parent;
66147+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66148+ if (retval != NULL)
66149+ goto out;
66150+
66151+ dentry = parent;
66152+ }
66153+
66154+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66155+
66156+ /* gr_real_root is pinned so we don't have to hold a reference */
66157+ if (retval == NULL)
66158+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
66159+out:
66160+ write_sequnlock(&rename_lock);
66161+ read_sequnlock_excl(&mount_lock);
66162+
66163+ BUG_ON(retval == NULL);
66164+
66165+ return retval;
66166+}
66167+
66168+static __inline__ struct acl_object_label *
66169+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66170+ const struct acl_subject_label *subj)
66171+{
66172+ char *path = NULL;
66173+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
66174+}
66175+
66176+static __inline__ struct acl_object_label *
66177+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66178+ const struct acl_subject_label *subj)
66179+{
66180+ char *path = NULL;
66181+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
66182+}
66183+
66184+static __inline__ struct acl_object_label *
66185+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66186+ const struct acl_subject_label *subj, char *path)
66187+{
66188+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
66189+}
66190+
66191+struct acl_subject_label *
66192+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66193+ const struct acl_role_label *role)
66194+{
66195+ struct dentry *dentry = (struct dentry *) l_dentry;
66196+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66197+ struct mount *real_mnt = real_mount(mnt);
66198+ struct acl_subject_label *retval;
66199+ struct dentry *parent;
66200+
66201+ read_seqlock_excl(&mount_lock);
66202+ write_seqlock(&rename_lock);
66203+
66204+ for (;;) {
66205+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66206+ break;
66207+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66208+ if (!mnt_has_parent(real_mnt))
66209+ break;
66210+
66211+ spin_lock(&dentry->d_lock);
66212+ read_lock(&gr_inode_lock);
66213+ retval =
66214+ lookup_acl_subj_label(dentry->d_inode->i_ino,
66215+ __get_dev(dentry), role);
66216+ read_unlock(&gr_inode_lock);
66217+ spin_unlock(&dentry->d_lock);
66218+ if (retval != NULL)
66219+ goto out;
66220+
66221+ dentry = real_mnt->mnt_mountpoint;
66222+ real_mnt = real_mnt->mnt_parent;
66223+ mnt = &real_mnt->mnt;
66224+ continue;
66225+ }
66226+
66227+ spin_lock(&dentry->d_lock);
66228+ read_lock(&gr_inode_lock);
66229+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66230+ __get_dev(dentry), role);
66231+ read_unlock(&gr_inode_lock);
66232+ parent = dentry->d_parent;
66233+ spin_unlock(&dentry->d_lock);
66234+
66235+ if (retval != NULL)
66236+ goto out;
66237+
66238+ dentry = parent;
66239+ }
66240+
66241+ spin_lock(&dentry->d_lock);
66242+ read_lock(&gr_inode_lock);
66243+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66244+ __get_dev(dentry), role);
66245+ read_unlock(&gr_inode_lock);
66246+ spin_unlock(&dentry->d_lock);
66247+
66248+ if (unlikely(retval == NULL)) {
66249+ /* gr_real_root is pinned, we don't need to hold a reference */
66250+ read_lock(&gr_inode_lock);
66251+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
66252+ __get_dev(gr_real_root.dentry), role);
66253+ read_unlock(&gr_inode_lock);
66254+ }
66255+out:
66256+ write_sequnlock(&rename_lock);
66257+ read_sequnlock_excl(&mount_lock);
66258+
66259+ BUG_ON(retval == NULL);
66260+
66261+ return retval;
66262+}
66263+
66264+void
66265+assign_special_role(const char *rolename)
66266+{
66267+ struct acl_object_label *obj;
66268+ struct acl_role_label *r;
66269+ struct acl_role_label *assigned = NULL;
66270+ struct task_struct *tsk;
66271+ struct file *filp;
66272+
66273+ FOR_EACH_ROLE_START(r)
66274+ if (!strcmp(rolename, r->rolename) &&
66275+ (r->roletype & GR_ROLE_SPECIAL)) {
66276+ assigned = r;
66277+ break;
66278+ }
66279+ FOR_EACH_ROLE_END(r)
66280+
66281+ if (!assigned)
66282+ return;
66283+
66284+ read_lock(&tasklist_lock);
66285+ read_lock(&grsec_exec_file_lock);
66286+
66287+ tsk = current->real_parent;
66288+ if (tsk == NULL)
66289+ goto out_unlock;
66290+
66291+ filp = tsk->exec_file;
66292+ if (filp == NULL)
66293+ goto out_unlock;
66294+
66295+ tsk->is_writable = 0;
66296+ tsk->inherited = 0;
66297+
66298+ tsk->acl_sp_role = 1;
66299+ tsk->acl_role_id = ++acl_sp_role_value;
66300+ tsk->role = assigned;
66301+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66302+
66303+ /* ignore additional mmap checks for processes that are writable
66304+ by the default ACL */
66305+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66306+ if (unlikely(obj->mode & GR_WRITE))
66307+ tsk->is_writable = 1;
66308+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66309+ if (unlikely(obj->mode & GR_WRITE))
66310+ tsk->is_writable = 1;
66311+
66312+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66313+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
66314+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
66315+#endif
66316+
66317+out_unlock:
66318+ read_unlock(&grsec_exec_file_lock);
66319+ read_unlock(&tasklist_lock);
66320+ return;
66321+}
66322+
66323+
66324+static void
66325+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
66326+{
66327+ struct task_struct *task = current;
66328+ const struct cred *cred = current_cred();
66329+
66330+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
66331+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66332+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66333+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
66334+
66335+ return;
66336+}
66337+
66338+static void
66339+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
66340+{
66341+ struct task_struct *task = current;
66342+ const struct cred *cred = current_cred();
66343+
66344+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66345+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66346+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66347+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
66348+
66349+ return;
66350+}
66351+
66352+static void
66353+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
66354+{
66355+ struct task_struct *task = current;
66356+ const struct cred *cred = current_cred();
66357+
66358+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66359+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66360+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66361+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
66362+
66363+ return;
66364+}
66365+
66366+static void
66367+gr_set_proc_res(struct task_struct *task)
66368+{
66369+ struct acl_subject_label *proc;
66370+ unsigned short i;
66371+
66372+ proc = task->acl;
66373+
66374+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
66375+ return;
66376+
66377+ for (i = 0; i < RLIM_NLIMITS; i++) {
66378+ if (!(proc->resmask & (1U << i)))
66379+ continue;
66380+
66381+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
66382+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
66383+
66384+ if (i == RLIMIT_CPU)
66385+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
66386+ }
66387+
66388+ return;
66389+}
66390+
66391+/* both of the below must be called with
66392+ rcu_read_lock();
66393+ read_lock(&tasklist_lock);
66394+ read_lock(&grsec_exec_file_lock);
66395+*/
66396+
66397+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
66398+{
66399+ char *tmpname;
66400+ struct acl_subject_label *tmpsubj;
66401+ struct file *filp;
66402+ struct name_entry *nmatch;
66403+
66404+ filp = task->exec_file;
66405+ if (filp == NULL)
66406+ return NULL;
66407+
66408+ /* the following is to apply the correct subject
66409+ on binaries running when the RBAC system
66410+ is enabled, when the binaries have been
66411+ replaced or deleted since their execution
66412+ -----
66413+ when the RBAC system starts, the inode/dev
66414+ from exec_file will be one the RBAC system
66415+ is unaware of. It only knows the inode/dev
66416+ of the present file on disk, or the absence
66417+ of it.
66418+ */
66419+
66420+ if (filename)
66421+ nmatch = __lookup_name_entry(state, filename);
66422+ else {
66423+ preempt_disable();
66424+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
66425+
66426+ nmatch = __lookup_name_entry(state, tmpname);
66427+ preempt_enable();
66428+ }
66429+ tmpsubj = NULL;
66430+ if (nmatch) {
66431+ if (nmatch->deleted)
66432+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
66433+ else
66434+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
66435+ }
66436+ /* this also works for the reload case -- if we don't match a potentially inherited subject
66437+ then we fall back to a normal lookup based on the binary's ino/dev
66438+ */
66439+ if (tmpsubj == NULL)
66440+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
66441+
66442+ return tmpsubj;
66443+}
66444+
66445+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
66446+{
66447+ return __gr_get_subject_for_task(&running_polstate, task, filename);
66448+}
66449+
66450+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
66451+{
66452+ struct acl_object_label *obj;
66453+ struct file *filp;
66454+
66455+ filp = task->exec_file;
66456+
66457+ task->acl = subj;
66458+ task->is_writable = 0;
66459+ /* ignore additional mmap checks for processes that are writable
66460+ by the default ACL */
66461+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
66462+ if (unlikely(obj->mode & GR_WRITE))
66463+ task->is_writable = 1;
66464+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66465+ if (unlikely(obj->mode & GR_WRITE))
66466+ task->is_writable = 1;
66467+
66468+ gr_set_proc_res(task);
66469+
66470+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66471+ 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);
66472+#endif
66473+}
66474+
66475+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
66476+{
66477+ __gr_apply_subject_to_task(&running_polstate, task, subj);
66478+}
66479+
66480+__u32
66481+gr_search_file(const struct dentry * dentry, const __u32 mode,
66482+ const struct vfsmount * mnt)
66483+{
66484+ __u32 retval = mode;
66485+ struct acl_subject_label *curracl;
66486+ struct acl_object_label *currobj;
66487+
66488+ if (unlikely(!(gr_status & GR_READY)))
66489+ return (mode & ~GR_AUDITS);
66490+
66491+ curracl = current->acl;
66492+
66493+ currobj = chk_obj_label(dentry, mnt, curracl);
66494+ retval = currobj->mode & mode;
66495+
66496+ /* if we're opening a specified transfer file for writing
66497+ (e.g. /dev/initctl), then transfer our role to init
66498+ */
66499+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
66500+ current->role->roletype & GR_ROLE_PERSIST)) {
66501+ struct task_struct *task = init_pid_ns.child_reaper;
66502+
66503+ if (task->role != current->role) {
66504+ struct acl_subject_label *subj;
66505+
66506+ task->acl_sp_role = 0;
66507+ task->acl_role_id = current->acl_role_id;
66508+ task->role = current->role;
66509+ rcu_read_lock();
66510+ read_lock(&grsec_exec_file_lock);
66511+ subj = gr_get_subject_for_task(task, NULL);
66512+ gr_apply_subject_to_task(task, subj);
66513+ read_unlock(&grsec_exec_file_lock);
66514+ rcu_read_unlock();
66515+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
66516+ }
66517+ }
66518+
66519+ if (unlikely
66520+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
66521+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
66522+ __u32 new_mode = mode;
66523+
66524+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66525+
66526+ retval = new_mode;
66527+
66528+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
66529+ new_mode |= GR_INHERIT;
66530+
66531+ if (!(mode & GR_NOLEARN))
66532+ gr_log_learn(dentry, mnt, new_mode);
66533+ }
66534+
66535+ return retval;
66536+}
66537+
66538+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
66539+ const struct dentry *parent,
66540+ const struct vfsmount *mnt)
66541+{
66542+ struct name_entry *match;
66543+ struct acl_object_label *matchpo;
66544+ struct acl_subject_label *curracl;
66545+ char *path;
66546+
66547+ if (unlikely(!(gr_status & GR_READY)))
66548+ return NULL;
66549+
66550+ preempt_disable();
66551+ path = gr_to_filename_rbac(new_dentry, mnt);
66552+ match = lookup_name_entry_create(path);
66553+
66554+ curracl = current->acl;
66555+
66556+ if (match) {
66557+ read_lock(&gr_inode_lock);
66558+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
66559+ read_unlock(&gr_inode_lock);
66560+
66561+ if (matchpo) {
66562+ preempt_enable();
66563+ return matchpo;
66564+ }
66565+ }
66566+
66567+ // lookup parent
66568+
66569+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
66570+
66571+ preempt_enable();
66572+ return matchpo;
66573+}
66574+
66575+__u32
66576+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
66577+ const struct vfsmount * mnt, const __u32 mode)
66578+{
66579+ struct acl_object_label *matchpo;
66580+ __u32 retval;
66581+
66582+ if (unlikely(!(gr_status & GR_READY)))
66583+ return (mode & ~GR_AUDITS);
66584+
66585+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
66586+
66587+ retval = matchpo->mode & mode;
66588+
66589+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
66590+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66591+ __u32 new_mode = mode;
66592+
66593+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66594+
66595+ gr_log_learn(new_dentry, mnt, new_mode);
66596+ return new_mode;
66597+ }
66598+
66599+ return retval;
66600+}
66601+
66602+__u32
66603+gr_check_link(const struct dentry * new_dentry,
66604+ const struct dentry * parent_dentry,
66605+ const struct vfsmount * parent_mnt,
66606+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
66607+{
66608+ struct acl_object_label *obj;
66609+ __u32 oldmode, newmode;
66610+ __u32 needmode;
66611+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
66612+ GR_DELETE | GR_INHERIT;
66613+
66614+ if (unlikely(!(gr_status & GR_READY)))
66615+ return (GR_CREATE | GR_LINK);
66616+
66617+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
66618+ oldmode = obj->mode;
66619+
66620+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
66621+ newmode = obj->mode;
66622+
66623+ needmode = newmode & checkmodes;
66624+
66625+ // old name for hardlink must have at least the permissions of the new name
66626+ if ((oldmode & needmode) != needmode)
66627+ goto bad;
66628+
66629+ // if old name had restrictions/auditing, make sure the new name does as well
66630+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
66631+
66632+ // don't allow hardlinking of suid/sgid/fcapped files without permission
66633+ if (is_privileged_binary(old_dentry))
66634+ needmode |= GR_SETID;
66635+
66636+ if ((newmode & needmode) != needmode)
66637+ goto bad;
66638+
66639+ // enforce minimum permissions
66640+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
66641+ return newmode;
66642+bad:
66643+ needmode = oldmode;
66644+ if (is_privileged_binary(old_dentry))
66645+ needmode |= GR_SETID;
66646+
66647+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
66648+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
66649+ return (GR_CREATE | GR_LINK);
66650+ } else if (newmode & GR_SUPPRESS)
66651+ return GR_SUPPRESS;
66652+ else
66653+ return 0;
66654+}
66655+
66656+int
66657+gr_check_hidden_task(const struct task_struct *task)
66658+{
66659+ if (unlikely(!(gr_status & GR_READY)))
66660+ return 0;
66661+
66662+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
66663+ return 1;
66664+
66665+ return 0;
66666+}
66667+
66668+int
66669+gr_check_protected_task(const struct task_struct *task)
66670+{
66671+ if (unlikely(!(gr_status & GR_READY) || !task))
66672+ return 0;
66673+
66674+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66675+ task->acl != current->acl)
66676+ return 1;
66677+
66678+ return 0;
66679+}
66680+
66681+int
66682+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
66683+{
66684+ struct task_struct *p;
66685+ int ret = 0;
66686+
66687+ if (unlikely(!(gr_status & GR_READY) || !pid))
66688+ return ret;
66689+
66690+ read_lock(&tasklist_lock);
66691+ do_each_pid_task(pid, type, p) {
66692+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66693+ p->acl != current->acl) {
66694+ ret = 1;
66695+ goto out;
66696+ }
66697+ } while_each_pid_task(pid, type, p);
66698+out:
66699+ read_unlock(&tasklist_lock);
66700+
66701+ return ret;
66702+}
66703+
66704+void
66705+gr_copy_label(struct task_struct *tsk)
66706+{
66707+ struct task_struct *p = current;
66708+
66709+ tsk->inherited = p->inherited;
66710+ tsk->acl_sp_role = 0;
66711+ tsk->acl_role_id = p->acl_role_id;
66712+ tsk->acl = p->acl;
66713+ tsk->role = p->role;
66714+ tsk->signal->used_accept = 0;
66715+ tsk->signal->curr_ip = p->signal->curr_ip;
66716+ tsk->signal->saved_ip = p->signal->saved_ip;
66717+ if (p->exec_file)
66718+ get_file(p->exec_file);
66719+ tsk->exec_file = p->exec_file;
66720+ tsk->is_writable = p->is_writable;
66721+ if (unlikely(p->signal->used_accept)) {
66722+ p->signal->curr_ip = 0;
66723+ p->signal->saved_ip = 0;
66724+ }
66725+
66726+ return;
66727+}
66728+
66729+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
66730+
66731+int
66732+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
66733+{
66734+ unsigned int i;
66735+ __u16 num;
66736+ uid_t *uidlist;
66737+ uid_t curuid;
66738+ int realok = 0;
66739+ int effectiveok = 0;
66740+ int fsok = 0;
66741+ uid_t globalreal, globaleffective, globalfs;
66742+
66743+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
66744+ struct user_struct *user;
66745+
66746+ if (!uid_valid(real))
66747+ goto skipit;
66748+
66749+ /* find user based on global namespace */
66750+
66751+ globalreal = GR_GLOBAL_UID(real);
66752+
66753+ user = find_user(make_kuid(&init_user_ns, globalreal));
66754+ if (user == NULL)
66755+ goto skipit;
66756+
66757+ if (gr_process_kernel_setuid_ban(user)) {
66758+ /* for find_user */
66759+ free_uid(user);
66760+ return 1;
66761+ }
66762+
66763+ /* for find_user */
66764+ free_uid(user);
66765+
66766+skipit:
66767+#endif
66768+
66769+ if (unlikely(!(gr_status & GR_READY)))
66770+ return 0;
66771+
66772+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66773+ gr_log_learn_uid_change(real, effective, fs);
66774+
66775+ num = current->acl->user_trans_num;
66776+ uidlist = current->acl->user_transitions;
66777+
66778+ if (uidlist == NULL)
66779+ return 0;
66780+
66781+ if (!uid_valid(real)) {
66782+ realok = 1;
66783+ globalreal = (uid_t)-1;
66784+ } else {
66785+ globalreal = GR_GLOBAL_UID(real);
66786+ }
66787+ if (!uid_valid(effective)) {
66788+ effectiveok = 1;
66789+ globaleffective = (uid_t)-1;
66790+ } else {
66791+ globaleffective = GR_GLOBAL_UID(effective);
66792+ }
66793+ if (!uid_valid(fs)) {
66794+ fsok = 1;
66795+ globalfs = (uid_t)-1;
66796+ } else {
66797+ globalfs = GR_GLOBAL_UID(fs);
66798+ }
66799+
66800+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
66801+ for (i = 0; i < num; i++) {
66802+ curuid = uidlist[i];
66803+ if (globalreal == curuid)
66804+ realok = 1;
66805+ if (globaleffective == curuid)
66806+ effectiveok = 1;
66807+ if (globalfs == curuid)
66808+ fsok = 1;
66809+ }
66810+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
66811+ for (i = 0; i < num; i++) {
66812+ curuid = uidlist[i];
66813+ if (globalreal == curuid)
66814+ break;
66815+ if (globaleffective == curuid)
66816+ break;
66817+ if (globalfs == curuid)
66818+ break;
66819+ }
66820+ /* not in deny list */
66821+ if (i == num) {
66822+ realok = 1;
66823+ effectiveok = 1;
66824+ fsok = 1;
66825+ }
66826+ }
66827+
66828+ if (realok && effectiveok && fsok)
66829+ return 0;
66830+ else {
66831+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
66832+ return 1;
66833+ }
66834+}
66835+
66836+int
66837+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
66838+{
66839+ unsigned int i;
66840+ __u16 num;
66841+ gid_t *gidlist;
66842+ gid_t curgid;
66843+ int realok = 0;
66844+ int effectiveok = 0;
66845+ int fsok = 0;
66846+ gid_t globalreal, globaleffective, globalfs;
66847+
66848+ if (unlikely(!(gr_status & GR_READY)))
66849+ return 0;
66850+
66851+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66852+ gr_log_learn_gid_change(real, effective, fs);
66853+
66854+ num = current->acl->group_trans_num;
66855+ gidlist = current->acl->group_transitions;
66856+
66857+ if (gidlist == NULL)
66858+ return 0;
66859+
66860+ if (!gid_valid(real)) {
66861+ realok = 1;
66862+ globalreal = (gid_t)-1;
66863+ } else {
66864+ globalreal = GR_GLOBAL_GID(real);
66865+ }
66866+ if (!gid_valid(effective)) {
66867+ effectiveok = 1;
66868+ globaleffective = (gid_t)-1;
66869+ } else {
66870+ globaleffective = GR_GLOBAL_GID(effective);
66871+ }
66872+ if (!gid_valid(fs)) {
66873+ fsok = 1;
66874+ globalfs = (gid_t)-1;
66875+ } else {
66876+ globalfs = GR_GLOBAL_GID(fs);
66877+ }
66878+
66879+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
66880+ for (i = 0; i < num; i++) {
66881+ curgid = gidlist[i];
66882+ if (globalreal == curgid)
66883+ realok = 1;
66884+ if (globaleffective == curgid)
66885+ effectiveok = 1;
66886+ if (globalfs == curgid)
66887+ fsok = 1;
66888+ }
66889+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
66890+ for (i = 0; i < num; i++) {
66891+ curgid = gidlist[i];
66892+ if (globalreal == curgid)
66893+ break;
66894+ if (globaleffective == curgid)
66895+ break;
66896+ if (globalfs == curgid)
66897+ break;
66898+ }
66899+ /* not in deny list */
66900+ if (i == num) {
66901+ realok = 1;
66902+ effectiveok = 1;
66903+ fsok = 1;
66904+ }
66905+ }
66906+
66907+ if (realok && effectiveok && fsok)
66908+ return 0;
66909+ else {
66910+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
66911+ return 1;
66912+ }
66913+}
66914+
66915+extern int gr_acl_is_capable(const int cap);
66916+
66917+void
66918+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
66919+{
66920+ struct acl_role_label *role = task->role;
66921+ struct acl_subject_label *subj = NULL;
66922+ struct acl_object_label *obj;
66923+ struct file *filp;
66924+ uid_t uid;
66925+ gid_t gid;
66926+
66927+ if (unlikely(!(gr_status & GR_READY)))
66928+ return;
66929+
66930+ uid = GR_GLOBAL_UID(kuid);
66931+ gid = GR_GLOBAL_GID(kgid);
66932+
66933+ filp = task->exec_file;
66934+
66935+ /* kernel process, we'll give them the kernel role */
66936+ if (unlikely(!filp)) {
66937+ task->role = running_polstate.kernel_role;
66938+ task->acl = running_polstate.kernel_role->root_label;
66939+ return;
66940+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
66941+ /* save the current ip at time of role lookup so that the proper
66942+ IP will be learned for role_allowed_ip */
66943+ task->signal->saved_ip = task->signal->curr_ip;
66944+ role = lookup_acl_role_label(task, uid, gid);
66945+ }
66946+
66947+ /* don't change the role if we're not a privileged process */
66948+ if (role && task->role != role &&
66949+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
66950+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
66951+ return;
66952+
66953+ /* perform subject lookup in possibly new role
66954+ we can use this result below in the case where role == task->role
66955+ */
66956+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
66957+
66958+ /* if we changed uid/gid, but result in the same role
66959+ and are using inheritance, don't lose the inherited subject
66960+ if current subject is other than what normal lookup
66961+ would result in, we arrived via inheritance, don't
66962+ lose subject
66963+ */
66964+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
66965+ (subj == task->acl)))
66966+ task->acl = subj;
66967+
66968+ /* leave task->inherited unaffected */
66969+
66970+ task->role = role;
66971+
66972+ task->is_writable = 0;
66973+
66974+ /* ignore additional mmap checks for processes that are writable
66975+ by the default ACL */
66976+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66977+ if (unlikely(obj->mode & GR_WRITE))
66978+ task->is_writable = 1;
66979+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66980+ if (unlikely(obj->mode & GR_WRITE))
66981+ task->is_writable = 1;
66982+
66983+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66984+ 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);
66985+#endif
66986+
66987+ gr_set_proc_res(task);
66988+
66989+ return;
66990+}
66991+
66992+int
66993+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
66994+ const int unsafe_flags)
66995+{
66996+ struct task_struct *task = current;
66997+ struct acl_subject_label *newacl;
66998+ struct acl_object_label *obj;
66999+ __u32 retmode;
67000+
67001+ if (unlikely(!(gr_status & GR_READY)))
67002+ return 0;
67003+
67004+ newacl = chk_subj_label(dentry, mnt, task->role);
67005+
67006+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
67007+ did an exec
67008+ */
67009+ rcu_read_lock();
67010+ read_lock(&tasklist_lock);
67011+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
67012+ (task->parent->acl->mode & GR_POVERRIDE))) {
67013+ read_unlock(&tasklist_lock);
67014+ rcu_read_unlock();
67015+ goto skip_check;
67016+ }
67017+ read_unlock(&tasklist_lock);
67018+ rcu_read_unlock();
67019+
67020+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
67021+ !(task->role->roletype & GR_ROLE_GOD) &&
67022+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
67023+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67024+ if (unsafe_flags & LSM_UNSAFE_SHARE)
67025+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
67026+ else
67027+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
67028+ return -EACCES;
67029+ }
67030+
67031+skip_check:
67032+
67033+ obj = chk_obj_label(dentry, mnt, task->acl);
67034+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
67035+
67036+ if (!(task->acl->mode & GR_INHERITLEARN) &&
67037+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
67038+ if (obj->nested)
67039+ task->acl = obj->nested;
67040+ else
67041+ task->acl = newacl;
67042+ task->inherited = 0;
67043+ } else {
67044+ task->inherited = 1;
67045+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
67046+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
67047+ }
67048+
67049+ task->is_writable = 0;
67050+
67051+ /* ignore additional mmap checks for processes that are writable
67052+ by the default ACL */
67053+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
67054+ if (unlikely(obj->mode & GR_WRITE))
67055+ task->is_writable = 1;
67056+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
67057+ if (unlikely(obj->mode & GR_WRITE))
67058+ task->is_writable = 1;
67059+
67060+ gr_set_proc_res(task);
67061+
67062+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67063+ 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);
67064+#endif
67065+ return 0;
67066+}
67067+
67068+/* always called with valid inodev ptr */
67069+static void
67070+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
67071+{
67072+ struct acl_object_label *matchpo;
67073+ struct acl_subject_label *matchps;
67074+ struct acl_subject_label *subj;
67075+ struct acl_role_label *role;
67076+ unsigned int x;
67077+
67078+ FOR_EACH_ROLE_START(role)
67079+ FOR_EACH_SUBJECT_START(role, subj, x)
67080+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67081+ matchpo->mode |= GR_DELETED;
67082+ FOR_EACH_SUBJECT_END(subj,x)
67083+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
67084+ /* nested subjects aren't in the role's subj_hash table */
67085+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67086+ matchpo->mode |= GR_DELETED;
67087+ FOR_EACH_NESTED_SUBJECT_END(subj)
67088+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
67089+ matchps->mode |= GR_DELETED;
67090+ FOR_EACH_ROLE_END(role)
67091+
67092+ inodev->nentry->deleted = 1;
67093+
67094+ return;
67095+}
67096+
67097+void
67098+gr_handle_delete(const ino_t ino, const dev_t dev)
67099+{
67100+ struct inodev_entry *inodev;
67101+
67102+ if (unlikely(!(gr_status & GR_READY)))
67103+ return;
67104+
67105+ write_lock(&gr_inode_lock);
67106+ inodev = lookup_inodev_entry(ino, dev);
67107+ if (inodev != NULL)
67108+ do_handle_delete(inodev, ino, dev);
67109+ write_unlock(&gr_inode_lock);
67110+
67111+ return;
67112+}
67113+
67114+static void
67115+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
67116+ const ino_t newinode, const dev_t newdevice,
67117+ struct acl_subject_label *subj)
67118+{
67119+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
67120+ struct acl_object_label *match;
67121+
67122+ match = subj->obj_hash[index];
67123+
67124+ while (match && (match->inode != oldinode ||
67125+ match->device != olddevice ||
67126+ !(match->mode & GR_DELETED)))
67127+ match = match->next;
67128+
67129+ if (match && (match->inode == oldinode)
67130+ && (match->device == olddevice)
67131+ && (match->mode & GR_DELETED)) {
67132+ if (match->prev == NULL) {
67133+ subj->obj_hash[index] = match->next;
67134+ if (match->next != NULL)
67135+ match->next->prev = NULL;
67136+ } else {
67137+ match->prev->next = match->next;
67138+ if (match->next != NULL)
67139+ match->next->prev = match->prev;
67140+ }
67141+ match->prev = NULL;
67142+ match->next = NULL;
67143+ match->inode = newinode;
67144+ match->device = newdevice;
67145+ match->mode &= ~GR_DELETED;
67146+
67147+ insert_acl_obj_label(match, subj);
67148+ }
67149+
67150+ return;
67151+}
67152+
67153+static void
67154+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
67155+ const ino_t newinode, const dev_t newdevice,
67156+ struct acl_role_label *role)
67157+{
67158+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
67159+ struct acl_subject_label *match;
67160+
67161+ match = role->subj_hash[index];
67162+
67163+ while (match && (match->inode != oldinode ||
67164+ match->device != olddevice ||
67165+ !(match->mode & GR_DELETED)))
67166+ match = match->next;
67167+
67168+ if (match && (match->inode == oldinode)
67169+ && (match->device == olddevice)
67170+ && (match->mode & GR_DELETED)) {
67171+ if (match->prev == NULL) {
67172+ role->subj_hash[index] = match->next;
67173+ if (match->next != NULL)
67174+ match->next->prev = NULL;
67175+ } else {
67176+ match->prev->next = match->next;
67177+ if (match->next != NULL)
67178+ match->next->prev = match->prev;
67179+ }
67180+ match->prev = NULL;
67181+ match->next = NULL;
67182+ match->inode = newinode;
67183+ match->device = newdevice;
67184+ match->mode &= ~GR_DELETED;
67185+
67186+ insert_acl_subj_label(match, role);
67187+ }
67188+
67189+ return;
67190+}
67191+
67192+static void
67193+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
67194+ const ino_t newinode, const dev_t newdevice)
67195+{
67196+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
67197+ struct inodev_entry *match;
67198+
67199+ match = running_polstate.inodev_set.i_hash[index];
67200+
67201+ while (match && (match->nentry->inode != oldinode ||
67202+ match->nentry->device != olddevice || !match->nentry->deleted))
67203+ match = match->next;
67204+
67205+ if (match && (match->nentry->inode == oldinode)
67206+ && (match->nentry->device == olddevice) &&
67207+ match->nentry->deleted) {
67208+ if (match->prev == NULL) {
67209+ running_polstate.inodev_set.i_hash[index] = match->next;
67210+ if (match->next != NULL)
67211+ match->next->prev = NULL;
67212+ } else {
67213+ match->prev->next = match->next;
67214+ if (match->next != NULL)
67215+ match->next->prev = match->prev;
67216+ }
67217+ match->prev = NULL;
67218+ match->next = NULL;
67219+ match->nentry->inode = newinode;
67220+ match->nentry->device = newdevice;
67221+ match->nentry->deleted = 0;
67222+
67223+ insert_inodev_entry(match);
67224+ }
67225+
67226+ return;
67227+}
67228+
67229+static void
67230+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
67231+{
67232+ struct acl_subject_label *subj;
67233+ struct acl_role_label *role;
67234+ unsigned int x;
67235+
67236+ FOR_EACH_ROLE_START(role)
67237+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
67238+
67239+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
67240+ if ((subj->inode == ino) && (subj->device == dev)) {
67241+ subj->inode = ino;
67242+ subj->device = dev;
67243+ }
67244+ /* nested subjects aren't in the role's subj_hash table */
67245+ update_acl_obj_label(matchn->inode, matchn->device,
67246+ ino, dev, subj);
67247+ FOR_EACH_NESTED_SUBJECT_END(subj)
67248+ FOR_EACH_SUBJECT_START(role, subj, x)
67249+ update_acl_obj_label(matchn->inode, matchn->device,
67250+ ino, dev, subj);
67251+ FOR_EACH_SUBJECT_END(subj,x)
67252+ FOR_EACH_ROLE_END(role)
67253+
67254+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
67255+
67256+ return;
67257+}
67258+
67259+static void
67260+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
67261+ const struct vfsmount *mnt)
67262+{
67263+ ino_t ino = dentry->d_inode->i_ino;
67264+ dev_t dev = __get_dev(dentry);
67265+
67266+ __do_handle_create(matchn, ino, dev);
67267+
67268+ return;
67269+}
67270+
67271+void
67272+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
67273+{
67274+ struct name_entry *matchn;
67275+
67276+ if (unlikely(!(gr_status & GR_READY)))
67277+ return;
67278+
67279+ preempt_disable();
67280+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
67281+
67282+ if (unlikely((unsigned long)matchn)) {
67283+ write_lock(&gr_inode_lock);
67284+ do_handle_create(matchn, dentry, mnt);
67285+ write_unlock(&gr_inode_lock);
67286+ }
67287+ preempt_enable();
67288+
67289+ return;
67290+}
67291+
67292+void
67293+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
67294+{
67295+ struct name_entry *matchn;
67296+
67297+ if (unlikely(!(gr_status & GR_READY)))
67298+ return;
67299+
67300+ preempt_disable();
67301+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
67302+
67303+ if (unlikely((unsigned long)matchn)) {
67304+ write_lock(&gr_inode_lock);
67305+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
67306+ write_unlock(&gr_inode_lock);
67307+ }
67308+ preempt_enable();
67309+
67310+ return;
67311+}
67312+
67313+void
67314+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67315+ struct dentry *old_dentry,
67316+ struct dentry *new_dentry,
67317+ struct vfsmount *mnt, const __u8 replace)
67318+{
67319+ struct name_entry *matchn;
67320+ struct inodev_entry *inodev;
67321+ struct inode *inode = new_dentry->d_inode;
67322+ ino_t old_ino = old_dentry->d_inode->i_ino;
67323+ dev_t old_dev = __get_dev(old_dentry);
67324+
67325+ /* vfs_rename swaps the name and parent link for old_dentry and
67326+ new_dentry
67327+ at this point, old_dentry has the new name, parent link, and inode
67328+ for the renamed file
67329+ if a file is being replaced by a rename, new_dentry has the inode
67330+ and name for the replaced file
67331+ */
67332+
67333+ if (unlikely(!(gr_status & GR_READY)))
67334+ return;
67335+
67336+ preempt_disable();
67337+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
67338+
67339+ /* we wouldn't have to check d_inode if it weren't for
67340+ NFS silly-renaming
67341+ */
67342+
67343+ write_lock(&gr_inode_lock);
67344+ if (unlikely(replace && inode)) {
67345+ ino_t new_ino = inode->i_ino;
67346+ dev_t new_dev = __get_dev(new_dentry);
67347+
67348+ inodev = lookup_inodev_entry(new_ino, new_dev);
67349+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
67350+ do_handle_delete(inodev, new_ino, new_dev);
67351+ }
67352+
67353+ inodev = lookup_inodev_entry(old_ino, old_dev);
67354+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
67355+ do_handle_delete(inodev, old_ino, old_dev);
67356+
67357+ if (unlikely((unsigned long)matchn))
67358+ do_handle_create(matchn, old_dentry, mnt);
67359+
67360+ write_unlock(&gr_inode_lock);
67361+ preempt_enable();
67362+
67363+ return;
67364+}
67365+
67366+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67367+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67368+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67369+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67370+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67371+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67372+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67373+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67374+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67375+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67376+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67377+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67378+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67379+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67380+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67381+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67382+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67383+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67384+};
67385+
67386+void
67387+gr_learn_resource(const struct task_struct *task,
67388+ const int res, const unsigned long wanted, const int gt)
67389+{
67390+ struct acl_subject_label *acl;
67391+ const struct cred *cred;
67392+
67393+ if (unlikely((gr_status & GR_READY) &&
67394+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67395+ goto skip_reslog;
67396+
67397+ gr_log_resource(task, res, wanted, gt);
67398+skip_reslog:
67399+
67400+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67401+ return;
67402+
67403+ acl = task->acl;
67404+
67405+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67406+ !(acl->resmask & (1U << (unsigned short) res))))
67407+ return;
67408+
67409+ if (wanted >= acl->res[res].rlim_cur) {
67410+ unsigned long res_add;
67411+
67412+ res_add = wanted + res_learn_bumps[res];
67413+
67414+ acl->res[res].rlim_cur = res_add;
67415+
67416+ if (wanted > acl->res[res].rlim_max)
67417+ acl->res[res].rlim_max = res_add;
67418+
67419+ /* only log the subject filename, since resource logging is supported for
67420+ single-subject learning only */
67421+ rcu_read_lock();
67422+ cred = __task_cred(task);
67423+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67424+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67425+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67426+ "", (unsigned long) res, &task->signal->saved_ip);
67427+ rcu_read_unlock();
67428+ }
67429+
67430+ return;
67431+}
67432+EXPORT_SYMBOL(gr_learn_resource);
67433+#endif
67434+
67435+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67436+void
67437+pax_set_initial_flags(struct linux_binprm *bprm)
67438+{
67439+ struct task_struct *task = current;
67440+ struct acl_subject_label *proc;
67441+ unsigned long flags;
67442+
67443+ if (unlikely(!(gr_status & GR_READY)))
67444+ return;
67445+
67446+ flags = pax_get_flags(task);
67447+
67448+ proc = task->acl;
67449+
67450+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67451+ flags &= ~MF_PAX_PAGEEXEC;
67452+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67453+ flags &= ~MF_PAX_SEGMEXEC;
67454+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67455+ flags &= ~MF_PAX_RANDMMAP;
67456+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67457+ flags &= ~MF_PAX_EMUTRAMP;
67458+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67459+ flags &= ~MF_PAX_MPROTECT;
67460+
67461+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67462+ flags |= MF_PAX_PAGEEXEC;
67463+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67464+ flags |= MF_PAX_SEGMEXEC;
67465+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67466+ flags |= MF_PAX_RANDMMAP;
67467+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67468+ flags |= MF_PAX_EMUTRAMP;
67469+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67470+ flags |= MF_PAX_MPROTECT;
67471+
67472+ pax_set_flags(task, flags);
67473+
67474+ return;
67475+}
67476+#endif
67477+
67478+int
67479+gr_handle_proc_ptrace(struct task_struct *task)
67480+{
67481+ struct file *filp;
67482+ struct task_struct *tmp = task;
67483+ struct task_struct *curtemp = current;
67484+ __u32 retmode;
67485+
67486+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67487+ if (unlikely(!(gr_status & GR_READY)))
67488+ return 0;
67489+#endif
67490+
67491+ read_lock(&tasklist_lock);
67492+ read_lock(&grsec_exec_file_lock);
67493+ filp = task->exec_file;
67494+
67495+ while (task_pid_nr(tmp) > 0) {
67496+ if (tmp == curtemp)
67497+ break;
67498+ tmp = tmp->real_parent;
67499+ }
67500+
67501+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67502+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67503+ read_unlock(&grsec_exec_file_lock);
67504+ read_unlock(&tasklist_lock);
67505+ return 1;
67506+ }
67507+
67508+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67509+ if (!(gr_status & GR_READY)) {
67510+ read_unlock(&grsec_exec_file_lock);
67511+ read_unlock(&tasklist_lock);
67512+ return 0;
67513+ }
67514+#endif
67515+
67516+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67517+ read_unlock(&grsec_exec_file_lock);
67518+ read_unlock(&tasklist_lock);
67519+
67520+ if (retmode & GR_NOPTRACE)
67521+ return 1;
67522+
67523+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67524+ && (current->acl != task->acl || (current->acl != current->role->root_label
67525+ && task_pid_nr(current) != task_pid_nr(task))))
67526+ return 1;
67527+
67528+ return 0;
67529+}
67530+
67531+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67532+{
67533+ if (unlikely(!(gr_status & GR_READY)))
67534+ return;
67535+
67536+ if (!(current->role->roletype & GR_ROLE_GOD))
67537+ return;
67538+
67539+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67540+ p->role->rolename, gr_task_roletype_to_char(p),
67541+ p->acl->filename);
67542+}
67543+
67544+int
67545+gr_handle_ptrace(struct task_struct *task, const long request)
67546+{
67547+ struct task_struct *tmp = task;
67548+ struct task_struct *curtemp = current;
67549+ __u32 retmode;
67550+
67551+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67552+ if (unlikely(!(gr_status & GR_READY)))
67553+ return 0;
67554+#endif
67555+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67556+ read_lock(&tasklist_lock);
67557+ while (task_pid_nr(tmp) > 0) {
67558+ if (tmp == curtemp)
67559+ break;
67560+ tmp = tmp->real_parent;
67561+ }
67562+
67563+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67564+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67565+ read_unlock(&tasklist_lock);
67566+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67567+ return 1;
67568+ }
67569+ read_unlock(&tasklist_lock);
67570+ }
67571+
67572+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67573+ if (!(gr_status & GR_READY))
67574+ return 0;
67575+#endif
67576+
67577+ read_lock(&grsec_exec_file_lock);
67578+ if (unlikely(!task->exec_file)) {
67579+ read_unlock(&grsec_exec_file_lock);
67580+ return 0;
67581+ }
67582+
67583+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67584+ read_unlock(&grsec_exec_file_lock);
67585+
67586+ if (retmode & GR_NOPTRACE) {
67587+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67588+ return 1;
67589+ }
67590+
67591+ if (retmode & GR_PTRACERD) {
67592+ switch (request) {
67593+ case PTRACE_SEIZE:
67594+ case PTRACE_POKETEXT:
67595+ case PTRACE_POKEDATA:
67596+ case PTRACE_POKEUSR:
67597+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67598+ case PTRACE_SETREGS:
67599+ case PTRACE_SETFPREGS:
67600+#endif
67601+#ifdef CONFIG_X86
67602+ case PTRACE_SETFPXREGS:
67603+#endif
67604+#ifdef CONFIG_ALTIVEC
67605+ case PTRACE_SETVRREGS:
67606+#endif
67607+ return 1;
67608+ default:
67609+ return 0;
67610+ }
67611+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
67612+ !(current->role->roletype & GR_ROLE_GOD) &&
67613+ (current->acl != task->acl)) {
67614+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67615+ return 1;
67616+ }
67617+
67618+ return 0;
67619+}
67620+
67621+static int is_writable_mmap(const struct file *filp)
67622+{
67623+ struct task_struct *task = current;
67624+ struct acl_object_label *obj, *obj2;
67625+
67626+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67627+ !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))) {
67628+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67629+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67630+ task->role->root_label);
67631+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67632+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67633+ return 1;
67634+ }
67635+ }
67636+ return 0;
67637+}
67638+
67639+int
67640+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67641+{
67642+ __u32 mode;
67643+
67644+ if (unlikely(!file || !(prot & PROT_EXEC)))
67645+ return 1;
67646+
67647+ if (is_writable_mmap(file))
67648+ return 0;
67649+
67650+ mode =
67651+ gr_search_file(file->f_path.dentry,
67652+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67653+ file->f_path.mnt);
67654+
67655+ if (!gr_tpe_allow(file))
67656+ return 0;
67657+
67658+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67659+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67660+ return 0;
67661+ } else if (unlikely(!(mode & GR_EXEC))) {
67662+ return 0;
67663+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67664+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67665+ return 1;
67666+ }
67667+
67668+ return 1;
67669+}
67670+
67671+int
67672+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67673+{
67674+ __u32 mode;
67675+
67676+ if (unlikely(!file || !(prot & PROT_EXEC)))
67677+ return 1;
67678+
67679+ if (is_writable_mmap(file))
67680+ return 0;
67681+
67682+ mode =
67683+ gr_search_file(file->f_path.dentry,
67684+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67685+ file->f_path.mnt);
67686+
67687+ if (!gr_tpe_allow(file))
67688+ return 0;
67689+
67690+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67691+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67692+ return 0;
67693+ } else if (unlikely(!(mode & GR_EXEC))) {
67694+ return 0;
67695+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67696+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67697+ return 1;
67698+ }
67699+
67700+ return 1;
67701+}
67702+
67703+void
67704+gr_acl_handle_psacct(struct task_struct *task, const long code)
67705+{
67706+ unsigned long runtime;
67707+ unsigned long cputime;
67708+ unsigned int wday, cday;
67709+ __u8 whr, chr;
67710+ __u8 wmin, cmin;
67711+ __u8 wsec, csec;
67712+ struct timespec timeval;
67713+
67714+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67715+ !(task->acl->mode & GR_PROCACCT)))
67716+ return;
67717+
67718+ do_posix_clock_monotonic_gettime(&timeval);
67719+ runtime = timeval.tv_sec - task->start_time.tv_sec;
67720+ wday = runtime / (3600 * 24);
67721+ runtime -= wday * (3600 * 24);
67722+ whr = runtime / 3600;
67723+ runtime -= whr * 3600;
67724+ wmin = runtime / 60;
67725+ runtime -= wmin * 60;
67726+ wsec = runtime;
67727+
67728+ cputime = (task->utime + task->stime) / HZ;
67729+ cday = cputime / (3600 * 24);
67730+ cputime -= cday * (3600 * 24);
67731+ chr = cputime / 3600;
67732+ cputime -= chr * 3600;
67733+ cmin = cputime / 60;
67734+ cputime -= cmin * 60;
67735+ csec = cputime;
67736+
67737+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67738+
67739+ return;
67740+}
67741+
67742+#ifdef CONFIG_TASKSTATS
67743+int gr_is_taskstats_denied(int pid)
67744+{
67745+ struct task_struct *task;
67746+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67747+ const struct cred *cred;
67748+#endif
67749+ int ret = 0;
67750+
67751+ /* restrict taskstats viewing to un-chrooted root users
67752+ who have the 'view' subject flag if the RBAC system is enabled
67753+ */
67754+
67755+ rcu_read_lock();
67756+ read_lock(&tasklist_lock);
67757+ task = find_task_by_vpid(pid);
67758+ if (task) {
67759+#ifdef CONFIG_GRKERNSEC_CHROOT
67760+ if (proc_is_chrooted(task))
67761+ ret = -EACCES;
67762+#endif
67763+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67764+ cred = __task_cred(task);
67765+#ifdef CONFIG_GRKERNSEC_PROC_USER
67766+ if (gr_is_global_nonroot(cred->uid))
67767+ ret = -EACCES;
67768+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67769+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
67770+ ret = -EACCES;
67771+#endif
67772+#endif
67773+ if (gr_status & GR_READY) {
67774+ if (!(task->acl->mode & GR_VIEW))
67775+ ret = -EACCES;
67776+ }
67777+ } else
67778+ ret = -ENOENT;
67779+
67780+ read_unlock(&tasklist_lock);
67781+ rcu_read_unlock();
67782+
67783+ return ret;
67784+}
67785+#endif
67786+
67787+/* AUXV entries are filled via a descendant of search_binary_handler
67788+ after we've already applied the subject for the target
67789+*/
67790+int gr_acl_enable_at_secure(void)
67791+{
67792+ if (unlikely(!(gr_status & GR_READY)))
67793+ return 0;
67794+
67795+ if (current->acl->mode & GR_ATSECURE)
67796+ return 1;
67797+
67798+ return 0;
67799+}
67800+
67801+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
67802+{
67803+ struct task_struct *task = current;
67804+ struct dentry *dentry = file->f_path.dentry;
67805+ struct vfsmount *mnt = file->f_path.mnt;
67806+ struct acl_object_label *obj, *tmp;
67807+ struct acl_subject_label *subj;
67808+ unsigned int bufsize;
67809+ int is_not_root;
67810+ char *path;
67811+ dev_t dev = __get_dev(dentry);
67812+
67813+ if (unlikely(!(gr_status & GR_READY)))
67814+ return 1;
67815+
67816+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67817+ return 1;
67818+
67819+ /* ignore Eric Biederman */
67820+ if (IS_PRIVATE(dentry->d_inode))
67821+ return 1;
67822+
67823+ subj = task->acl;
67824+ read_lock(&gr_inode_lock);
67825+ do {
67826+ obj = lookup_acl_obj_label(ino, dev, subj);
67827+ if (obj != NULL) {
67828+ read_unlock(&gr_inode_lock);
67829+ return (obj->mode & GR_FIND) ? 1 : 0;
67830+ }
67831+ } while ((subj = subj->parent_subject));
67832+ read_unlock(&gr_inode_lock);
67833+
67834+ /* this is purely an optimization since we're looking for an object
67835+ for the directory we're doing a readdir on
67836+ if it's possible for any globbed object to match the entry we're
67837+ filling into the directory, then the object we find here will be
67838+ an anchor point with attached globbed objects
67839+ */
67840+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
67841+ if (obj->globbed == NULL)
67842+ return (obj->mode & GR_FIND) ? 1 : 0;
67843+
67844+ is_not_root = ((obj->filename[0] == '/') &&
67845+ (obj->filename[1] == '\0')) ? 0 : 1;
67846+ bufsize = PAGE_SIZE - namelen - is_not_root;
67847+
67848+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
67849+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
67850+ return 1;
67851+
67852+ preempt_disable();
67853+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67854+ bufsize);
67855+
67856+ bufsize = strlen(path);
67857+
67858+ /* if base is "/", don't append an additional slash */
67859+ if (is_not_root)
67860+ *(path + bufsize) = '/';
67861+ memcpy(path + bufsize + is_not_root, name, namelen);
67862+ *(path + bufsize + namelen + is_not_root) = '\0';
67863+
67864+ tmp = obj->globbed;
67865+ while (tmp) {
67866+ if (!glob_match(tmp->filename, path)) {
67867+ preempt_enable();
67868+ return (tmp->mode & GR_FIND) ? 1 : 0;
67869+ }
67870+ tmp = tmp->next;
67871+ }
67872+ preempt_enable();
67873+ return (obj->mode & GR_FIND) ? 1 : 0;
67874+}
67875+
67876+void gr_put_exec_file(struct task_struct *task)
67877+{
67878+ struct file *filp;
67879+
67880+ write_lock(&grsec_exec_file_lock);
67881+ filp = task->exec_file;
67882+ task->exec_file = NULL;
67883+ write_unlock(&grsec_exec_file_lock);
67884+
67885+ if (filp)
67886+ fput(filp);
67887+
67888+ return;
67889+}
67890+
67891+
67892+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
67893+EXPORT_SYMBOL(gr_acl_is_enabled);
67894+#endif
67895+#ifdef CONFIG_SECURITY
67896+EXPORT_SYMBOL(gr_check_user_change);
67897+EXPORT_SYMBOL(gr_check_group_change);
67898+#endif
67899+
67900diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
67901new file mode 100644
67902index 0000000..18ffbbd
67903--- /dev/null
67904+++ b/grsecurity/gracl_alloc.c
67905@@ -0,0 +1,105 @@
67906+#include <linux/kernel.h>
67907+#include <linux/mm.h>
67908+#include <linux/slab.h>
67909+#include <linux/vmalloc.h>
67910+#include <linux/gracl.h>
67911+#include <linux/grsecurity.h>
67912+
67913+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
67914+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
67915+
67916+static __inline__ int
67917+alloc_pop(void)
67918+{
67919+ if (current_alloc_state->alloc_stack_next == 1)
67920+ return 0;
67921+
67922+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
67923+
67924+ current_alloc_state->alloc_stack_next--;
67925+
67926+ return 1;
67927+}
67928+
67929+static __inline__ int
67930+alloc_push(void *buf)
67931+{
67932+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
67933+ return 1;
67934+
67935+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
67936+
67937+ current_alloc_state->alloc_stack_next++;
67938+
67939+ return 0;
67940+}
67941+
67942+void *
67943+acl_alloc(unsigned long len)
67944+{
67945+ void *ret = NULL;
67946+
67947+ if (!len || len > PAGE_SIZE)
67948+ goto out;
67949+
67950+ ret = kmalloc(len, GFP_KERNEL);
67951+
67952+ if (ret) {
67953+ if (alloc_push(ret)) {
67954+ kfree(ret);
67955+ ret = NULL;
67956+ }
67957+ }
67958+
67959+out:
67960+ return ret;
67961+}
67962+
67963+void *
67964+acl_alloc_num(unsigned long num, unsigned long len)
67965+{
67966+ if (!len || (num > (PAGE_SIZE / len)))
67967+ return NULL;
67968+
67969+ return acl_alloc(num * len);
67970+}
67971+
67972+void
67973+acl_free_all(void)
67974+{
67975+ if (!current_alloc_state->alloc_stack)
67976+ return;
67977+
67978+ while (alloc_pop()) ;
67979+
67980+ if (current_alloc_state->alloc_stack) {
67981+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
67982+ kfree(current_alloc_state->alloc_stack);
67983+ else
67984+ vfree(current_alloc_state->alloc_stack);
67985+ }
67986+
67987+ current_alloc_state->alloc_stack = NULL;
67988+ current_alloc_state->alloc_stack_size = 1;
67989+ current_alloc_state->alloc_stack_next = 1;
67990+
67991+ return;
67992+}
67993+
67994+int
67995+acl_alloc_stack_init(unsigned long size)
67996+{
67997+ if ((size * sizeof (void *)) <= PAGE_SIZE)
67998+ current_alloc_state->alloc_stack =
67999+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
68000+ else
68001+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
68002+
68003+ current_alloc_state->alloc_stack_size = size;
68004+ current_alloc_state->alloc_stack_next = 1;
68005+
68006+ if (!current_alloc_state->alloc_stack)
68007+ return 0;
68008+ else
68009+ return 1;
68010+}
68011diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
68012new file mode 100644
68013index 0000000..bdd51ea
68014--- /dev/null
68015+++ b/grsecurity/gracl_cap.c
68016@@ -0,0 +1,110 @@
68017+#include <linux/kernel.h>
68018+#include <linux/module.h>
68019+#include <linux/sched.h>
68020+#include <linux/gracl.h>
68021+#include <linux/grsecurity.h>
68022+#include <linux/grinternal.h>
68023+
68024+extern const char *captab_log[];
68025+extern int captab_log_entries;
68026+
68027+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68028+{
68029+ struct acl_subject_label *curracl;
68030+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68031+ kernel_cap_t cap_audit = __cap_empty_set;
68032+
68033+ if (!gr_acl_is_enabled())
68034+ return 1;
68035+
68036+ curracl = task->acl;
68037+
68038+ cap_drop = curracl->cap_lower;
68039+ cap_mask = curracl->cap_mask;
68040+ cap_audit = curracl->cap_invert_audit;
68041+
68042+ while ((curracl = curracl->parent_subject)) {
68043+ /* if the cap isn't specified in the current computed mask but is specified in the
68044+ current level subject, and is lowered in the current level subject, then add
68045+ it to the set of dropped capabilities
68046+ otherwise, add the current level subject's mask to the current computed mask
68047+ */
68048+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68049+ cap_raise(cap_mask, cap);
68050+ if (cap_raised(curracl->cap_lower, cap))
68051+ cap_raise(cap_drop, cap);
68052+ if (cap_raised(curracl->cap_invert_audit, cap))
68053+ cap_raise(cap_audit, cap);
68054+ }
68055+ }
68056+
68057+ if (!cap_raised(cap_drop, cap)) {
68058+ if (cap_raised(cap_audit, cap))
68059+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
68060+ return 1;
68061+ }
68062+
68063+ curracl = task->acl;
68064+
68065+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
68066+ && cap_raised(cred->cap_effective, cap)) {
68067+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68068+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
68069+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
68070+ gr_to_filename(task->exec_file->f_path.dentry,
68071+ task->exec_file->f_path.mnt) : curracl->filename,
68072+ curracl->filename, 0UL,
68073+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
68074+ return 1;
68075+ }
68076+
68077+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
68078+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
68079+
68080+ return 0;
68081+}
68082+
68083+int
68084+gr_acl_is_capable(const int cap)
68085+{
68086+ return gr_task_acl_is_capable(current, current_cred(), cap);
68087+}
68088+
68089+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
68090+{
68091+ struct acl_subject_label *curracl;
68092+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68093+
68094+ if (!gr_acl_is_enabled())
68095+ return 1;
68096+
68097+ curracl = task->acl;
68098+
68099+ cap_drop = curracl->cap_lower;
68100+ cap_mask = curracl->cap_mask;
68101+
68102+ while ((curracl = curracl->parent_subject)) {
68103+ /* if the cap isn't specified in the current computed mask but is specified in the
68104+ current level subject, and is lowered in the current level subject, then add
68105+ it to the set of dropped capabilities
68106+ otherwise, add the current level subject's mask to the current computed mask
68107+ */
68108+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68109+ cap_raise(cap_mask, cap);
68110+ if (cap_raised(curracl->cap_lower, cap))
68111+ cap_raise(cap_drop, cap);
68112+ }
68113+ }
68114+
68115+ if (!cap_raised(cap_drop, cap))
68116+ return 1;
68117+
68118+ return 0;
68119+}
68120+
68121+int
68122+gr_acl_is_capable_nolog(const int cap)
68123+{
68124+ return gr_task_acl_is_capable_nolog(current, cap);
68125+}
68126+
68127diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
68128new file mode 100644
68129index 0000000..ca25605
68130--- /dev/null
68131+++ b/grsecurity/gracl_compat.c
68132@@ -0,0 +1,270 @@
68133+#include <linux/kernel.h>
68134+#include <linux/gracl.h>
68135+#include <linux/compat.h>
68136+#include <linux/gracl_compat.h>
68137+
68138+#include <asm/uaccess.h>
68139+
68140+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
68141+{
68142+ struct gr_arg_wrapper_compat uwrapcompat;
68143+
68144+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
68145+ return -EFAULT;
68146+
68147+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
68148+ (uwrapcompat.version != 0x2901)) ||
68149+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
68150+ return -EINVAL;
68151+
68152+ uwrap->arg = compat_ptr(uwrapcompat.arg);
68153+ uwrap->version = uwrapcompat.version;
68154+ uwrap->size = sizeof(struct gr_arg);
68155+
68156+ return 0;
68157+}
68158+
68159+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
68160+{
68161+ struct gr_arg_compat argcompat;
68162+
68163+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
68164+ return -EFAULT;
68165+
68166+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
68167+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
68168+ arg->role_db.num_roles = argcompat.role_db.num_roles;
68169+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
68170+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
68171+ arg->role_db.num_objects = argcompat.role_db.num_objects;
68172+
68173+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
68174+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
68175+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
68176+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
68177+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
68178+ arg->segv_device = argcompat.segv_device;
68179+ arg->segv_inode = argcompat.segv_inode;
68180+ arg->segv_uid = argcompat.segv_uid;
68181+ arg->num_sprole_pws = argcompat.num_sprole_pws;
68182+ arg->mode = argcompat.mode;
68183+
68184+ return 0;
68185+}
68186+
68187+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
68188+{
68189+ struct acl_object_label_compat objcompat;
68190+
68191+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
68192+ return -EFAULT;
68193+
68194+ obj->filename = compat_ptr(objcompat.filename);
68195+ obj->inode = objcompat.inode;
68196+ obj->device = objcompat.device;
68197+ obj->mode = objcompat.mode;
68198+
68199+ obj->nested = compat_ptr(objcompat.nested);
68200+ obj->globbed = compat_ptr(objcompat.globbed);
68201+
68202+ obj->prev = compat_ptr(objcompat.prev);
68203+ obj->next = compat_ptr(objcompat.next);
68204+
68205+ return 0;
68206+}
68207+
68208+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
68209+{
68210+ unsigned int i;
68211+ struct acl_subject_label_compat subjcompat;
68212+
68213+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
68214+ return -EFAULT;
68215+
68216+ subj->filename = compat_ptr(subjcompat.filename);
68217+ subj->inode = subjcompat.inode;
68218+ subj->device = subjcompat.device;
68219+ subj->mode = subjcompat.mode;
68220+ subj->cap_mask = subjcompat.cap_mask;
68221+ subj->cap_lower = subjcompat.cap_lower;
68222+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
68223+
68224+ for (i = 0; i < GR_NLIMITS; i++) {
68225+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
68226+ subj->res[i].rlim_cur = RLIM_INFINITY;
68227+ else
68228+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
68229+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
68230+ subj->res[i].rlim_max = RLIM_INFINITY;
68231+ else
68232+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
68233+ }
68234+ subj->resmask = subjcompat.resmask;
68235+
68236+ subj->user_trans_type = subjcompat.user_trans_type;
68237+ subj->group_trans_type = subjcompat.group_trans_type;
68238+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
68239+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
68240+ subj->user_trans_num = subjcompat.user_trans_num;
68241+ subj->group_trans_num = subjcompat.group_trans_num;
68242+
68243+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
68244+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
68245+ subj->ip_type = subjcompat.ip_type;
68246+ subj->ips = compat_ptr(subjcompat.ips);
68247+ subj->ip_num = subjcompat.ip_num;
68248+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
68249+
68250+ subj->crashes = subjcompat.crashes;
68251+ subj->expires = subjcompat.expires;
68252+
68253+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
68254+ subj->hash = compat_ptr(subjcompat.hash);
68255+ subj->prev = compat_ptr(subjcompat.prev);
68256+ subj->next = compat_ptr(subjcompat.next);
68257+
68258+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
68259+ subj->obj_hash_size = subjcompat.obj_hash_size;
68260+ subj->pax_flags = subjcompat.pax_flags;
68261+
68262+ return 0;
68263+}
68264+
68265+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
68266+{
68267+ struct acl_role_label_compat rolecompat;
68268+
68269+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
68270+ return -EFAULT;
68271+
68272+ role->rolename = compat_ptr(rolecompat.rolename);
68273+ role->uidgid = rolecompat.uidgid;
68274+ role->roletype = rolecompat.roletype;
68275+
68276+ role->auth_attempts = rolecompat.auth_attempts;
68277+ role->expires = rolecompat.expires;
68278+
68279+ role->root_label = compat_ptr(rolecompat.root_label);
68280+ role->hash = compat_ptr(rolecompat.hash);
68281+
68282+ role->prev = compat_ptr(rolecompat.prev);
68283+ role->next = compat_ptr(rolecompat.next);
68284+
68285+ role->transitions = compat_ptr(rolecompat.transitions);
68286+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68287+ role->domain_children = compat_ptr(rolecompat.domain_children);
68288+ role->domain_child_num = rolecompat.domain_child_num;
68289+
68290+ role->umask = rolecompat.umask;
68291+
68292+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
68293+ role->subj_hash_size = rolecompat.subj_hash_size;
68294+
68295+ return 0;
68296+}
68297+
68298+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68299+{
68300+ struct role_allowed_ip_compat roleip_compat;
68301+
68302+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68303+ return -EFAULT;
68304+
68305+ roleip->addr = roleip_compat.addr;
68306+ roleip->netmask = roleip_compat.netmask;
68307+
68308+ roleip->prev = compat_ptr(roleip_compat.prev);
68309+ roleip->next = compat_ptr(roleip_compat.next);
68310+
68311+ return 0;
68312+}
68313+
68314+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68315+{
68316+ struct role_transition_compat trans_compat;
68317+
68318+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68319+ return -EFAULT;
68320+
68321+ trans->rolename = compat_ptr(trans_compat.rolename);
68322+
68323+ trans->prev = compat_ptr(trans_compat.prev);
68324+ trans->next = compat_ptr(trans_compat.next);
68325+
68326+ return 0;
68327+
68328+}
68329+
68330+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68331+{
68332+ struct gr_hash_struct_compat hash_compat;
68333+
68334+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68335+ return -EFAULT;
68336+
68337+ hash->table = compat_ptr(hash_compat.table);
68338+ hash->nametable = compat_ptr(hash_compat.nametable);
68339+ hash->first = compat_ptr(hash_compat.first);
68340+
68341+ hash->table_size = hash_compat.table_size;
68342+ hash->used_size = hash_compat.used_size;
68343+
68344+ hash->type = hash_compat.type;
68345+
68346+ return 0;
68347+}
68348+
68349+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68350+{
68351+ compat_uptr_t ptrcompat;
68352+
68353+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68354+ return -EFAULT;
68355+
68356+ *(void **)ptr = compat_ptr(ptrcompat);
68357+
68358+ return 0;
68359+}
68360+
68361+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68362+{
68363+ struct acl_ip_label_compat ip_compat;
68364+
68365+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68366+ return -EFAULT;
68367+
68368+ ip->iface = compat_ptr(ip_compat.iface);
68369+ ip->addr = ip_compat.addr;
68370+ ip->netmask = ip_compat.netmask;
68371+ ip->low = ip_compat.low;
68372+ ip->high = ip_compat.high;
68373+ ip->mode = ip_compat.mode;
68374+ ip->type = ip_compat.type;
68375+
68376+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68377+
68378+ ip->prev = compat_ptr(ip_compat.prev);
68379+ ip->next = compat_ptr(ip_compat.next);
68380+
68381+ return 0;
68382+}
68383+
68384+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68385+{
68386+ struct sprole_pw_compat pw_compat;
68387+
68388+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68389+ return -EFAULT;
68390+
68391+ pw->rolename = compat_ptr(pw_compat.rolename);
68392+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68393+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68394+
68395+ return 0;
68396+}
68397+
68398+size_t get_gr_arg_wrapper_size_compat(void)
68399+{
68400+ return sizeof(struct gr_arg_wrapper_compat);
68401+}
68402+
68403diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68404new file mode 100644
68405index 0000000..a89b1f4
68406--- /dev/null
68407+++ b/grsecurity/gracl_fs.c
68408@@ -0,0 +1,437 @@
68409+#include <linux/kernel.h>
68410+#include <linux/sched.h>
68411+#include <linux/types.h>
68412+#include <linux/fs.h>
68413+#include <linux/file.h>
68414+#include <linux/stat.h>
68415+#include <linux/grsecurity.h>
68416+#include <linux/grinternal.h>
68417+#include <linux/gracl.h>
68418+
68419+umode_t
68420+gr_acl_umask(void)
68421+{
68422+ if (unlikely(!gr_acl_is_enabled()))
68423+ return 0;
68424+
68425+ return current->role->umask;
68426+}
68427+
68428+__u32
68429+gr_acl_handle_hidden_file(const struct dentry * dentry,
68430+ const struct vfsmount * mnt)
68431+{
68432+ __u32 mode;
68433+
68434+ if (unlikely(d_is_negative(dentry)))
68435+ return GR_FIND;
68436+
68437+ mode =
68438+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68439+
68440+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68441+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68442+ return mode;
68443+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68444+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68445+ return 0;
68446+ } else if (unlikely(!(mode & GR_FIND)))
68447+ return 0;
68448+
68449+ return GR_FIND;
68450+}
68451+
68452+__u32
68453+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68454+ int acc_mode)
68455+{
68456+ __u32 reqmode = GR_FIND;
68457+ __u32 mode;
68458+
68459+ if (unlikely(d_is_negative(dentry)))
68460+ return reqmode;
68461+
68462+ if (acc_mode & MAY_APPEND)
68463+ reqmode |= GR_APPEND;
68464+ else if (acc_mode & MAY_WRITE)
68465+ reqmode |= GR_WRITE;
68466+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68467+ reqmode |= GR_READ;
68468+
68469+ mode =
68470+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68471+ mnt);
68472+
68473+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68474+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68475+ reqmode & GR_READ ? " reading" : "",
68476+ reqmode & GR_WRITE ? " writing" : reqmode &
68477+ GR_APPEND ? " appending" : "");
68478+ return reqmode;
68479+ } else
68480+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68481+ {
68482+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68483+ reqmode & GR_READ ? " reading" : "",
68484+ reqmode & GR_WRITE ? " writing" : reqmode &
68485+ GR_APPEND ? " appending" : "");
68486+ return 0;
68487+ } else if (unlikely((mode & reqmode) != reqmode))
68488+ return 0;
68489+
68490+ return reqmode;
68491+}
68492+
68493+__u32
68494+gr_acl_handle_creat(const struct dentry * dentry,
68495+ const struct dentry * p_dentry,
68496+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68497+ const int imode)
68498+{
68499+ __u32 reqmode = GR_WRITE | GR_CREATE;
68500+ __u32 mode;
68501+
68502+ if (acc_mode & MAY_APPEND)
68503+ reqmode |= GR_APPEND;
68504+ // if a directory was required or the directory already exists, then
68505+ // don't count this open as a read
68506+ if ((acc_mode & MAY_READ) &&
68507+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68508+ reqmode |= GR_READ;
68509+ if ((open_flags & O_CREAT) &&
68510+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68511+ reqmode |= GR_SETID;
68512+
68513+ mode =
68514+ gr_check_create(dentry, p_dentry, p_mnt,
68515+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68516+
68517+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68518+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68519+ reqmode & GR_READ ? " reading" : "",
68520+ reqmode & GR_WRITE ? " writing" : reqmode &
68521+ GR_APPEND ? " appending" : "");
68522+ return reqmode;
68523+ } else
68524+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68525+ {
68526+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68527+ reqmode & GR_READ ? " reading" : "",
68528+ reqmode & GR_WRITE ? " writing" : reqmode &
68529+ GR_APPEND ? " appending" : "");
68530+ return 0;
68531+ } else if (unlikely((mode & reqmode) != reqmode))
68532+ return 0;
68533+
68534+ return reqmode;
68535+}
68536+
68537+__u32
68538+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68539+ const int fmode)
68540+{
68541+ __u32 mode, reqmode = GR_FIND;
68542+
68543+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68544+ reqmode |= GR_EXEC;
68545+ if (fmode & S_IWOTH)
68546+ reqmode |= GR_WRITE;
68547+ if (fmode & S_IROTH)
68548+ reqmode |= GR_READ;
68549+
68550+ mode =
68551+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68552+ mnt);
68553+
68554+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68555+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68556+ reqmode & GR_READ ? " reading" : "",
68557+ reqmode & GR_WRITE ? " writing" : "",
68558+ reqmode & GR_EXEC ? " executing" : "");
68559+ return reqmode;
68560+ } else
68561+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68562+ {
68563+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68564+ reqmode & GR_READ ? " reading" : "",
68565+ reqmode & GR_WRITE ? " writing" : "",
68566+ reqmode & GR_EXEC ? " executing" : "");
68567+ return 0;
68568+ } else if (unlikely((mode & reqmode) != reqmode))
68569+ return 0;
68570+
68571+ return reqmode;
68572+}
68573+
68574+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68575+{
68576+ __u32 mode;
68577+
68578+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68579+
68580+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68581+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68582+ return mode;
68583+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68584+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68585+ return 0;
68586+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68587+ return 0;
68588+
68589+ return (reqmode);
68590+}
68591+
68592+__u32
68593+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68594+{
68595+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68596+}
68597+
68598+__u32
68599+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68600+{
68601+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68602+}
68603+
68604+__u32
68605+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68606+{
68607+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68608+}
68609+
68610+__u32
68611+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68612+{
68613+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68614+}
68615+
68616+__u32
68617+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68618+ umode_t *modeptr)
68619+{
68620+ umode_t mode;
68621+
68622+ *modeptr &= ~gr_acl_umask();
68623+ mode = *modeptr;
68624+
68625+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68626+ return 1;
68627+
68628+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68629+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68630+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68631+ GR_CHMOD_ACL_MSG);
68632+ } else {
68633+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68634+ }
68635+}
68636+
68637+__u32
68638+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68639+{
68640+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68641+}
68642+
68643+__u32
68644+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68645+{
68646+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68647+}
68648+
68649+__u32
68650+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
68651+{
68652+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
68653+}
68654+
68655+__u32
68656+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68657+{
68658+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68659+}
68660+
68661+__u32
68662+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68663+{
68664+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68665+ GR_UNIXCONNECT_ACL_MSG);
68666+}
68667+
68668+/* hardlinks require at minimum create and link permission,
68669+ any additional privilege required is based on the
68670+ privilege of the file being linked to
68671+*/
68672+__u32
68673+gr_acl_handle_link(const struct dentry * new_dentry,
68674+ const struct dentry * parent_dentry,
68675+ const struct vfsmount * parent_mnt,
68676+ const struct dentry * old_dentry,
68677+ const struct vfsmount * old_mnt, const struct filename *to)
68678+{
68679+ __u32 mode;
68680+ __u32 needmode = GR_CREATE | GR_LINK;
68681+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68682+
68683+ mode =
68684+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68685+ old_mnt);
68686+
68687+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68688+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68689+ return mode;
68690+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68691+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68692+ return 0;
68693+ } else if (unlikely((mode & needmode) != needmode))
68694+ return 0;
68695+
68696+ return 1;
68697+}
68698+
68699+__u32
68700+gr_acl_handle_symlink(const struct dentry * new_dentry,
68701+ const struct dentry * parent_dentry,
68702+ const struct vfsmount * parent_mnt, const struct filename *from)
68703+{
68704+ __u32 needmode = GR_WRITE | GR_CREATE;
68705+ __u32 mode;
68706+
68707+ mode =
68708+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
68709+ GR_CREATE | GR_AUDIT_CREATE |
68710+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68711+
68712+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68713+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68714+ return mode;
68715+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68716+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68717+ return 0;
68718+ } else if (unlikely((mode & needmode) != needmode))
68719+ return 0;
68720+
68721+ return (GR_WRITE | GR_CREATE);
68722+}
68723+
68724+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)
68725+{
68726+ __u32 mode;
68727+
68728+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68729+
68730+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68731+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68732+ return mode;
68733+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68734+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68735+ return 0;
68736+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68737+ return 0;
68738+
68739+ return (reqmode);
68740+}
68741+
68742+__u32
68743+gr_acl_handle_mknod(const struct dentry * new_dentry,
68744+ const struct dentry * parent_dentry,
68745+ const struct vfsmount * parent_mnt,
68746+ const int mode)
68747+{
68748+ __u32 reqmode = GR_WRITE | GR_CREATE;
68749+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68750+ reqmode |= GR_SETID;
68751+
68752+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68753+ reqmode, GR_MKNOD_ACL_MSG);
68754+}
68755+
68756+__u32
68757+gr_acl_handle_mkdir(const struct dentry *new_dentry,
68758+ const struct dentry *parent_dentry,
68759+ const struct vfsmount *parent_mnt)
68760+{
68761+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68762+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
68763+}
68764+
68765+#define RENAME_CHECK_SUCCESS(old, new) \
68766+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
68767+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
68768+
68769+int
68770+gr_acl_handle_rename(struct dentry *new_dentry,
68771+ struct dentry *parent_dentry,
68772+ const struct vfsmount *parent_mnt,
68773+ struct dentry *old_dentry,
68774+ struct inode *old_parent_inode,
68775+ struct vfsmount *old_mnt, const struct filename *newname)
68776+{
68777+ __u32 comp1, comp2;
68778+ int error = 0;
68779+
68780+ if (unlikely(!gr_acl_is_enabled()))
68781+ return 0;
68782+
68783+ if (d_is_negative(new_dentry)) {
68784+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
68785+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
68786+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
68787+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
68788+ GR_DELETE | GR_AUDIT_DELETE |
68789+ GR_AUDIT_READ | GR_AUDIT_WRITE |
68790+ GR_SUPPRESS, old_mnt);
68791+ } else {
68792+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
68793+ GR_CREATE | GR_DELETE |
68794+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
68795+ GR_AUDIT_READ | GR_AUDIT_WRITE |
68796+ GR_SUPPRESS, parent_mnt);
68797+ comp2 =
68798+ gr_search_file(old_dentry,
68799+ GR_READ | GR_WRITE | GR_AUDIT_READ |
68800+ GR_DELETE | GR_AUDIT_DELETE |
68801+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
68802+ }
68803+
68804+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
68805+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
68806+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68807+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
68808+ && !(comp2 & GR_SUPPRESS)) {
68809+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68810+ error = -EACCES;
68811+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
68812+ error = -EACCES;
68813+
68814+ return error;
68815+}
68816+
68817+void
68818+gr_acl_handle_exit(void)
68819+{
68820+ u16 id;
68821+ char *rolename;
68822+
68823+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
68824+ !(current->role->roletype & GR_ROLE_PERSIST))) {
68825+ id = current->acl_role_id;
68826+ rolename = current->role->rolename;
68827+ gr_set_acls(1);
68828+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
68829+ }
68830+
68831+ gr_put_exec_file(current);
68832+ return;
68833+}
68834+
68835+int
68836+gr_acl_handle_procpidmem(const struct task_struct *task)
68837+{
68838+ if (unlikely(!gr_acl_is_enabled()))
68839+ return 0;
68840+
68841+ if (task != current && task->acl->mode & GR_PROTPROCFD)
68842+ return -EACCES;
68843+
68844+ return 0;
68845+}
68846diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
68847new file mode 100644
68848index 0000000..f056b81
68849--- /dev/null
68850+++ b/grsecurity/gracl_ip.c
68851@@ -0,0 +1,386 @@
68852+#include <linux/kernel.h>
68853+#include <asm/uaccess.h>
68854+#include <asm/errno.h>
68855+#include <net/sock.h>
68856+#include <linux/file.h>
68857+#include <linux/fs.h>
68858+#include <linux/net.h>
68859+#include <linux/in.h>
68860+#include <linux/skbuff.h>
68861+#include <linux/ip.h>
68862+#include <linux/udp.h>
68863+#include <linux/types.h>
68864+#include <linux/sched.h>
68865+#include <linux/netdevice.h>
68866+#include <linux/inetdevice.h>
68867+#include <linux/gracl.h>
68868+#include <linux/grsecurity.h>
68869+#include <linux/grinternal.h>
68870+
68871+#define GR_BIND 0x01
68872+#define GR_CONNECT 0x02
68873+#define GR_INVERT 0x04
68874+#define GR_BINDOVERRIDE 0x08
68875+#define GR_CONNECTOVERRIDE 0x10
68876+#define GR_SOCK_FAMILY 0x20
68877+
68878+static const char * gr_protocols[IPPROTO_MAX] = {
68879+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
68880+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
68881+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
68882+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
68883+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
68884+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
68885+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
68886+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
68887+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
68888+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
68889+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
68890+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
68891+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
68892+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
68893+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
68894+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
68895+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
68896+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
68897+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
68898+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
68899+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
68900+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
68901+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
68902+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
68903+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
68904+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
68905+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
68906+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
68907+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
68908+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
68909+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
68910+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
68911+ };
68912+
68913+static const char * gr_socktypes[SOCK_MAX] = {
68914+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
68915+ "unknown:7", "unknown:8", "unknown:9", "packet"
68916+ };
68917+
68918+static const char * gr_sockfamilies[AF_MAX+1] = {
68919+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
68920+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
68921+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
68922+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
68923+ };
68924+
68925+const char *
68926+gr_proto_to_name(unsigned char proto)
68927+{
68928+ return gr_protocols[proto];
68929+}
68930+
68931+const char *
68932+gr_socktype_to_name(unsigned char type)
68933+{
68934+ return gr_socktypes[type];
68935+}
68936+
68937+const char *
68938+gr_sockfamily_to_name(unsigned char family)
68939+{
68940+ return gr_sockfamilies[family];
68941+}
68942+
68943+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
68944+
68945+int
68946+gr_search_socket(const int domain, const int type, const int protocol)
68947+{
68948+ struct acl_subject_label *curr;
68949+ const struct cred *cred = current_cred();
68950+
68951+ if (unlikely(!gr_acl_is_enabled()))
68952+ goto exit;
68953+
68954+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
68955+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
68956+ goto exit; // let the kernel handle it
68957+
68958+ curr = current->acl;
68959+
68960+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
68961+ /* the family is allowed, if this is PF_INET allow it only if
68962+ the extra sock type/protocol checks pass */
68963+ if (domain == PF_INET)
68964+ goto inet_check;
68965+ goto exit;
68966+ } else {
68967+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68968+ __u32 fakeip = 0;
68969+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68970+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68971+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68972+ gr_to_filename(current->exec_file->f_path.dentry,
68973+ current->exec_file->f_path.mnt) :
68974+ curr->filename, curr->filename,
68975+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
68976+ &current->signal->saved_ip);
68977+ goto exit;
68978+ }
68979+ goto exit_fail;
68980+ }
68981+
68982+inet_check:
68983+ /* the rest of this checking is for IPv4 only */
68984+ if (!curr->ips)
68985+ goto exit;
68986+
68987+ if ((curr->ip_type & (1U << type)) &&
68988+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
68989+ goto exit;
68990+
68991+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68992+ /* we don't place acls on raw sockets , and sometimes
68993+ dgram/ip sockets are opened for ioctl and not
68994+ bind/connect, so we'll fake a bind learn log */
68995+ if (type == SOCK_RAW || type == SOCK_PACKET) {
68996+ __u32 fakeip = 0;
68997+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68998+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68999+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
69000+ gr_to_filename(current->exec_file->f_path.dentry,
69001+ current->exec_file->f_path.mnt) :
69002+ curr->filename, curr->filename,
69003+ &fakeip, 0, type,
69004+ protocol, GR_CONNECT, &current->signal->saved_ip);
69005+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
69006+ __u32 fakeip = 0;
69007+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69008+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
69009+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
69010+ gr_to_filename(current->exec_file->f_path.dentry,
69011+ current->exec_file->f_path.mnt) :
69012+ curr->filename, curr->filename,
69013+ &fakeip, 0, type,
69014+ protocol, GR_BIND, &current->signal->saved_ip);
69015+ }
69016+ /* we'll log when they use connect or bind */
69017+ goto exit;
69018+ }
69019+
69020+exit_fail:
69021+ if (domain == PF_INET)
69022+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
69023+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
69024+ else if (rcu_access_pointer(net_families[domain]) != NULL)
69025+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
69026+ gr_socktype_to_name(type), protocol);
69027+
69028+ return 0;
69029+exit:
69030+ return 1;
69031+}
69032+
69033+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)
69034+{
69035+ if ((ip->mode & mode) &&
69036+ (ip_port >= ip->low) &&
69037+ (ip_port <= ip->high) &&
69038+ ((ntohl(ip_addr) & our_netmask) ==
69039+ (ntohl(our_addr) & our_netmask))
69040+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
69041+ && (ip->type & (1U << type))) {
69042+ if (ip->mode & GR_INVERT)
69043+ return 2; // specifically denied
69044+ else
69045+ return 1; // allowed
69046+ }
69047+
69048+ return 0; // not specifically allowed, may continue parsing
69049+}
69050+
69051+static int
69052+gr_search_connectbind(const int full_mode, struct sock *sk,
69053+ struct sockaddr_in *addr, const int type)
69054+{
69055+ char iface[IFNAMSIZ] = {0};
69056+ struct acl_subject_label *curr;
69057+ struct acl_ip_label *ip;
69058+ struct inet_sock *isk;
69059+ struct net_device *dev;
69060+ struct in_device *idev;
69061+ unsigned long i;
69062+ int ret;
69063+ int mode = full_mode & (GR_BIND | GR_CONNECT);
69064+ __u32 ip_addr = 0;
69065+ __u32 our_addr;
69066+ __u32 our_netmask;
69067+ char *p;
69068+ __u16 ip_port = 0;
69069+ const struct cred *cred = current_cred();
69070+
69071+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
69072+ return 0;
69073+
69074+ curr = current->acl;
69075+ isk = inet_sk(sk);
69076+
69077+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
69078+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
69079+ addr->sin_addr.s_addr = curr->inaddr_any_override;
69080+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
69081+ struct sockaddr_in saddr;
69082+ int err;
69083+
69084+ saddr.sin_family = AF_INET;
69085+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
69086+ saddr.sin_port = isk->inet_sport;
69087+
69088+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69089+ if (err)
69090+ return err;
69091+
69092+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69093+ if (err)
69094+ return err;
69095+ }
69096+
69097+ if (!curr->ips)
69098+ return 0;
69099+
69100+ ip_addr = addr->sin_addr.s_addr;
69101+ ip_port = ntohs(addr->sin_port);
69102+
69103+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69104+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69105+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
69106+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
69107+ gr_to_filename(current->exec_file->f_path.dentry,
69108+ current->exec_file->f_path.mnt) :
69109+ curr->filename, curr->filename,
69110+ &ip_addr, ip_port, type,
69111+ sk->sk_protocol, mode, &current->signal->saved_ip);
69112+ return 0;
69113+ }
69114+
69115+ for (i = 0; i < curr->ip_num; i++) {
69116+ ip = *(curr->ips + i);
69117+ if (ip->iface != NULL) {
69118+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
69119+ p = strchr(iface, ':');
69120+ if (p != NULL)
69121+ *p = '\0';
69122+ dev = dev_get_by_name(sock_net(sk), iface);
69123+ if (dev == NULL)
69124+ continue;
69125+ idev = in_dev_get(dev);
69126+ if (idev == NULL) {
69127+ dev_put(dev);
69128+ continue;
69129+ }
69130+ rcu_read_lock();
69131+ for_ifa(idev) {
69132+ if (!strcmp(ip->iface, ifa->ifa_label)) {
69133+ our_addr = ifa->ifa_address;
69134+ our_netmask = 0xffffffff;
69135+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69136+ if (ret == 1) {
69137+ rcu_read_unlock();
69138+ in_dev_put(idev);
69139+ dev_put(dev);
69140+ return 0;
69141+ } else if (ret == 2) {
69142+ rcu_read_unlock();
69143+ in_dev_put(idev);
69144+ dev_put(dev);
69145+ goto denied;
69146+ }
69147+ }
69148+ } endfor_ifa(idev);
69149+ rcu_read_unlock();
69150+ in_dev_put(idev);
69151+ dev_put(dev);
69152+ } else {
69153+ our_addr = ip->addr;
69154+ our_netmask = ip->netmask;
69155+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69156+ if (ret == 1)
69157+ return 0;
69158+ else if (ret == 2)
69159+ goto denied;
69160+ }
69161+ }
69162+
69163+denied:
69164+ if (mode == GR_BIND)
69165+ 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));
69166+ else if (mode == GR_CONNECT)
69167+ 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));
69168+
69169+ return -EACCES;
69170+}
69171+
69172+int
69173+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
69174+{
69175+ /* always allow disconnection of dgram sockets with connect */
69176+ if (addr->sin_family == AF_UNSPEC)
69177+ return 0;
69178+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
69179+}
69180+
69181+int
69182+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
69183+{
69184+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
69185+}
69186+
69187+int gr_search_listen(struct socket *sock)
69188+{
69189+ struct sock *sk = sock->sk;
69190+ struct sockaddr_in addr;
69191+
69192+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69193+ addr.sin_port = inet_sk(sk)->inet_sport;
69194+
69195+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69196+}
69197+
69198+int gr_search_accept(struct socket *sock)
69199+{
69200+ struct sock *sk = sock->sk;
69201+ struct sockaddr_in addr;
69202+
69203+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69204+ addr.sin_port = inet_sk(sk)->inet_sport;
69205+
69206+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69207+}
69208+
69209+int
69210+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
69211+{
69212+ if (addr)
69213+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
69214+ else {
69215+ struct sockaddr_in sin;
69216+ const struct inet_sock *inet = inet_sk(sk);
69217+
69218+ sin.sin_addr.s_addr = inet->inet_daddr;
69219+ sin.sin_port = inet->inet_dport;
69220+
69221+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69222+ }
69223+}
69224+
69225+int
69226+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
69227+{
69228+ struct sockaddr_in sin;
69229+
69230+ if (unlikely(skb->len < sizeof (struct udphdr)))
69231+ return 0; // skip this packet
69232+
69233+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
69234+ sin.sin_port = udp_hdr(skb)->source;
69235+
69236+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69237+}
69238diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
69239new file mode 100644
69240index 0000000..25f54ef
69241--- /dev/null
69242+++ b/grsecurity/gracl_learn.c
69243@@ -0,0 +1,207 @@
69244+#include <linux/kernel.h>
69245+#include <linux/mm.h>
69246+#include <linux/sched.h>
69247+#include <linux/poll.h>
69248+#include <linux/string.h>
69249+#include <linux/file.h>
69250+#include <linux/types.h>
69251+#include <linux/vmalloc.h>
69252+#include <linux/grinternal.h>
69253+
69254+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
69255+ size_t count, loff_t *ppos);
69256+extern int gr_acl_is_enabled(void);
69257+
69258+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
69259+static int gr_learn_attached;
69260+
69261+/* use a 512k buffer */
69262+#define LEARN_BUFFER_SIZE (512 * 1024)
69263+
69264+static DEFINE_SPINLOCK(gr_learn_lock);
69265+static DEFINE_MUTEX(gr_learn_user_mutex);
69266+
69267+/* we need to maintain two buffers, so that the kernel context of grlearn
69268+ uses a semaphore around the userspace copying, and the other kernel contexts
69269+ use a spinlock when copying into the buffer, since they cannot sleep
69270+*/
69271+static char *learn_buffer;
69272+static char *learn_buffer_user;
69273+static int learn_buffer_len;
69274+static int learn_buffer_user_len;
69275+
69276+static ssize_t
69277+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
69278+{
69279+ DECLARE_WAITQUEUE(wait, current);
69280+ ssize_t retval = 0;
69281+
69282+ add_wait_queue(&learn_wait, &wait);
69283+ set_current_state(TASK_INTERRUPTIBLE);
69284+ do {
69285+ mutex_lock(&gr_learn_user_mutex);
69286+ spin_lock(&gr_learn_lock);
69287+ if (learn_buffer_len)
69288+ break;
69289+ spin_unlock(&gr_learn_lock);
69290+ mutex_unlock(&gr_learn_user_mutex);
69291+ if (file->f_flags & O_NONBLOCK) {
69292+ retval = -EAGAIN;
69293+ goto out;
69294+ }
69295+ if (signal_pending(current)) {
69296+ retval = -ERESTARTSYS;
69297+ goto out;
69298+ }
69299+
69300+ schedule();
69301+ } while (1);
69302+
69303+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69304+ learn_buffer_user_len = learn_buffer_len;
69305+ retval = learn_buffer_len;
69306+ learn_buffer_len = 0;
69307+
69308+ spin_unlock(&gr_learn_lock);
69309+
69310+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69311+ retval = -EFAULT;
69312+
69313+ mutex_unlock(&gr_learn_user_mutex);
69314+out:
69315+ set_current_state(TASK_RUNNING);
69316+ remove_wait_queue(&learn_wait, &wait);
69317+ return retval;
69318+}
69319+
69320+static unsigned int
69321+poll_learn(struct file * file, poll_table * wait)
69322+{
69323+ poll_wait(file, &learn_wait, wait);
69324+
69325+ if (learn_buffer_len)
69326+ return (POLLIN | POLLRDNORM);
69327+
69328+ return 0;
69329+}
69330+
69331+void
69332+gr_clear_learn_entries(void)
69333+{
69334+ char *tmp;
69335+
69336+ mutex_lock(&gr_learn_user_mutex);
69337+ spin_lock(&gr_learn_lock);
69338+ tmp = learn_buffer;
69339+ learn_buffer = NULL;
69340+ spin_unlock(&gr_learn_lock);
69341+ if (tmp)
69342+ vfree(tmp);
69343+ if (learn_buffer_user != NULL) {
69344+ vfree(learn_buffer_user);
69345+ learn_buffer_user = NULL;
69346+ }
69347+ learn_buffer_len = 0;
69348+ mutex_unlock(&gr_learn_user_mutex);
69349+
69350+ return;
69351+}
69352+
69353+void
69354+gr_add_learn_entry(const char *fmt, ...)
69355+{
69356+ va_list args;
69357+ unsigned int len;
69358+
69359+ if (!gr_learn_attached)
69360+ return;
69361+
69362+ spin_lock(&gr_learn_lock);
69363+
69364+ /* leave a gap at the end so we know when it's "full" but don't have to
69365+ compute the exact length of the string we're trying to append
69366+ */
69367+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69368+ spin_unlock(&gr_learn_lock);
69369+ wake_up_interruptible(&learn_wait);
69370+ return;
69371+ }
69372+ if (learn_buffer == NULL) {
69373+ spin_unlock(&gr_learn_lock);
69374+ return;
69375+ }
69376+
69377+ va_start(args, fmt);
69378+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69379+ va_end(args);
69380+
69381+ learn_buffer_len += len + 1;
69382+
69383+ spin_unlock(&gr_learn_lock);
69384+ wake_up_interruptible(&learn_wait);
69385+
69386+ return;
69387+}
69388+
69389+static int
69390+open_learn(struct inode *inode, struct file *file)
69391+{
69392+ if (file->f_mode & FMODE_READ && gr_learn_attached)
69393+ return -EBUSY;
69394+ if (file->f_mode & FMODE_READ) {
69395+ int retval = 0;
69396+ mutex_lock(&gr_learn_user_mutex);
69397+ if (learn_buffer == NULL)
69398+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69399+ if (learn_buffer_user == NULL)
69400+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69401+ if (learn_buffer == NULL) {
69402+ retval = -ENOMEM;
69403+ goto out_error;
69404+ }
69405+ if (learn_buffer_user == NULL) {
69406+ retval = -ENOMEM;
69407+ goto out_error;
69408+ }
69409+ learn_buffer_len = 0;
69410+ learn_buffer_user_len = 0;
69411+ gr_learn_attached = 1;
69412+out_error:
69413+ mutex_unlock(&gr_learn_user_mutex);
69414+ return retval;
69415+ }
69416+ return 0;
69417+}
69418+
69419+static int
69420+close_learn(struct inode *inode, struct file *file)
69421+{
69422+ if (file->f_mode & FMODE_READ) {
69423+ char *tmp = NULL;
69424+ mutex_lock(&gr_learn_user_mutex);
69425+ spin_lock(&gr_learn_lock);
69426+ tmp = learn_buffer;
69427+ learn_buffer = NULL;
69428+ spin_unlock(&gr_learn_lock);
69429+ if (tmp)
69430+ vfree(tmp);
69431+ if (learn_buffer_user != NULL) {
69432+ vfree(learn_buffer_user);
69433+ learn_buffer_user = NULL;
69434+ }
69435+ learn_buffer_len = 0;
69436+ learn_buffer_user_len = 0;
69437+ gr_learn_attached = 0;
69438+ mutex_unlock(&gr_learn_user_mutex);
69439+ }
69440+
69441+ return 0;
69442+}
69443+
69444+const struct file_operations grsec_fops = {
69445+ .read = read_learn,
69446+ .write = write_grsec_handler,
69447+ .open = open_learn,
69448+ .release = close_learn,
69449+ .poll = poll_learn,
69450+};
69451diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
69452new file mode 100644
69453index 0000000..361a099
69454--- /dev/null
69455+++ b/grsecurity/gracl_policy.c
69456@@ -0,0 +1,1782 @@
69457+#include <linux/kernel.h>
69458+#include <linux/module.h>
69459+#include <linux/sched.h>
69460+#include <linux/mm.h>
69461+#include <linux/file.h>
69462+#include <linux/fs.h>
69463+#include <linux/namei.h>
69464+#include <linux/mount.h>
69465+#include <linux/tty.h>
69466+#include <linux/proc_fs.h>
69467+#include <linux/lglock.h>
69468+#include <linux/slab.h>
69469+#include <linux/vmalloc.h>
69470+#include <linux/types.h>
69471+#include <linux/sysctl.h>
69472+#include <linux/netdevice.h>
69473+#include <linux/ptrace.h>
69474+#include <linux/gracl.h>
69475+#include <linux/gralloc.h>
69476+#include <linux/security.h>
69477+#include <linux/grinternal.h>
69478+#include <linux/pid_namespace.h>
69479+#include <linux/stop_machine.h>
69480+#include <linux/fdtable.h>
69481+#include <linux/percpu.h>
69482+#include <linux/lglock.h>
69483+#include <linux/hugetlb.h>
69484+#include <linux/posix-timers.h>
69485+#include "../fs/mount.h"
69486+
69487+#include <asm/uaccess.h>
69488+#include <asm/errno.h>
69489+#include <asm/mman.h>
69490+
69491+extern struct gr_policy_state *polstate;
69492+
69493+#define FOR_EACH_ROLE_START(role) \
69494+ role = polstate->role_list; \
69495+ while (role) {
69496+
69497+#define FOR_EACH_ROLE_END(role) \
69498+ role = role->prev; \
69499+ }
69500+
69501+struct path gr_real_root;
69502+
69503+extern struct gr_alloc_state *current_alloc_state;
69504+
69505+u16 acl_sp_role_value;
69506+
69507+static DEFINE_MUTEX(gr_dev_mutex);
69508+
69509+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
69510+extern void gr_clear_learn_entries(void);
69511+
69512+static struct gr_arg gr_usermode;
69513+static unsigned char gr_system_salt[GR_SALT_LEN];
69514+static unsigned char gr_system_sum[GR_SHA_LEN];
69515+
69516+static unsigned int gr_auth_attempts = 0;
69517+static unsigned long gr_auth_expires = 0UL;
69518+
69519+struct acl_object_label *fakefs_obj_rw;
69520+struct acl_object_label *fakefs_obj_rwx;
69521+
69522+extern int gr_init_uidset(void);
69523+extern void gr_free_uidset(void);
69524+extern void gr_remove_uid(uid_t uid);
69525+extern int gr_find_uid(uid_t uid);
69526+
69527+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
69528+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
69529+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
69530+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
69531+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);
69532+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
69533+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
69534+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
69535+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
69536+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69537+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69538+extern void assign_special_role(const char *rolename);
69539+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
69540+extern int gr_rbac_disable(void *unused);
69541+extern void gr_enable_rbac_system(void);
69542+
69543+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
69544+{
69545+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
69546+ return -EFAULT;
69547+
69548+ return 0;
69549+}
69550+
69551+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69552+{
69553+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
69554+ return -EFAULT;
69555+
69556+ return 0;
69557+}
69558+
69559+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69560+{
69561+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
69562+ return -EFAULT;
69563+
69564+ return 0;
69565+}
69566+
69567+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
69568+{
69569+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
69570+ return -EFAULT;
69571+
69572+ return 0;
69573+}
69574+
69575+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69576+{
69577+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
69578+ return -EFAULT;
69579+
69580+ return 0;
69581+}
69582+
69583+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69584+{
69585+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
69586+ return -EFAULT;
69587+
69588+ return 0;
69589+}
69590+
69591+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69592+{
69593+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
69594+ return -EFAULT;
69595+
69596+ return 0;
69597+}
69598+
69599+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
69600+{
69601+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
69602+ return -EFAULT;
69603+
69604+ return 0;
69605+}
69606+
69607+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
69608+{
69609+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
69610+ return -EFAULT;
69611+
69612+ return 0;
69613+}
69614+
69615+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
69616+{
69617+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
69618+ return -EFAULT;
69619+
69620+ if (((uwrap->version != GRSECURITY_VERSION) &&
69621+ (uwrap->version != 0x2901)) ||
69622+ (uwrap->size != sizeof(struct gr_arg)))
69623+ return -EINVAL;
69624+
69625+ return 0;
69626+}
69627+
69628+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
69629+{
69630+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
69631+ return -EFAULT;
69632+
69633+ return 0;
69634+}
69635+
69636+static size_t get_gr_arg_wrapper_size_normal(void)
69637+{
69638+ return sizeof(struct gr_arg_wrapper);
69639+}
69640+
69641+#ifdef CONFIG_COMPAT
69642+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
69643+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
69644+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
69645+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
69646+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
69647+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
69648+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
69649+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
69650+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
69651+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
69652+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
69653+extern size_t get_gr_arg_wrapper_size_compat(void);
69654+
69655+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
69656+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
69657+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
69658+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
69659+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
69660+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
69661+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
69662+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
69663+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
69664+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
69665+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
69666+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
69667+
69668+#else
69669+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
69670+#define copy_gr_arg copy_gr_arg_normal
69671+#define copy_gr_hash_struct copy_gr_hash_struct_normal
69672+#define copy_acl_object_label copy_acl_object_label_normal
69673+#define copy_acl_subject_label copy_acl_subject_label_normal
69674+#define copy_acl_role_label copy_acl_role_label_normal
69675+#define copy_acl_ip_label copy_acl_ip_label_normal
69676+#define copy_pointer_from_array copy_pointer_from_array_normal
69677+#define copy_sprole_pw copy_sprole_pw_normal
69678+#define copy_role_transition copy_role_transition_normal
69679+#define copy_role_allowed_ip copy_role_allowed_ip_normal
69680+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
69681+#endif
69682+
69683+static struct acl_subject_label *
69684+lookup_subject_map(const struct acl_subject_label *userp)
69685+{
69686+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
69687+ struct subject_map *match;
69688+
69689+ match = polstate->subj_map_set.s_hash[index];
69690+
69691+ while (match && match->user != userp)
69692+ match = match->next;
69693+
69694+ if (match != NULL)
69695+ return match->kernel;
69696+ else
69697+ return NULL;
69698+}
69699+
69700+static void
69701+insert_subj_map_entry(struct subject_map *subjmap)
69702+{
69703+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
69704+ struct subject_map **curr;
69705+
69706+ subjmap->prev = NULL;
69707+
69708+ curr = &polstate->subj_map_set.s_hash[index];
69709+ if (*curr != NULL)
69710+ (*curr)->prev = subjmap;
69711+
69712+ subjmap->next = *curr;
69713+ *curr = subjmap;
69714+
69715+ return;
69716+}
69717+
69718+static void
69719+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
69720+{
69721+ unsigned int index =
69722+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
69723+ struct acl_role_label **curr;
69724+ struct acl_role_label *tmp, *tmp2;
69725+
69726+ curr = &polstate->acl_role_set.r_hash[index];
69727+
69728+ /* simple case, slot is empty, just set it to our role */
69729+ if (*curr == NULL) {
69730+ *curr = role;
69731+ } else {
69732+ /* example:
69733+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
69734+ 2 -> 3
69735+ */
69736+ /* first check to see if we can already be reached via this slot */
69737+ tmp = *curr;
69738+ while (tmp && tmp != role)
69739+ tmp = tmp->next;
69740+ if (tmp == role) {
69741+ /* we don't need to add ourselves to this slot's chain */
69742+ return;
69743+ }
69744+ /* we need to add ourselves to this chain, two cases */
69745+ if (role->next == NULL) {
69746+ /* simple case, append the current chain to our role */
69747+ role->next = *curr;
69748+ *curr = role;
69749+ } else {
69750+ /* 1 -> 2 -> 3 -> 4
69751+ 2 -> 3 -> 4
69752+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
69753+ */
69754+ /* trickier case: walk our role's chain until we find
69755+ the role for the start of the current slot's chain */
69756+ tmp = role;
69757+ tmp2 = *curr;
69758+ while (tmp->next && tmp->next != tmp2)
69759+ tmp = tmp->next;
69760+ if (tmp->next == tmp2) {
69761+ /* from example above, we found 3, so just
69762+ replace this slot's chain with ours */
69763+ *curr = role;
69764+ } else {
69765+ /* we didn't find a subset of our role's chain
69766+ in the current slot's chain, so append their
69767+ chain to ours, and set us as the first role in
69768+ the slot's chain
69769+
69770+ we could fold this case with the case above,
69771+ but making it explicit for clarity
69772+ */
69773+ tmp->next = tmp2;
69774+ *curr = role;
69775+ }
69776+ }
69777+ }
69778+
69779+ return;
69780+}
69781+
69782+static void
69783+insert_acl_role_label(struct acl_role_label *role)
69784+{
69785+ int i;
69786+
69787+ if (polstate->role_list == NULL) {
69788+ polstate->role_list = role;
69789+ role->prev = NULL;
69790+ } else {
69791+ role->prev = polstate->role_list;
69792+ polstate->role_list = role;
69793+ }
69794+
69795+ /* used for hash chains */
69796+ role->next = NULL;
69797+
69798+ if (role->roletype & GR_ROLE_DOMAIN) {
69799+ for (i = 0; i < role->domain_child_num; i++)
69800+ __insert_acl_role_label(role, role->domain_children[i]);
69801+ } else
69802+ __insert_acl_role_label(role, role->uidgid);
69803+}
69804+
69805+static int
69806+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
69807+{
69808+ struct name_entry **curr, *nentry;
69809+ struct inodev_entry *ientry;
69810+ unsigned int len = strlen(name);
69811+ unsigned int key = full_name_hash(name, len);
69812+ unsigned int index = key % polstate->name_set.n_size;
69813+
69814+ curr = &polstate->name_set.n_hash[index];
69815+
69816+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
69817+ curr = &((*curr)->next);
69818+
69819+ if (*curr != NULL)
69820+ return 1;
69821+
69822+ nentry = acl_alloc(sizeof (struct name_entry));
69823+ if (nentry == NULL)
69824+ return 0;
69825+ ientry = acl_alloc(sizeof (struct inodev_entry));
69826+ if (ientry == NULL)
69827+ return 0;
69828+ ientry->nentry = nentry;
69829+
69830+ nentry->key = key;
69831+ nentry->name = name;
69832+ nentry->inode = inode;
69833+ nentry->device = device;
69834+ nentry->len = len;
69835+ nentry->deleted = deleted;
69836+
69837+ nentry->prev = NULL;
69838+ curr = &polstate->name_set.n_hash[index];
69839+ if (*curr != NULL)
69840+ (*curr)->prev = nentry;
69841+ nentry->next = *curr;
69842+ *curr = nentry;
69843+
69844+ /* insert us into the table searchable by inode/dev */
69845+ __insert_inodev_entry(polstate, ientry);
69846+
69847+ return 1;
69848+}
69849+
69850+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
69851+
69852+static void *
69853+create_table(__u32 * len, int elementsize)
69854+{
69855+ unsigned int table_sizes[] = {
69856+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
69857+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
69858+ 4194301, 8388593, 16777213, 33554393, 67108859
69859+ };
69860+ void *newtable = NULL;
69861+ unsigned int pwr = 0;
69862+
69863+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
69864+ table_sizes[pwr] <= *len)
69865+ pwr++;
69866+
69867+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
69868+ return newtable;
69869+
69870+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
69871+ newtable =
69872+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
69873+ else
69874+ newtable = vmalloc(table_sizes[pwr] * elementsize);
69875+
69876+ *len = table_sizes[pwr];
69877+
69878+ return newtable;
69879+}
69880+
69881+static int
69882+init_variables(const struct gr_arg *arg, bool reload)
69883+{
69884+ struct task_struct *reaper = init_pid_ns.child_reaper;
69885+ unsigned int stacksize;
69886+
69887+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
69888+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
69889+ polstate->name_set.n_size = arg->role_db.num_objects;
69890+ polstate->inodev_set.i_size = arg->role_db.num_objects;
69891+
69892+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
69893+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
69894+ return 1;
69895+
69896+ if (!reload) {
69897+ if (!gr_init_uidset())
69898+ return 1;
69899+ }
69900+
69901+ /* set up the stack that holds allocation info */
69902+
69903+ stacksize = arg->role_db.num_pointers + 5;
69904+
69905+ if (!acl_alloc_stack_init(stacksize))
69906+ return 1;
69907+
69908+ if (!reload) {
69909+ /* grab reference for the real root dentry and vfsmount */
69910+ get_fs_root(reaper->fs, &gr_real_root);
69911+
69912+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69913+ 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);
69914+#endif
69915+
69916+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
69917+ if (fakefs_obj_rw == NULL)
69918+ return 1;
69919+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
69920+
69921+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
69922+ if (fakefs_obj_rwx == NULL)
69923+ return 1;
69924+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
69925+ }
69926+
69927+ polstate->subj_map_set.s_hash =
69928+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
69929+ polstate->acl_role_set.r_hash =
69930+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
69931+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
69932+ polstate->inodev_set.i_hash =
69933+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
69934+
69935+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
69936+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
69937+ return 1;
69938+
69939+ memset(polstate->subj_map_set.s_hash, 0,
69940+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
69941+ memset(polstate->acl_role_set.r_hash, 0,
69942+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
69943+ memset(polstate->name_set.n_hash, 0,
69944+ sizeof (struct name_entry *) * polstate->name_set.n_size);
69945+ memset(polstate->inodev_set.i_hash, 0,
69946+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
69947+
69948+ return 0;
69949+}
69950+
69951+/* free information not needed after startup
69952+ currently contains user->kernel pointer mappings for subjects
69953+*/
69954+
69955+static void
69956+free_init_variables(void)
69957+{
69958+ __u32 i;
69959+
69960+ if (polstate->subj_map_set.s_hash) {
69961+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
69962+ if (polstate->subj_map_set.s_hash[i]) {
69963+ kfree(polstate->subj_map_set.s_hash[i]);
69964+ polstate->subj_map_set.s_hash[i] = NULL;
69965+ }
69966+ }
69967+
69968+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
69969+ PAGE_SIZE)
69970+ kfree(polstate->subj_map_set.s_hash);
69971+ else
69972+ vfree(polstate->subj_map_set.s_hash);
69973+ }
69974+
69975+ return;
69976+}
69977+
69978+static void
69979+free_variables(bool reload)
69980+{
69981+ struct acl_subject_label *s;
69982+ struct acl_role_label *r;
69983+ struct task_struct *task, *task2;
69984+ unsigned int x;
69985+
69986+ if (!reload) {
69987+ gr_clear_learn_entries();
69988+
69989+ read_lock(&tasklist_lock);
69990+ do_each_thread(task2, task) {
69991+ task->acl_sp_role = 0;
69992+ task->acl_role_id = 0;
69993+ task->inherited = 0;
69994+ task->acl = NULL;
69995+ task->role = NULL;
69996+ } while_each_thread(task2, task);
69997+ read_unlock(&tasklist_lock);
69998+
69999+ kfree(fakefs_obj_rw);
70000+ fakefs_obj_rw = NULL;
70001+ kfree(fakefs_obj_rwx);
70002+ fakefs_obj_rwx = NULL;
70003+
70004+ /* release the reference to the real root dentry and vfsmount */
70005+ path_put(&gr_real_root);
70006+ memset(&gr_real_root, 0, sizeof(gr_real_root));
70007+ }
70008+
70009+ /* free all object hash tables */
70010+
70011+ FOR_EACH_ROLE_START(r)
70012+ if (r->subj_hash == NULL)
70013+ goto next_role;
70014+ FOR_EACH_SUBJECT_START(r, s, x)
70015+ if (s->obj_hash == NULL)
70016+ break;
70017+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70018+ kfree(s->obj_hash);
70019+ else
70020+ vfree(s->obj_hash);
70021+ FOR_EACH_SUBJECT_END(s, x)
70022+ FOR_EACH_NESTED_SUBJECT_START(r, s)
70023+ if (s->obj_hash == NULL)
70024+ break;
70025+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70026+ kfree(s->obj_hash);
70027+ else
70028+ vfree(s->obj_hash);
70029+ FOR_EACH_NESTED_SUBJECT_END(s)
70030+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
70031+ kfree(r->subj_hash);
70032+ else
70033+ vfree(r->subj_hash);
70034+ r->subj_hash = NULL;
70035+next_role:
70036+ FOR_EACH_ROLE_END(r)
70037+
70038+ acl_free_all();
70039+
70040+ if (polstate->acl_role_set.r_hash) {
70041+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
70042+ PAGE_SIZE)
70043+ kfree(polstate->acl_role_set.r_hash);
70044+ else
70045+ vfree(polstate->acl_role_set.r_hash);
70046+ }
70047+ if (polstate->name_set.n_hash) {
70048+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
70049+ PAGE_SIZE)
70050+ kfree(polstate->name_set.n_hash);
70051+ else
70052+ vfree(polstate->name_set.n_hash);
70053+ }
70054+
70055+ if (polstate->inodev_set.i_hash) {
70056+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
70057+ PAGE_SIZE)
70058+ kfree(polstate->inodev_set.i_hash);
70059+ else
70060+ vfree(polstate->inodev_set.i_hash);
70061+ }
70062+
70063+ if (!reload)
70064+ gr_free_uidset();
70065+
70066+ memset(&polstate->name_set, 0, sizeof (struct name_db));
70067+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
70068+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
70069+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
70070+
70071+ polstate->default_role = NULL;
70072+ polstate->kernel_role = NULL;
70073+ polstate->role_list = NULL;
70074+
70075+ return;
70076+}
70077+
70078+static struct acl_subject_label *
70079+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
70080+
70081+static int alloc_and_copy_string(char **name, unsigned int maxlen)
70082+{
70083+ unsigned int len = strnlen_user(*name, maxlen);
70084+ char *tmp;
70085+
70086+ if (!len || len >= maxlen)
70087+ return -EINVAL;
70088+
70089+ if ((tmp = (char *) acl_alloc(len)) == NULL)
70090+ return -ENOMEM;
70091+
70092+ if (copy_from_user(tmp, *name, len))
70093+ return -EFAULT;
70094+
70095+ tmp[len-1] = '\0';
70096+ *name = tmp;
70097+
70098+ return 0;
70099+}
70100+
70101+static int
70102+copy_user_glob(struct acl_object_label *obj)
70103+{
70104+ struct acl_object_label *g_tmp, **guser;
70105+ int error;
70106+
70107+ if (obj->globbed == NULL)
70108+ return 0;
70109+
70110+ guser = &obj->globbed;
70111+ while (*guser) {
70112+ g_tmp = (struct acl_object_label *)
70113+ acl_alloc(sizeof (struct acl_object_label));
70114+ if (g_tmp == NULL)
70115+ return -ENOMEM;
70116+
70117+ if (copy_acl_object_label(g_tmp, *guser))
70118+ return -EFAULT;
70119+
70120+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
70121+ if (error)
70122+ return error;
70123+
70124+ *guser = g_tmp;
70125+ guser = &(g_tmp->next);
70126+ }
70127+
70128+ return 0;
70129+}
70130+
70131+static int
70132+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
70133+ struct acl_role_label *role)
70134+{
70135+ struct acl_object_label *o_tmp;
70136+ int ret;
70137+
70138+ while (userp) {
70139+ if ((o_tmp = (struct acl_object_label *)
70140+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
70141+ return -ENOMEM;
70142+
70143+ if (copy_acl_object_label(o_tmp, userp))
70144+ return -EFAULT;
70145+
70146+ userp = o_tmp->prev;
70147+
70148+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
70149+ if (ret)
70150+ return ret;
70151+
70152+ insert_acl_obj_label(o_tmp, subj);
70153+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
70154+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
70155+ return -ENOMEM;
70156+
70157+ ret = copy_user_glob(o_tmp);
70158+ if (ret)
70159+ return ret;
70160+
70161+ if (o_tmp->nested) {
70162+ int already_copied;
70163+
70164+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
70165+ if (IS_ERR(o_tmp->nested))
70166+ return PTR_ERR(o_tmp->nested);
70167+
70168+ /* insert into nested subject list if we haven't copied this one yet
70169+ to prevent duplicate entries */
70170+ if (!already_copied) {
70171+ o_tmp->nested->next = role->hash->first;
70172+ role->hash->first = o_tmp->nested;
70173+ }
70174+ }
70175+ }
70176+
70177+ return 0;
70178+}
70179+
70180+static __u32
70181+count_user_subjs(struct acl_subject_label *userp)
70182+{
70183+ struct acl_subject_label s_tmp;
70184+ __u32 num = 0;
70185+
70186+ while (userp) {
70187+ if (copy_acl_subject_label(&s_tmp, userp))
70188+ break;
70189+
70190+ userp = s_tmp.prev;
70191+ }
70192+
70193+ return num;
70194+}
70195+
70196+static int
70197+copy_user_allowedips(struct acl_role_label *rolep)
70198+{
70199+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
70200+
70201+ ruserip = rolep->allowed_ips;
70202+
70203+ while (ruserip) {
70204+ rlast = rtmp;
70205+
70206+ if ((rtmp = (struct role_allowed_ip *)
70207+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
70208+ return -ENOMEM;
70209+
70210+ if (copy_role_allowed_ip(rtmp, ruserip))
70211+ return -EFAULT;
70212+
70213+ ruserip = rtmp->prev;
70214+
70215+ if (!rlast) {
70216+ rtmp->prev = NULL;
70217+ rolep->allowed_ips = rtmp;
70218+ } else {
70219+ rlast->next = rtmp;
70220+ rtmp->prev = rlast;
70221+ }
70222+
70223+ if (!ruserip)
70224+ rtmp->next = NULL;
70225+ }
70226+
70227+ return 0;
70228+}
70229+
70230+static int
70231+copy_user_transitions(struct acl_role_label *rolep)
70232+{
70233+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
70234+ int error;
70235+
70236+ rusertp = rolep->transitions;
70237+
70238+ while (rusertp) {
70239+ rlast = rtmp;
70240+
70241+ if ((rtmp = (struct role_transition *)
70242+ acl_alloc(sizeof (struct role_transition))) == NULL)
70243+ return -ENOMEM;
70244+
70245+ if (copy_role_transition(rtmp, rusertp))
70246+ return -EFAULT;
70247+
70248+ rusertp = rtmp->prev;
70249+
70250+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
70251+ if (error)
70252+ return error;
70253+
70254+ if (!rlast) {
70255+ rtmp->prev = NULL;
70256+ rolep->transitions = rtmp;
70257+ } else {
70258+ rlast->next = rtmp;
70259+ rtmp->prev = rlast;
70260+ }
70261+
70262+ if (!rusertp)
70263+ rtmp->next = NULL;
70264+ }
70265+
70266+ return 0;
70267+}
70268+
70269+static __u32 count_user_objs(const struct acl_object_label __user *userp)
70270+{
70271+ struct acl_object_label o_tmp;
70272+ __u32 num = 0;
70273+
70274+ while (userp) {
70275+ if (copy_acl_object_label(&o_tmp, userp))
70276+ break;
70277+
70278+ userp = o_tmp.prev;
70279+ num++;
70280+ }
70281+
70282+ return num;
70283+}
70284+
70285+static struct acl_subject_label *
70286+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
70287+{
70288+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
70289+ __u32 num_objs;
70290+ struct acl_ip_label **i_tmp, *i_utmp2;
70291+ struct gr_hash_struct ghash;
70292+ struct subject_map *subjmap;
70293+ unsigned int i_num;
70294+ int err;
70295+
70296+ if (already_copied != NULL)
70297+ *already_copied = 0;
70298+
70299+ s_tmp = lookup_subject_map(userp);
70300+
70301+ /* we've already copied this subject into the kernel, just return
70302+ the reference to it, and don't copy it over again
70303+ */
70304+ if (s_tmp) {
70305+ if (already_copied != NULL)
70306+ *already_copied = 1;
70307+ return(s_tmp);
70308+ }
70309+
70310+ if ((s_tmp = (struct acl_subject_label *)
70311+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
70312+ return ERR_PTR(-ENOMEM);
70313+
70314+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
70315+ if (subjmap == NULL)
70316+ return ERR_PTR(-ENOMEM);
70317+
70318+ subjmap->user = userp;
70319+ subjmap->kernel = s_tmp;
70320+ insert_subj_map_entry(subjmap);
70321+
70322+ if (copy_acl_subject_label(s_tmp, userp))
70323+ return ERR_PTR(-EFAULT);
70324+
70325+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
70326+ if (err)
70327+ return ERR_PTR(err);
70328+
70329+ if (!strcmp(s_tmp->filename, "/"))
70330+ role->root_label = s_tmp;
70331+
70332+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
70333+ return ERR_PTR(-EFAULT);
70334+
70335+ /* copy user and group transition tables */
70336+
70337+ if (s_tmp->user_trans_num) {
70338+ uid_t *uidlist;
70339+
70340+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
70341+ if (uidlist == NULL)
70342+ return ERR_PTR(-ENOMEM);
70343+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
70344+ return ERR_PTR(-EFAULT);
70345+
70346+ s_tmp->user_transitions = uidlist;
70347+ }
70348+
70349+ if (s_tmp->group_trans_num) {
70350+ gid_t *gidlist;
70351+
70352+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
70353+ if (gidlist == NULL)
70354+ return ERR_PTR(-ENOMEM);
70355+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
70356+ return ERR_PTR(-EFAULT);
70357+
70358+ s_tmp->group_transitions = gidlist;
70359+ }
70360+
70361+ /* set up object hash table */
70362+ num_objs = count_user_objs(ghash.first);
70363+
70364+ s_tmp->obj_hash_size = num_objs;
70365+ s_tmp->obj_hash =
70366+ (struct acl_object_label **)
70367+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
70368+
70369+ if (!s_tmp->obj_hash)
70370+ return ERR_PTR(-ENOMEM);
70371+
70372+ memset(s_tmp->obj_hash, 0,
70373+ s_tmp->obj_hash_size *
70374+ sizeof (struct acl_object_label *));
70375+
70376+ /* add in objects */
70377+ err = copy_user_objs(ghash.first, s_tmp, role);
70378+
70379+ if (err)
70380+ return ERR_PTR(err);
70381+
70382+ /* set pointer for parent subject */
70383+ if (s_tmp->parent_subject) {
70384+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
70385+
70386+ if (IS_ERR(s_tmp2))
70387+ return s_tmp2;
70388+
70389+ s_tmp->parent_subject = s_tmp2;
70390+ }
70391+
70392+ /* add in ip acls */
70393+
70394+ if (!s_tmp->ip_num) {
70395+ s_tmp->ips = NULL;
70396+ goto insert;
70397+ }
70398+
70399+ i_tmp =
70400+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
70401+ sizeof (struct acl_ip_label *));
70402+
70403+ if (!i_tmp)
70404+ return ERR_PTR(-ENOMEM);
70405+
70406+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
70407+ *(i_tmp + i_num) =
70408+ (struct acl_ip_label *)
70409+ acl_alloc(sizeof (struct acl_ip_label));
70410+ if (!*(i_tmp + i_num))
70411+ return ERR_PTR(-ENOMEM);
70412+
70413+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
70414+ return ERR_PTR(-EFAULT);
70415+
70416+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
70417+ return ERR_PTR(-EFAULT);
70418+
70419+ if ((*(i_tmp + i_num))->iface == NULL)
70420+ continue;
70421+
70422+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
70423+ if (err)
70424+ return ERR_PTR(err);
70425+ }
70426+
70427+ s_tmp->ips = i_tmp;
70428+
70429+insert:
70430+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
70431+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
70432+ return ERR_PTR(-ENOMEM);
70433+
70434+ return s_tmp;
70435+}
70436+
70437+static int
70438+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
70439+{
70440+ struct acl_subject_label s_pre;
70441+ struct acl_subject_label * ret;
70442+ int err;
70443+
70444+ while (userp) {
70445+ if (copy_acl_subject_label(&s_pre, userp))
70446+ return -EFAULT;
70447+
70448+ ret = do_copy_user_subj(userp, role, NULL);
70449+
70450+ err = PTR_ERR(ret);
70451+ if (IS_ERR(ret))
70452+ return err;
70453+
70454+ insert_acl_subj_label(ret, role);
70455+
70456+ userp = s_pre.prev;
70457+ }
70458+
70459+ return 0;
70460+}
70461+
70462+static int
70463+copy_user_acl(struct gr_arg *arg)
70464+{
70465+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
70466+ struct acl_subject_label *subj_list;
70467+ struct sprole_pw *sptmp;
70468+ struct gr_hash_struct *ghash;
70469+ uid_t *domainlist;
70470+ unsigned int r_num;
70471+ int err = 0;
70472+ __u16 i;
70473+ __u32 num_subjs;
70474+
70475+ /* we need a default and kernel role */
70476+ if (arg->role_db.num_roles < 2)
70477+ return -EINVAL;
70478+
70479+ /* copy special role authentication info from userspace */
70480+
70481+ polstate->num_sprole_pws = arg->num_sprole_pws;
70482+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
70483+
70484+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
70485+ return -ENOMEM;
70486+
70487+ for (i = 0; i < polstate->num_sprole_pws; i++) {
70488+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
70489+ if (!sptmp)
70490+ return -ENOMEM;
70491+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
70492+ return -EFAULT;
70493+
70494+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
70495+ if (err)
70496+ return err;
70497+
70498+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70499+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
70500+#endif
70501+
70502+ polstate->acl_special_roles[i] = sptmp;
70503+ }
70504+
70505+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
70506+
70507+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
70508+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
70509+
70510+ if (!r_tmp)
70511+ return -ENOMEM;
70512+
70513+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
70514+ return -EFAULT;
70515+
70516+ if (copy_acl_role_label(r_tmp, r_utmp2))
70517+ return -EFAULT;
70518+
70519+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
70520+ if (err)
70521+ return err;
70522+
70523+ if (!strcmp(r_tmp->rolename, "default")
70524+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
70525+ polstate->default_role = r_tmp;
70526+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
70527+ polstate->kernel_role = r_tmp;
70528+ }
70529+
70530+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
70531+ return -ENOMEM;
70532+
70533+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
70534+ return -EFAULT;
70535+
70536+ r_tmp->hash = ghash;
70537+
70538+ num_subjs = count_user_subjs(r_tmp->hash->first);
70539+
70540+ r_tmp->subj_hash_size = num_subjs;
70541+ r_tmp->subj_hash =
70542+ (struct acl_subject_label **)
70543+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
70544+
70545+ if (!r_tmp->subj_hash)
70546+ return -ENOMEM;
70547+
70548+ err = copy_user_allowedips(r_tmp);
70549+ if (err)
70550+ return err;
70551+
70552+ /* copy domain info */
70553+ if (r_tmp->domain_children != NULL) {
70554+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
70555+ if (domainlist == NULL)
70556+ return -ENOMEM;
70557+
70558+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
70559+ return -EFAULT;
70560+
70561+ r_tmp->domain_children = domainlist;
70562+ }
70563+
70564+ err = copy_user_transitions(r_tmp);
70565+ if (err)
70566+ return err;
70567+
70568+ memset(r_tmp->subj_hash, 0,
70569+ r_tmp->subj_hash_size *
70570+ sizeof (struct acl_subject_label *));
70571+
70572+ /* acquire the list of subjects, then NULL out
70573+ the list prior to parsing the subjects for this role,
70574+ as during this parsing the list is replaced with a list
70575+ of *nested* subjects for the role
70576+ */
70577+ subj_list = r_tmp->hash->first;
70578+
70579+ /* set nested subject list to null */
70580+ r_tmp->hash->first = NULL;
70581+
70582+ err = copy_user_subjs(subj_list, r_tmp);
70583+
70584+ if (err)
70585+ return err;
70586+
70587+ insert_acl_role_label(r_tmp);
70588+ }
70589+
70590+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
70591+ return -EINVAL;
70592+
70593+ return err;
70594+}
70595+
70596+static int gracl_reload_apply_policies(void *reload)
70597+{
70598+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
70599+ struct task_struct *task, *task2;
70600+ struct acl_role_label *role, *rtmp;
70601+ struct acl_subject_label *subj;
70602+ const struct cred *cred;
70603+ int role_applied;
70604+ int ret = 0;
70605+
70606+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
70607+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
70608+
70609+ /* first make sure we'll be able to apply the new policy cleanly */
70610+ do_each_thread(task2, task) {
70611+ if (task->exec_file == NULL)
70612+ continue;
70613+ role_applied = 0;
70614+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70615+ /* preserve special roles */
70616+ FOR_EACH_ROLE_START(role)
70617+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70618+ rtmp = task->role;
70619+ task->role = role;
70620+ role_applied = 1;
70621+ break;
70622+ }
70623+ FOR_EACH_ROLE_END(role)
70624+ }
70625+ if (!role_applied) {
70626+ cred = __task_cred(task);
70627+ rtmp = task->role;
70628+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70629+ }
70630+ /* this handles non-nested inherited subjects, nested subjects will still
70631+ be dropped currently */
70632+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70633+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
70634+ /* change the role back so that we've made no modifications to the policy */
70635+ task->role = rtmp;
70636+
70637+ if (subj == NULL || task->tmpacl == NULL) {
70638+ ret = -EINVAL;
70639+ goto out;
70640+ }
70641+ } while_each_thread(task2, task);
70642+
70643+ /* now actually apply the policy */
70644+
70645+ do_each_thread(task2, task) {
70646+ if (task->exec_file) {
70647+ role_applied = 0;
70648+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70649+ /* preserve special roles */
70650+ FOR_EACH_ROLE_START(role)
70651+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70652+ task->role = role;
70653+ role_applied = 1;
70654+ break;
70655+ }
70656+ FOR_EACH_ROLE_END(role)
70657+ }
70658+ if (!role_applied) {
70659+ cred = __task_cred(task);
70660+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70661+ }
70662+ /* this handles non-nested inherited subjects, nested subjects will still
70663+ be dropped currently */
70664+ if (!reload_state->oldmode && task->inherited)
70665+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70666+ else {
70667+ /* looked up and tagged to the task previously */
70668+ subj = task->tmpacl;
70669+ }
70670+ /* subj will be non-null */
70671+ __gr_apply_subject_to_task(polstate, task, subj);
70672+ if (reload_state->oldmode) {
70673+ task->acl_role_id = 0;
70674+ task->acl_sp_role = 0;
70675+ task->inherited = 0;
70676+ }
70677+ } else {
70678+ // it's a kernel process
70679+ task->role = polstate->kernel_role;
70680+ task->acl = polstate->kernel_role->root_label;
70681+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
70682+ task->acl->mode &= ~GR_PROCFIND;
70683+#endif
70684+ }
70685+ } while_each_thread(task2, task);
70686+
70687+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
70688+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
70689+
70690+out:
70691+
70692+ return ret;
70693+}
70694+
70695+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
70696+{
70697+ struct gr_reload_state new_reload_state = { };
70698+ int err;
70699+
70700+ new_reload_state.oldpolicy_ptr = polstate;
70701+ new_reload_state.oldalloc_ptr = current_alloc_state;
70702+ new_reload_state.oldmode = oldmode;
70703+
70704+ current_alloc_state = &new_reload_state.newalloc;
70705+ polstate = &new_reload_state.newpolicy;
70706+
70707+ /* everything relevant is now saved off, copy in the new policy */
70708+ if (init_variables(args, true)) {
70709+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70710+ err = -ENOMEM;
70711+ goto error;
70712+ }
70713+
70714+ err = copy_user_acl(args);
70715+ free_init_variables();
70716+ if (err)
70717+ goto error;
70718+ /* the new policy is copied in, with the old policy available via saved_state
70719+ first go through applying roles, making sure to preserve special roles
70720+ then apply new subjects, making sure to preserve inherited and nested subjects,
70721+ though currently only inherited subjects will be preserved
70722+ */
70723+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
70724+ if (err)
70725+ goto error;
70726+
70727+ /* we've now applied the new policy, so restore the old policy state to free it */
70728+ polstate = &new_reload_state.oldpolicy;
70729+ current_alloc_state = &new_reload_state.oldalloc;
70730+ free_variables(true);
70731+
70732+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
70733+ to running_polstate/current_alloc_state inside stop_machine
70734+ */
70735+ err = 0;
70736+ goto out;
70737+error:
70738+ /* on error of loading the new policy, we'll just keep the previous
70739+ policy set around
70740+ */
70741+ free_variables(true);
70742+
70743+ /* doesn't affect runtime, but maintains consistent state */
70744+out:
70745+ polstate = new_reload_state.oldpolicy_ptr;
70746+ current_alloc_state = new_reload_state.oldalloc_ptr;
70747+
70748+ return err;
70749+}
70750+
70751+static int
70752+gracl_init(struct gr_arg *args)
70753+{
70754+ int error = 0;
70755+
70756+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
70757+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
70758+
70759+ if (init_variables(args, false)) {
70760+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70761+ error = -ENOMEM;
70762+ goto out;
70763+ }
70764+
70765+ error = copy_user_acl(args);
70766+ free_init_variables();
70767+ if (error)
70768+ goto out;
70769+
70770+ error = gr_set_acls(0);
70771+ if (error)
70772+ goto out;
70773+
70774+ gr_enable_rbac_system();
70775+
70776+ return 0;
70777+
70778+out:
70779+ free_variables(false);
70780+ return error;
70781+}
70782+
70783+static int
70784+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
70785+ unsigned char **sum)
70786+{
70787+ struct acl_role_label *r;
70788+ struct role_allowed_ip *ipp;
70789+ struct role_transition *trans;
70790+ unsigned int i;
70791+ int found = 0;
70792+ u32 curr_ip = current->signal->curr_ip;
70793+
70794+ current->signal->saved_ip = curr_ip;
70795+
70796+ /* check transition table */
70797+
70798+ for (trans = current->role->transitions; trans; trans = trans->next) {
70799+ if (!strcmp(rolename, trans->rolename)) {
70800+ found = 1;
70801+ break;
70802+ }
70803+ }
70804+
70805+ if (!found)
70806+ return 0;
70807+
70808+ /* handle special roles that do not require authentication
70809+ and check ip */
70810+
70811+ FOR_EACH_ROLE_START(r)
70812+ if (!strcmp(rolename, r->rolename) &&
70813+ (r->roletype & GR_ROLE_SPECIAL)) {
70814+ found = 0;
70815+ if (r->allowed_ips != NULL) {
70816+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
70817+ if ((ntohl(curr_ip) & ipp->netmask) ==
70818+ (ntohl(ipp->addr) & ipp->netmask))
70819+ found = 1;
70820+ }
70821+ } else
70822+ found = 2;
70823+ if (!found)
70824+ return 0;
70825+
70826+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
70827+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
70828+ *salt = NULL;
70829+ *sum = NULL;
70830+ return 1;
70831+ }
70832+ }
70833+ FOR_EACH_ROLE_END(r)
70834+
70835+ for (i = 0; i < polstate->num_sprole_pws; i++) {
70836+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
70837+ *salt = polstate->acl_special_roles[i]->salt;
70838+ *sum = polstate->acl_special_roles[i]->sum;
70839+ return 1;
70840+ }
70841+ }
70842+
70843+ return 0;
70844+}
70845+
70846+int gr_check_secure_terminal(struct task_struct *task)
70847+{
70848+ struct task_struct *p, *p2, *p3;
70849+ struct files_struct *files;
70850+ struct fdtable *fdt;
70851+ struct file *our_file = NULL, *file;
70852+ int i;
70853+
70854+ if (task->signal->tty == NULL)
70855+ return 1;
70856+
70857+ files = get_files_struct(task);
70858+ if (files != NULL) {
70859+ rcu_read_lock();
70860+ fdt = files_fdtable(files);
70861+ for (i=0; i < fdt->max_fds; i++) {
70862+ file = fcheck_files(files, i);
70863+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
70864+ get_file(file);
70865+ our_file = file;
70866+ }
70867+ }
70868+ rcu_read_unlock();
70869+ put_files_struct(files);
70870+ }
70871+
70872+ if (our_file == NULL)
70873+ return 1;
70874+
70875+ read_lock(&tasklist_lock);
70876+ do_each_thread(p2, p) {
70877+ files = get_files_struct(p);
70878+ if (files == NULL ||
70879+ (p->signal && p->signal->tty == task->signal->tty)) {
70880+ if (files != NULL)
70881+ put_files_struct(files);
70882+ continue;
70883+ }
70884+ rcu_read_lock();
70885+ fdt = files_fdtable(files);
70886+ for (i=0; i < fdt->max_fds; i++) {
70887+ file = fcheck_files(files, i);
70888+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
70889+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
70890+ p3 = task;
70891+ while (task_pid_nr(p3) > 0) {
70892+ if (p3 == p)
70893+ break;
70894+ p3 = p3->real_parent;
70895+ }
70896+ if (p3 == p)
70897+ break;
70898+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
70899+ gr_handle_alertkill(p);
70900+ rcu_read_unlock();
70901+ put_files_struct(files);
70902+ read_unlock(&tasklist_lock);
70903+ fput(our_file);
70904+ return 0;
70905+ }
70906+ }
70907+ rcu_read_unlock();
70908+ put_files_struct(files);
70909+ } while_each_thread(p2, p);
70910+ read_unlock(&tasklist_lock);
70911+
70912+ fput(our_file);
70913+ return 1;
70914+}
70915+
70916+ssize_t
70917+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
70918+{
70919+ struct gr_arg_wrapper uwrap;
70920+ unsigned char *sprole_salt = NULL;
70921+ unsigned char *sprole_sum = NULL;
70922+ int error = 0;
70923+ int error2 = 0;
70924+ size_t req_count = 0;
70925+ unsigned char oldmode = 0;
70926+
70927+ mutex_lock(&gr_dev_mutex);
70928+
70929+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
70930+ error = -EPERM;
70931+ goto out;
70932+ }
70933+
70934+#ifdef CONFIG_COMPAT
70935+ pax_open_kernel();
70936+ if (is_compat_task()) {
70937+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
70938+ copy_gr_arg = &copy_gr_arg_compat;
70939+ copy_acl_object_label = &copy_acl_object_label_compat;
70940+ copy_acl_subject_label = &copy_acl_subject_label_compat;
70941+ copy_acl_role_label = &copy_acl_role_label_compat;
70942+ copy_acl_ip_label = &copy_acl_ip_label_compat;
70943+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
70944+ copy_role_transition = &copy_role_transition_compat;
70945+ copy_sprole_pw = &copy_sprole_pw_compat;
70946+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
70947+ copy_pointer_from_array = &copy_pointer_from_array_compat;
70948+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
70949+ } else {
70950+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
70951+ copy_gr_arg = &copy_gr_arg_normal;
70952+ copy_acl_object_label = &copy_acl_object_label_normal;
70953+ copy_acl_subject_label = &copy_acl_subject_label_normal;
70954+ copy_acl_role_label = &copy_acl_role_label_normal;
70955+ copy_acl_ip_label = &copy_acl_ip_label_normal;
70956+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
70957+ copy_role_transition = &copy_role_transition_normal;
70958+ copy_sprole_pw = &copy_sprole_pw_normal;
70959+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
70960+ copy_pointer_from_array = &copy_pointer_from_array_normal;
70961+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
70962+ }
70963+ pax_close_kernel();
70964+#endif
70965+
70966+ req_count = get_gr_arg_wrapper_size();
70967+
70968+ if (count != req_count) {
70969+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
70970+ error = -EINVAL;
70971+ goto out;
70972+ }
70973+
70974+
70975+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
70976+ gr_auth_expires = 0;
70977+ gr_auth_attempts = 0;
70978+ }
70979+
70980+ error = copy_gr_arg_wrapper(buf, &uwrap);
70981+ if (error)
70982+ goto out;
70983+
70984+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
70985+ if (error)
70986+ goto out;
70987+
70988+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
70989+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
70990+ time_after(gr_auth_expires, get_seconds())) {
70991+ error = -EBUSY;
70992+ goto out;
70993+ }
70994+
70995+ /* if non-root trying to do anything other than use a special role,
70996+ do not attempt authentication, do not count towards authentication
70997+ locking
70998+ */
70999+
71000+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
71001+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71002+ gr_is_global_nonroot(current_uid())) {
71003+ error = -EPERM;
71004+ goto out;
71005+ }
71006+
71007+ /* ensure pw and special role name are null terminated */
71008+
71009+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
71010+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
71011+
71012+ /* Okay.
71013+ * We have our enough of the argument structure..(we have yet
71014+ * to copy_from_user the tables themselves) . Copy the tables
71015+ * only if we need them, i.e. for loading operations. */
71016+
71017+ switch (gr_usermode.mode) {
71018+ case GR_STATUS:
71019+ if (gr_acl_is_enabled()) {
71020+ error = 1;
71021+ if (!gr_check_secure_terminal(current))
71022+ error = 3;
71023+ } else
71024+ error = 2;
71025+ goto out;
71026+ case GR_SHUTDOWN:
71027+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71028+ stop_machine(gr_rbac_disable, NULL, NULL);
71029+ free_variables(false);
71030+ memset(&gr_usermode, 0, sizeof(gr_usermode));
71031+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
71032+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
71033+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
71034+ } else if (gr_acl_is_enabled()) {
71035+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
71036+ error = -EPERM;
71037+ } else {
71038+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
71039+ error = -EAGAIN;
71040+ }
71041+ break;
71042+ case GR_ENABLE:
71043+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
71044+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
71045+ else {
71046+ if (gr_acl_is_enabled())
71047+ error = -EAGAIN;
71048+ else
71049+ error = error2;
71050+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
71051+ }
71052+ break;
71053+ case GR_OLDRELOAD:
71054+ oldmode = 1;
71055+ case GR_RELOAD:
71056+ if (!gr_acl_is_enabled()) {
71057+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
71058+ error = -EAGAIN;
71059+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71060+ error2 = gracl_reload(&gr_usermode, oldmode);
71061+ if (!error2)
71062+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
71063+ else {
71064+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71065+ error = error2;
71066+ }
71067+ } else {
71068+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71069+ error = -EPERM;
71070+ }
71071+ break;
71072+ case GR_SEGVMOD:
71073+ if (unlikely(!gr_acl_is_enabled())) {
71074+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
71075+ error = -EAGAIN;
71076+ break;
71077+ }
71078+
71079+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71080+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
71081+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
71082+ struct acl_subject_label *segvacl;
71083+ segvacl =
71084+ lookup_acl_subj_label(gr_usermode.segv_inode,
71085+ gr_usermode.segv_device,
71086+ current->role);
71087+ if (segvacl) {
71088+ segvacl->crashes = 0;
71089+ segvacl->expires = 0;
71090+ }
71091+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
71092+ gr_remove_uid(gr_usermode.segv_uid);
71093+ }
71094+ } else {
71095+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
71096+ error = -EPERM;
71097+ }
71098+ break;
71099+ case GR_SPROLE:
71100+ case GR_SPROLEPAM:
71101+ if (unlikely(!gr_acl_is_enabled())) {
71102+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
71103+ error = -EAGAIN;
71104+ break;
71105+ }
71106+
71107+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
71108+ current->role->expires = 0;
71109+ current->role->auth_attempts = 0;
71110+ }
71111+
71112+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71113+ time_after(current->role->expires, get_seconds())) {
71114+ error = -EBUSY;
71115+ goto out;
71116+ }
71117+
71118+ if (lookup_special_role_auth
71119+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
71120+ && ((!sprole_salt && !sprole_sum)
71121+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
71122+ char *p = "";
71123+ assign_special_role(gr_usermode.sp_role);
71124+ read_lock(&tasklist_lock);
71125+ if (current->real_parent)
71126+ p = current->real_parent->role->rolename;
71127+ read_unlock(&tasklist_lock);
71128+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
71129+ p, acl_sp_role_value);
71130+ } else {
71131+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
71132+ error = -EPERM;
71133+ if(!(current->role->auth_attempts++))
71134+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71135+
71136+ goto out;
71137+ }
71138+ break;
71139+ case GR_UNSPROLE:
71140+ if (unlikely(!gr_acl_is_enabled())) {
71141+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
71142+ error = -EAGAIN;
71143+ break;
71144+ }
71145+
71146+ if (current->role->roletype & GR_ROLE_SPECIAL) {
71147+ char *p = "";
71148+ int i = 0;
71149+
71150+ read_lock(&tasklist_lock);
71151+ if (current->real_parent) {
71152+ p = current->real_parent->role->rolename;
71153+ i = current->real_parent->acl_role_id;
71154+ }
71155+ read_unlock(&tasklist_lock);
71156+
71157+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
71158+ gr_set_acls(1);
71159+ } else {
71160+ error = -EPERM;
71161+ goto out;
71162+ }
71163+ break;
71164+ default:
71165+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
71166+ error = -EINVAL;
71167+ break;
71168+ }
71169+
71170+ if (error != -EPERM)
71171+ goto out;
71172+
71173+ if(!(gr_auth_attempts++))
71174+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71175+
71176+ out:
71177+ mutex_unlock(&gr_dev_mutex);
71178+
71179+ if (!error)
71180+ error = req_count;
71181+
71182+ return error;
71183+}
71184+
71185+int
71186+gr_set_acls(const int type)
71187+{
71188+ struct task_struct *task, *task2;
71189+ struct acl_role_label *role = current->role;
71190+ struct acl_subject_label *subj;
71191+ __u16 acl_role_id = current->acl_role_id;
71192+ const struct cred *cred;
71193+ int ret;
71194+
71195+ rcu_read_lock();
71196+ read_lock(&tasklist_lock);
71197+ read_lock(&grsec_exec_file_lock);
71198+ do_each_thread(task2, task) {
71199+ /* check to see if we're called from the exit handler,
71200+ if so, only replace ACLs that have inherited the admin
71201+ ACL */
71202+
71203+ if (type && (task->role != role ||
71204+ task->acl_role_id != acl_role_id))
71205+ continue;
71206+
71207+ task->acl_role_id = 0;
71208+ task->acl_sp_role = 0;
71209+ task->inherited = 0;
71210+
71211+ if (task->exec_file) {
71212+ cred = __task_cred(task);
71213+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71214+ subj = __gr_get_subject_for_task(polstate, task, NULL);
71215+ if (subj == NULL) {
71216+ ret = -EINVAL;
71217+ read_unlock(&grsec_exec_file_lock);
71218+ read_unlock(&tasklist_lock);
71219+ rcu_read_unlock();
71220+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
71221+ return ret;
71222+ }
71223+ __gr_apply_subject_to_task(polstate, task, subj);
71224+ } else {
71225+ // it's a kernel process
71226+ task->role = polstate->kernel_role;
71227+ task->acl = polstate->kernel_role->root_label;
71228+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71229+ task->acl->mode &= ~GR_PROCFIND;
71230+#endif
71231+ }
71232+ } while_each_thread(task2, task);
71233+ read_unlock(&grsec_exec_file_lock);
71234+ read_unlock(&tasklist_lock);
71235+ rcu_read_unlock();
71236+
71237+ return 0;
71238+}
71239diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
71240new file mode 100644
71241index 0000000..39645c9
71242--- /dev/null
71243+++ b/grsecurity/gracl_res.c
71244@@ -0,0 +1,68 @@
71245+#include <linux/kernel.h>
71246+#include <linux/sched.h>
71247+#include <linux/gracl.h>
71248+#include <linux/grinternal.h>
71249+
71250+static const char *restab_log[] = {
71251+ [RLIMIT_CPU] = "RLIMIT_CPU",
71252+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
71253+ [RLIMIT_DATA] = "RLIMIT_DATA",
71254+ [RLIMIT_STACK] = "RLIMIT_STACK",
71255+ [RLIMIT_CORE] = "RLIMIT_CORE",
71256+ [RLIMIT_RSS] = "RLIMIT_RSS",
71257+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
71258+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
71259+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
71260+ [RLIMIT_AS] = "RLIMIT_AS",
71261+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
71262+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
71263+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
71264+ [RLIMIT_NICE] = "RLIMIT_NICE",
71265+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
71266+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
71267+ [GR_CRASH_RES] = "RLIMIT_CRASH"
71268+};
71269+
71270+void
71271+gr_log_resource(const struct task_struct *task,
71272+ const int res, const unsigned long wanted, const int gt)
71273+{
71274+ const struct cred *cred;
71275+ unsigned long rlim;
71276+
71277+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
71278+ return;
71279+
71280+ // not yet supported resource
71281+ if (unlikely(!restab_log[res]))
71282+ return;
71283+
71284+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
71285+ rlim = task_rlimit_max(task, res);
71286+ else
71287+ rlim = task_rlimit(task, res);
71288+
71289+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
71290+ return;
71291+
71292+ rcu_read_lock();
71293+ cred = __task_cred(task);
71294+
71295+ if (res == RLIMIT_NPROC &&
71296+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
71297+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
71298+ goto out_rcu_unlock;
71299+ else if (res == RLIMIT_MEMLOCK &&
71300+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
71301+ goto out_rcu_unlock;
71302+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
71303+ goto out_rcu_unlock;
71304+ rcu_read_unlock();
71305+
71306+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
71307+
71308+ return;
71309+out_rcu_unlock:
71310+ rcu_read_unlock();
71311+ return;
71312+}
71313diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
71314new file mode 100644
71315index 0000000..2040e61
71316--- /dev/null
71317+++ b/grsecurity/gracl_segv.c
71318@@ -0,0 +1,313 @@
71319+#include <linux/kernel.h>
71320+#include <linux/mm.h>
71321+#include <asm/uaccess.h>
71322+#include <asm/errno.h>
71323+#include <asm/mman.h>
71324+#include <net/sock.h>
71325+#include <linux/file.h>
71326+#include <linux/fs.h>
71327+#include <linux/net.h>
71328+#include <linux/in.h>
71329+#include <linux/slab.h>
71330+#include <linux/types.h>
71331+#include <linux/sched.h>
71332+#include <linux/timer.h>
71333+#include <linux/gracl.h>
71334+#include <linux/grsecurity.h>
71335+#include <linux/grinternal.h>
71336+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71337+#include <linux/magic.h>
71338+#include <linux/pagemap.h>
71339+#include "../fs/btrfs/async-thread.h"
71340+#include "../fs/btrfs/ctree.h"
71341+#include "../fs/btrfs/btrfs_inode.h"
71342+#endif
71343+
71344+static struct crash_uid *uid_set;
71345+static unsigned short uid_used;
71346+static DEFINE_SPINLOCK(gr_uid_lock);
71347+extern rwlock_t gr_inode_lock;
71348+extern struct acl_subject_label *
71349+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
71350+ struct acl_role_label *role);
71351+
71352+static inline dev_t __get_dev(const struct dentry *dentry)
71353+{
71354+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71355+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
71356+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
71357+ else
71358+#endif
71359+ return dentry->d_sb->s_dev;
71360+}
71361+
71362+int
71363+gr_init_uidset(void)
71364+{
71365+ uid_set =
71366+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
71367+ uid_used = 0;
71368+
71369+ return uid_set ? 1 : 0;
71370+}
71371+
71372+void
71373+gr_free_uidset(void)
71374+{
71375+ if (uid_set) {
71376+ struct crash_uid *tmpset;
71377+ spin_lock(&gr_uid_lock);
71378+ tmpset = uid_set;
71379+ uid_set = NULL;
71380+ uid_used = 0;
71381+ spin_unlock(&gr_uid_lock);
71382+ if (tmpset)
71383+ kfree(tmpset);
71384+ }
71385+
71386+ return;
71387+}
71388+
71389+int
71390+gr_find_uid(const uid_t uid)
71391+{
71392+ struct crash_uid *tmp = uid_set;
71393+ uid_t buid;
71394+ int low = 0, high = uid_used - 1, mid;
71395+
71396+ while (high >= low) {
71397+ mid = (low + high) >> 1;
71398+ buid = tmp[mid].uid;
71399+ if (buid == uid)
71400+ return mid;
71401+ if (buid > uid)
71402+ high = mid - 1;
71403+ if (buid < uid)
71404+ low = mid + 1;
71405+ }
71406+
71407+ return -1;
71408+}
71409+
71410+static __inline__ void
71411+gr_insertsort(void)
71412+{
71413+ unsigned short i, j;
71414+ struct crash_uid index;
71415+
71416+ for (i = 1; i < uid_used; i++) {
71417+ index = uid_set[i];
71418+ j = i;
71419+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
71420+ uid_set[j] = uid_set[j - 1];
71421+ j--;
71422+ }
71423+ uid_set[j] = index;
71424+ }
71425+
71426+ return;
71427+}
71428+
71429+static __inline__ void
71430+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
71431+{
71432+ int loc;
71433+ uid_t uid = GR_GLOBAL_UID(kuid);
71434+
71435+ if (uid_used == GR_UIDTABLE_MAX)
71436+ return;
71437+
71438+ loc = gr_find_uid(uid);
71439+
71440+ if (loc >= 0) {
71441+ uid_set[loc].expires = expires;
71442+ return;
71443+ }
71444+
71445+ uid_set[uid_used].uid = uid;
71446+ uid_set[uid_used].expires = expires;
71447+ uid_used++;
71448+
71449+ gr_insertsort();
71450+
71451+ return;
71452+}
71453+
71454+void
71455+gr_remove_uid(const unsigned short loc)
71456+{
71457+ unsigned short i;
71458+
71459+ for (i = loc + 1; i < uid_used; i++)
71460+ uid_set[i - 1] = uid_set[i];
71461+
71462+ uid_used--;
71463+
71464+ return;
71465+}
71466+
71467+int
71468+gr_check_crash_uid(const kuid_t kuid)
71469+{
71470+ int loc;
71471+ int ret = 0;
71472+ uid_t uid;
71473+
71474+ if (unlikely(!gr_acl_is_enabled()))
71475+ return 0;
71476+
71477+ uid = GR_GLOBAL_UID(kuid);
71478+
71479+ spin_lock(&gr_uid_lock);
71480+ loc = gr_find_uid(uid);
71481+
71482+ if (loc < 0)
71483+ goto out_unlock;
71484+
71485+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
71486+ gr_remove_uid(loc);
71487+ else
71488+ ret = 1;
71489+
71490+out_unlock:
71491+ spin_unlock(&gr_uid_lock);
71492+ return ret;
71493+}
71494+
71495+static __inline__ int
71496+proc_is_setxid(const struct cred *cred)
71497+{
71498+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
71499+ !uid_eq(cred->uid, cred->fsuid))
71500+ return 1;
71501+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
71502+ !gid_eq(cred->gid, cred->fsgid))
71503+ return 1;
71504+
71505+ return 0;
71506+}
71507+
71508+extern int gr_fake_force_sig(int sig, struct task_struct *t);
71509+
71510+void
71511+gr_handle_crash(struct task_struct *task, const int sig)
71512+{
71513+ struct acl_subject_label *curr;
71514+ struct task_struct *tsk, *tsk2;
71515+ const struct cred *cred;
71516+ const struct cred *cred2;
71517+
71518+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
71519+ return;
71520+
71521+ if (unlikely(!gr_acl_is_enabled()))
71522+ return;
71523+
71524+ curr = task->acl;
71525+
71526+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
71527+ return;
71528+
71529+ if (time_before_eq(curr->expires, get_seconds())) {
71530+ curr->expires = 0;
71531+ curr->crashes = 0;
71532+ }
71533+
71534+ curr->crashes++;
71535+
71536+ if (!curr->expires)
71537+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
71538+
71539+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71540+ time_after(curr->expires, get_seconds())) {
71541+ rcu_read_lock();
71542+ cred = __task_cred(task);
71543+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
71544+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71545+ spin_lock(&gr_uid_lock);
71546+ gr_insert_uid(cred->uid, curr->expires);
71547+ spin_unlock(&gr_uid_lock);
71548+ curr->expires = 0;
71549+ curr->crashes = 0;
71550+ read_lock(&tasklist_lock);
71551+ do_each_thread(tsk2, tsk) {
71552+ cred2 = __task_cred(tsk);
71553+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
71554+ gr_fake_force_sig(SIGKILL, tsk);
71555+ } while_each_thread(tsk2, tsk);
71556+ read_unlock(&tasklist_lock);
71557+ } else {
71558+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71559+ read_lock(&tasklist_lock);
71560+ read_lock(&grsec_exec_file_lock);
71561+ do_each_thread(tsk2, tsk) {
71562+ if (likely(tsk != task)) {
71563+ // if this thread has the same subject as the one that triggered
71564+ // RES_CRASH and it's the same binary, kill it
71565+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
71566+ gr_fake_force_sig(SIGKILL, tsk);
71567+ }
71568+ } while_each_thread(tsk2, tsk);
71569+ read_unlock(&grsec_exec_file_lock);
71570+ read_unlock(&tasklist_lock);
71571+ }
71572+ rcu_read_unlock();
71573+ }
71574+
71575+ return;
71576+}
71577+
71578+int
71579+gr_check_crash_exec(const struct file *filp)
71580+{
71581+ struct acl_subject_label *curr;
71582+
71583+ if (unlikely(!gr_acl_is_enabled()))
71584+ return 0;
71585+
71586+ read_lock(&gr_inode_lock);
71587+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
71588+ __get_dev(filp->f_path.dentry),
71589+ current->role);
71590+ read_unlock(&gr_inode_lock);
71591+
71592+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
71593+ (!curr->crashes && !curr->expires))
71594+ return 0;
71595+
71596+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71597+ time_after(curr->expires, get_seconds()))
71598+ return 1;
71599+ else if (time_before_eq(curr->expires, get_seconds())) {
71600+ curr->crashes = 0;
71601+ curr->expires = 0;
71602+ }
71603+
71604+ return 0;
71605+}
71606+
71607+void
71608+gr_handle_alertkill(struct task_struct *task)
71609+{
71610+ struct acl_subject_label *curracl;
71611+ __u32 curr_ip;
71612+ struct task_struct *p, *p2;
71613+
71614+ if (unlikely(!gr_acl_is_enabled()))
71615+ return;
71616+
71617+ curracl = task->acl;
71618+ curr_ip = task->signal->curr_ip;
71619+
71620+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
71621+ read_lock(&tasklist_lock);
71622+ do_each_thread(p2, p) {
71623+ if (p->signal->curr_ip == curr_ip)
71624+ gr_fake_force_sig(SIGKILL, p);
71625+ } while_each_thread(p2, p);
71626+ read_unlock(&tasklist_lock);
71627+ } else if (curracl->mode & GR_KILLPROC)
71628+ gr_fake_force_sig(SIGKILL, task);
71629+
71630+ return;
71631+}
71632diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
71633new file mode 100644
71634index 0000000..98011b0
71635--- /dev/null
71636+++ b/grsecurity/gracl_shm.c
71637@@ -0,0 +1,40 @@
71638+#include <linux/kernel.h>
71639+#include <linux/mm.h>
71640+#include <linux/sched.h>
71641+#include <linux/file.h>
71642+#include <linux/ipc.h>
71643+#include <linux/gracl.h>
71644+#include <linux/grsecurity.h>
71645+#include <linux/grinternal.h>
71646+
71647+int
71648+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71649+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
71650+{
71651+ struct task_struct *task;
71652+
71653+ if (!gr_acl_is_enabled())
71654+ return 1;
71655+
71656+ rcu_read_lock();
71657+ read_lock(&tasklist_lock);
71658+
71659+ task = find_task_by_vpid(shm_cprid);
71660+
71661+ if (unlikely(!task))
71662+ task = find_task_by_vpid(shm_lapid);
71663+
71664+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
71665+ (task_pid_nr(task) == shm_lapid)) &&
71666+ (task->acl->mode & GR_PROTSHM) &&
71667+ (task->acl != current->acl))) {
71668+ read_unlock(&tasklist_lock);
71669+ rcu_read_unlock();
71670+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
71671+ return 0;
71672+ }
71673+ read_unlock(&tasklist_lock);
71674+ rcu_read_unlock();
71675+
71676+ return 1;
71677+}
71678diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
71679new file mode 100644
71680index 0000000..bc0be01
71681--- /dev/null
71682+++ b/grsecurity/grsec_chdir.c
71683@@ -0,0 +1,19 @@
71684+#include <linux/kernel.h>
71685+#include <linux/sched.h>
71686+#include <linux/fs.h>
71687+#include <linux/file.h>
71688+#include <linux/grsecurity.h>
71689+#include <linux/grinternal.h>
71690+
71691+void
71692+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
71693+{
71694+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71695+ if ((grsec_enable_chdir && grsec_enable_group &&
71696+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
71697+ !grsec_enable_group)) {
71698+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
71699+ }
71700+#endif
71701+ return;
71702+}
71703diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
71704new file mode 100644
71705index 0000000..e10b319
71706--- /dev/null
71707+++ b/grsecurity/grsec_chroot.c
71708@@ -0,0 +1,370 @@
71709+#include <linux/kernel.h>
71710+#include <linux/module.h>
71711+#include <linux/sched.h>
71712+#include <linux/file.h>
71713+#include <linux/fs.h>
71714+#include <linux/mount.h>
71715+#include <linux/types.h>
71716+#include "../fs/mount.h"
71717+#include <linux/grsecurity.h>
71718+#include <linux/grinternal.h>
71719+
71720+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71721+int gr_init_ran;
71722+#endif
71723+
71724+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
71725+{
71726+#ifdef CONFIG_GRKERNSEC
71727+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
71728+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
71729+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71730+ && gr_init_ran
71731+#endif
71732+ )
71733+ task->gr_is_chrooted = 1;
71734+ else {
71735+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71736+ if (task_pid_nr(task) == 1 && !gr_init_ran)
71737+ gr_init_ran = 1;
71738+#endif
71739+ task->gr_is_chrooted = 0;
71740+ }
71741+
71742+ task->gr_chroot_dentry = path->dentry;
71743+#endif
71744+ return;
71745+}
71746+
71747+void gr_clear_chroot_entries(struct task_struct *task)
71748+{
71749+#ifdef CONFIG_GRKERNSEC
71750+ task->gr_is_chrooted = 0;
71751+ task->gr_chroot_dentry = NULL;
71752+#endif
71753+ return;
71754+}
71755+
71756+int
71757+gr_handle_chroot_unix(const pid_t pid)
71758+{
71759+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71760+ struct task_struct *p;
71761+
71762+ if (unlikely(!grsec_enable_chroot_unix))
71763+ return 1;
71764+
71765+ if (likely(!proc_is_chrooted(current)))
71766+ return 1;
71767+
71768+ rcu_read_lock();
71769+ read_lock(&tasklist_lock);
71770+ p = find_task_by_vpid_unrestricted(pid);
71771+ if (unlikely(p && !have_same_root(current, p))) {
71772+ read_unlock(&tasklist_lock);
71773+ rcu_read_unlock();
71774+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
71775+ return 0;
71776+ }
71777+ read_unlock(&tasklist_lock);
71778+ rcu_read_unlock();
71779+#endif
71780+ return 1;
71781+}
71782+
71783+int
71784+gr_handle_chroot_nice(void)
71785+{
71786+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71787+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
71788+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
71789+ return -EPERM;
71790+ }
71791+#endif
71792+ return 0;
71793+}
71794+
71795+int
71796+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
71797+{
71798+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71799+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
71800+ && proc_is_chrooted(current)) {
71801+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
71802+ return -EACCES;
71803+ }
71804+#endif
71805+ return 0;
71806+}
71807+
71808+int
71809+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
71810+{
71811+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71812+ struct task_struct *p;
71813+ int ret = 0;
71814+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
71815+ return ret;
71816+
71817+ read_lock(&tasklist_lock);
71818+ do_each_pid_task(pid, type, p) {
71819+ if (!have_same_root(current, p)) {
71820+ ret = 1;
71821+ goto out;
71822+ }
71823+ } while_each_pid_task(pid, type, p);
71824+out:
71825+ read_unlock(&tasklist_lock);
71826+ return ret;
71827+#endif
71828+ return 0;
71829+}
71830+
71831+int
71832+gr_pid_is_chrooted(struct task_struct *p)
71833+{
71834+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71835+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
71836+ return 0;
71837+
71838+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
71839+ !have_same_root(current, p)) {
71840+ return 1;
71841+ }
71842+#endif
71843+ return 0;
71844+}
71845+
71846+EXPORT_SYMBOL(gr_pid_is_chrooted);
71847+
71848+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
71849+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
71850+{
71851+ struct path path, currentroot;
71852+ int ret = 0;
71853+
71854+ path.dentry = (struct dentry *)u_dentry;
71855+ path.mnt = (struct vfsmount *)u_mnt;
71856+ get_fs_root(current->fs, &currentroot);
71857+ if (path_is_under(&path, &currentroot))
71858+ ret = 1;
71859+ path_put(&currentroot);
71860+
71861+ return ret;
71862+}
71863+#endif
71864+
71865+int
71866+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
71867+{
71868+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71869+ if (!grsec_enable_chroot_fchdir)
71870+ return 1;
71871+
71872+ if (!proc_is_chrooted(current))
71873+ return 1;
71874+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
71875+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
71876+ return 0;
71877+ }
71878+#endif
71879+ return 1;
71880+}
71881+
71882+int
71883+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71884+ const time_t shm_createtime)
71885+{
71886+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71887+ struct task_struct *p;
71888+ time_t starttime;
71889+
71890+ if (unlikely(!grsec_enable_chroot_shmat))
71891+ return 1;
71892+
71893+ if (likely(!proc_is_chrooted(current)))
71894+ return 1;
71895+
71896+ rcu_read_lock();
71897+ read_lock(&tasklist_lock);
71898+
71899+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
71900+ starttime = p->start_time.tv_sec;
71901+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
71902+ if (have_same_root(current, p)) {
71903+ goto allow;
71904+ } else {
71905+ read_unlock(&tasklist_lock);
71906+ rcu_read_unlock();
71907+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
71908+ return 0;
71909+ }
71910+ }
71911+ /* creator exited, pid reuse, fall through to next check */
71912+ }
71913+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
71914+ if (unlikely(!have_same_root(current, p))) {
71915+ read_unlock(&tasklist_lock);
71916+ rcu_read_unlock();
71917+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
71918+ return 0;
71919+ }
71920+ }
71921+
71922+allow:
71923+ read_unlock(&tasklist_lock);
71924+ rcu_read_unlock();
71925+#endif
71926+ return 1;
71927+}
71928+
71929+void
71930+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
71931+{
71932+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71933+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
71934+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
71935+#endif
71936+ return;
71937+}
71938+
71939+int
71940+gr_handle_chroot_mknod(const struct dentry *dentry,
71941+ const struct vfsmount *mnt, const int mode)
71942+{
71943+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71944+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
71945+ proc_is_chrooted(current)) {
71946+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
71947+ return -EPERM;
71948+ }
71949+#endif
71950+ return 0;
71951+}
71952+
71953+int
71954+gr_handle_chroot_mount(const struct dentry *dentry,
71955+ const struct vfsmount *mnt, const char *dev_name)
71956+{
71957+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71958+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
71959+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
71960+ return -EPERM;
71961+ }
71962+#endif
71963+ return 0;
71964+}
71965+
71966+int
71967+gr_handle_chroot_pivot(void)
71968+{
71969+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71970+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
71971+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
71972+ return -EPERM;
71973+ }
71974+#endif
71975+ return 0;
71976+}
71977+
71978+int
71979+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
71980+{
71981+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71982+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
71983+ !gr_is_outside_chroot(dentry, mnt)) {
71984+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
71985+ return -EPERM;
71986+ }
71987+#endif
71988+ return 0;
71989+}
71990+
71991+extern const char *captab_log[];
71992+extern int captab_log_entries;
71993+
71994+int
71995+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
71996+{
71997+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71998+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
71999+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72000+ if (cap_raised(chroot_caps, cap)) {
72001+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
72002+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
72003+ }
72004+ return 0;
72005+ }
72006+ }
72007+#endif
72008+ return 1;
72009+}
72010+
72011+int
72012+gr_chroot_is_capable(const int cap)
72013+{
72014+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72015+ return gr_task_chroot_is_capable(current, current_cred(), cap);
72016+#endif
72017+ return 1;
72018+}
72019+
72020+int
72021+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
72022+{
72023+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72024+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72025+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72026+ if (cap_raised(chroot_caps, cap)) {
72027+ return 0;
72028+ }
72029+ }
72030+#endif
72031+ return 1;
72032+}
72033+
72034+int
72035+gr_chroot_is_capable_nolog(const int cap)
72036+{
72037+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72038+ return gr_task_chroot_is_capable_nolog(current, cap);
72039+#endif
72040+ return 1;
72041+}
72042+
72043+int
72044+gr_handle_chroot_sysctl(const int op)
72045+{
72046+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72047+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
72048+ proc_is_chrooted(current))
72049+ return -EACCES;
72050+#endif
72051+ return 0;
72052+}
72053+
72054+void
72055+gr_handle_chroot_chdir(const struct path *path)
72056+{
72057+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72058+ if (grsec_enable_chroot_chdir)
72059+ set_fs_pwd(current->fs, path);
72060+#endif
72061+ return;
72062+}
72063+
72064+int
72065+gr_handle_chroot_chmod(const struct dentry *dentry,
72066+ const struct vfsmount *mnt, const int mode)
72067+{
72068+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72069+ /* allow chmod +s on directories, but not files */
72070+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
72071+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
72072+ proc_is_chrooted(current)) {
72073+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
72074+ return -EPERM;
72075+ }
72076+#endif
72077+ return 0;
72078+}
72079diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
72080new file mode 100644
72081index 0000000..52b3e30
72082--- /dev/null
72083+++ b/grsecurity/grsec_disabled.c
72084@@ -0,0 +1,433 @@
72085+#include <linux/kernel.h>
72086+#include <linux/module.h>
72087+#include <linux/sched.h>
72088+#include <linux/file.h>
72089+#include <linux/fs.h>
72090+#include <linux/kdev_t.h>
72091+#include <linux/net.h>
72092+#include <linux/in.h>
72093+#include <linux/ip.h>
72094+#include <linux/skbuff.h>
72095+#include <linux/sysctl.h>
72096+
72097+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
72098+void
72099+pax_set_initial_flags(struct linux_binprm *bprm)
72100+{
72101+ return;
72102+}
72103+#endif
72104+
72105+#ifdef CONFIG_SYSCTL
72106+__u32
72107+gr_handle_sysctl(const struct ctl_table * table, const int op)
72108+{
72109+ return 0;
72110+}
72111+#endif
72112+
72113+#ifdef CONFIG_TASKSTATS
72114+int gr_is_taskstats_denied(int pid)
72115+{
72116+ return 0;
72117+}
72118+#endif
72119+
72120+int
72121+gr_acl_is_enabled(void)
72122+{
72123+ return 0;
72124+}
72125+
72126+void
72127+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72128+{
72129+ return;
72130+}
72131+
72132+int
72133+gr_handle_rawio(const struct inode *inode)
72134+{
72135+ return 0;
72136+}
72137+
72138+void
72139+gr_acl_handle_psacct(struct task_struct *task, const long code)
72140+{
72141+ return;
72142+}
72143+
72144+int
72145+gr_handle_ptrace(struct task_struct *task, const long request)
72146+{
72147+ return 0;
72148+}
72149+
72150+int
72151+gr_handle_proc_ptrace(struct task_struct *task)
72152+{
72153+ return 0;
72154+}
72155+
72156+int
72157+gr_set_acls(const int type)
72158+{
72159+ return 0;
72160+}
72161+
72162+int
72163+gr_check_hidden_task(const struct task_struct *tsk)
72164+{
72165+ return 0;
72166+}
72167+
72168+int
72169+gr_check_protected_task(const struct task_struct *task)
72170+{
72171+ return 0;
72172+}
72173+
72174+int
72175+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
72176+{
72177+ return 0;
72178+}
72179+
72180+void
72181+gr_copy_label(struct task_struct *tsk)
72182+{
72183+ return;
72184+}
72185+
72186+void
72187+gr_set_pax_flags(struct task_struct *task)
72188+{
72189+ return;
72190+}
72191+
72192+int
72193+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72194+ const int unsafe_share)
72195+{
72196+ return 0;
72197+}
72198+
72199+void
72200+gr_handle_delete(const ino_t ino, const dev_t dev)
72201+{
72202+ return;
72203+}
72204+
72205+void
72206+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72207+{
72208+ return;
72209+}
72210+
72211+void
72212+gr_handle_crash(struct task_struct *task, const int sig)
72213+{
72214+ return;
72215+}
72216+
72217+int
72218+gr_check_crash_exec(const struct file *filp)
72219+{
72220+ return 0;
72221+}
72222+
72223+int
72224+gr_check_crash_uid(const kuid_t uid)
72225+{
72226+ return 0;
72227+}
72228+
72229+void
72230+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72231+ struct dentry *old_dentry,
72232+ struct dentry *new_dentry,
72233+ struct vfsmount *mnt, const __u8 replace)
72234+{
72235+ return;
72236+}
72237+
72238+int
72239+gr_search_socket(const int family, const int type, const int protocol)
72240+{
72241+ return 1;
72242+}
72243+
72244+int
72245+gr_search_connectbind(const int mode, const struct socket *sock,
72246+ const struct sockaddr_in *addr)
72247+{
72248+ return 0;
72249+}
72250+
72251+void
72252+gr_handle_alertkill(struct task_struct *task)
72253+{
72254+ return;
72255+}
72256+
72257+__u32
72258+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
72259+{
72260+ return 1;
72261+}
72262+
72263+__u32
72264+gr_acl_handle_hidden_file(const struct dentry * dentry,
72265+ const struct vfsmount * mnt)
72266+{
72267+ return 1;
72268+}
72269+
72270+__u32
72271+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72272+ int acc_mode)
72273+{
72274+ return 1;
72275+}
72276+
72277+__u32
72278+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72279+{
72280+ return 1;
72281+}
72282+
72283+__u32
72284+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
72285+{
72286+ return 1;
72287+}
72288+
72289+int
72290+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
72291+ unsigned int *vm_flags)
72292+{
72293+ return 1;
72294+}
72295+
72296+__u32
72297+gr_acl_handle_truncate(const struct dentry * dentry,
72298+ const struct vfsmount * mnt)
72299+{
72300+ return 1;
72301+}
72302+
72303+__u32
72304+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
72305+{
72306+ return 1;
72307+}
72308+
72309+__u32
72310+gr_acl_handle_access(const struct dentry * dentry,
72311+ const struct vfsmount * mnt, const int fmode)
72312+{
72313+ return 1;
72314+}
72315+
72316+__u32
72317+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
72318+ umode_t *mode)
72319+{
72320+ return 1;
72321+}
72322+
72323+__u32
72324+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
72325+{
72326+ return 1;
72327+}
72328+
72329+__u32
72330+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
72331+{
72332+ return 1;
72333+}
72334+
72335+__u32
72336+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
72337+{
72338+ return 1;
72339+}
72340+
72341+void
72342+grsecurity_init(void)
72343+{
72344+ return;
72345+}
72346+
72347+umode_t gr_acl_umask(void)
72348+{
72349+ return 0;
72350+}
72351+
72352+__u32
72353+gr_acl_handle_mknod(const struct dentry * new_dentry,
72354+ const struct dentry * parent_dentry,
72355+ const struct vfsmount * parent_mnt,
72356+ const int mode)
72357+{
72358+ return 1;
72359+}
72360+
72361+__u32
72362+gr_acl_handle_mkdir(const struct dentry * new_dentry,
72363+ const struct dentry * parent_dentry,
72364+ const struct vfsmount * parent_mnt)
72365+{
72366+ return 1;
72367+}
72368+
72369+__u32
72370+gr_acl_handle_symlink(const struct dentry * new_dentry,
72371+ const struct dentry * parent_dentry,
72372+ const struct vfsmount * parent_mnt, const struct filename *from)
72373+{
72374+ return 1;
72375+}
72376+
72377+__u32
72378+gr_acl_handle_link(const struct dentry * new_dentry,
72379+ const struct dentry * parent_dentry,
72380+ const struct vfsmount * parent_mnt,
72381+ const struct dentry * old_dentry,
72382+ const struct vfsmount * old_mnt, const struct filename *to)
72383+{
72384+ return 1;
72385+}
72386+
72387+int
72388+gr_acl_handle_rename(const struct dentry *new_dentry,
72389+ const struct dentry *parent_dentry,
72390+ const struct vfsmount *parent_mnt,
72391+ const struct dentry *old_dentry,
72392+ const struct inode *old_parent_inode,
72393+ const struct vfsmount *old_mnt, const struct filename *newname)
72394+{
72395+ return 0;
72396+}
72397+
72398+int
72399+gr_acl_handle_filldir(const struct file *file, const char *name,
72400+ const int namelen, const ino_t ino)
72401+{
72402+ return 1;
72403+}
72404+
72405+int
72406+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72407+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
72408+{
72409+ return 1;
72410+}
72411+
72412+int
72413+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
72414+{
72415+ return 0;
72416+}
72417+
72418+int
72419+gr_search_accept(const struct socket *sock)
72420+{
72421+ return 0;
72422+}
72423+
72424+int
72425+gr_search_listen(const struct socket *sock)
72426+{
72427+ return 0;
72428+}
72429+
72430+int
72431+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
72432+{
72433+ return 0;
72434+}
72435+
72436+__u32
72437+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
72438+{
72439+ return 1;
72440+}
72441+
72442+__u32
72443+gr_acl_handle_creat(const struct dentry * dentry,
72444+ const struct dentry * p_dentry,
72445+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72446+ const int imode)
72447+{
72448+ return 1;
72449+}
72450+
72451+void
72452+gr_acl_handle_exit(void)
72453+{
72454+ return;
72455+}
72456+
72457+int
72458+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72459+{
72460+ return 1;
72461+}
72462+
72463+void
72464+gr_set_role_label(const kuid_t uid, const kgid_t gid)
72465+{
72466+ return;
72467+}
72468+
72469+int
72470+gr_acl_handle_procpidmem(const struct task_struct *task)
72471+{
72472+ return 0;
72473+}
72474+
72475+int
72476+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
72477+{
72478+ return 0;
72479+}
72480+
72481+int
72482+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
72483+{
72484+ return 0;
72485+}
72486+
72487+int
72488+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
72489+{
72490+ return 0;
72491+}
72492+
72493+int
72494+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72495+{
72496+ return 0;
72497+}
72498+
72499+int gr_acl_enable_at_secure(void)
72500+{
72501+ return 0;
72502+}
72503+
72504+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
72505+{
72506+ return dentry->d_sb->s_dev;
72507+}
72508+
72509+void gr_put_exec_file(struct task_struct *task)
72510+{
72511+ return;
72512+}
72513+
72514+#ifdef CONFIG_SECURITY
72515+EXPORT_SYMBOL(gr_check_user_change);
72516+EXPORT_SYMBOL(gr_check_group_change);
72517+#endif
72518diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
72519new file mode 100644
72520index 0000000..387032b
72521--- /dev/null
72522+++ b/grsecurity/grsec_exec.c
72523@@ -0,0 +1,187 @@
72524+#include <linux/kernel.h>
72525+#include <linux/sched.h>
72526+#include <linux/file.h>
72527+#include <linux/binfmts.h>
72528+#include <linux/fs.h>
72529+#include <linux/types.h>
72530+#include <linux/grdefs.h>
72531+#include <linux/grsecurity.h>
72532+#include <linux/grinternal.h>
72533+#include <linux/capability.h>
72534+#include <linux/module.h>
72535+#include <linux/compat.h>
72536+
72537+#include <asm/uaccess.h>
72538+
72539+#ifdef CONFIG_GRKERNSEC_EXECLOG
72540+static char gr_exec_arg_buf[132];
72541+static DEFINE_MUTEX(gr_exec_arg_mutex);
72542+#endif
72543+
72544+struct user_arg_ptr {
72545+#ifdef CONFIG_COMPAT
72546+ bool is_compat;
72547+#endif
72548+ union {
72549+ const char __user *const __user *native;
72550+#ifdef CONFIG_COMPAT
72551+ const compat_uptr_t __user *compat;
72552+#endif
72553+ } ptr;
72554+};
72555+
72556+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
72557+
72558+void
72559+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
72560+{
72561+#ifdef CONFIG_GRKERNSEC_EXECLOG
72562+ char *grarg = gr_exec_arg_buf;
72563+ unsigned int i, x, execlen = 0;
72564+ char c;
72565+
72566+ if (!((grsec_enable_execlog && grsec_enable_group &&
72567+ in_group_p(grsec_audit_gid))
72568+ || (grsec_enable_execlog && !grsec_enable_group)))
72569+ return;
72570+
72571+ mutex_lock(&gr_exec_arg_mutex);
72572+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
72573+
72574+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
72575+ const char __user *p;
72576+ unsigned int len;
72577+
72578+ p = get_user_arg_ptr(argv, i);
72579+ if (IS_ERR(p))
72580+ goto log;
72581+
72582+ len = strnlen_user(p, 128 - execlen);
72583+ if (len > 128 - execlen)
72584+ len = 128 - execlen;
72585+ else if (len > 0)
72586+ len--;
72587+ if (copy_from_user(grarg + execlen, p, len))
72588+ goto log;
72589+
72590+ /* rewrite unprintable characters */
72591+ for (x = 0; x < len; x++) {
72592+ c = *(grarg + execlen + x);
72593+ if (c < 32 || c > 126)
72594+ *(grarg + execlen + x) = ' ';
72595+ }
72596+
72597+ execlen += len;
72598+ *(grarg + execlen) = ' ';
72599+ *(grarg + execlen + 1) = '\0';
72600+ execlen++;
72601+ }
72602+
72603+ log:
72604+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
72605+ bprm->file->f_path.mnt, grarg);
72606+ mutex_unlock(&gr_exec_arg_mutex);
72607+#endif
72608+ return;
72609+}
72610+
72611+#ifdef CONFIG_GRKERNSEC
72612+extern int gr_acl_is_capable(const int cap);
72613+extern int gr_acl_is_capable_nolog(const int cap);
72614+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72615+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
72616+extern int gr_chroot_is_capable(const int cap);
72617+extern int gr_chroot_is_capable_nolog(const int cap);
72618+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72619+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
72620+#endif
72621+
72622+const char *captab_log[] = {
72623+ "CAP_CHOWN",
72624+ "CAP_DAC_OVERRIDE",
72625+ "CAP_DAC_READ_SEARCH",
72626+ "CAP_FOWNER",
72627+ "CAP_FSETID",
72628+ "CAP_KILL",
72629+ "CAP_SETGID",
72630+ "CAP_SETUID",
72631+ "CAP_SETPCAP",
72632+ "CAP_LINUX_IMMUTABLE",
72633+ "CAP_NET_BIND_SERVICE",
72634+ "CAP_NET_BROADCAST",
72635+ "CAP_NET_ADMIN",
72636+ "CAP_NET_RAW",
72637+ "CAP_IPC_LOCK",
72638+ "CAP_IPC_OWNER",
72639+ "CAP_SYS_MODULE",
72640+ "CAP_SYS_RAWIO",
72641+ "CAP_SYS_CHROOT",
72642+ "CAP_SYS_PTRACE",
72643+ "CAP_SYS_PACCT",
72644+ "CAP_SYS_ADMIN",
72645+ "CAP_SYS_BOOT",
72646+ "CAP_SYS_NICE",
72647+ "CAP_SYS_RESOURCE",
72648+ "CAP_SYS_TIME",
72649+ "CAP_SYS_TTY_CONFIG",
72650+ "CAP_MKNOD",
72651+ "CAP_LEASE",
72652+ "CAP_AUDIT_WRITE",
72653+ "CAP_AUDIT_CONTROL",
72654+ "CAP_SETFCAP",
72655+ "CAP_MAC_OVERRIDE",
72656+ "CAP_MAC_ADMIN",
72657+ "CAP_SYSLOG",
72658+ "CAP_WAKE_ALARM"
72659+};
72660+
72661+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
72662+
72663+int gr_is_capable(const int cap)
72664+{
72665+#ifdef CONFIG_GRKERNSEC
72666+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
72667+ return 1;
72668+ return 0;
72669+#else
72670+ return 1;
72671+#endif
72672+}
72673+
72674+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72675+{
72676+#ifdef CONFIG_GRKERNSEC
72677+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
72678+ return 1;
72679+ return 0;
72680+#else
72681+ return 1;
72682+#endif
72683+}
72684+
72685+int gr_is_capable_nolog(const int cap)
72686+{
72687+#ifdef CONFIG_GRKERNSEC
72688+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
72689+ return 1;
72690+ return 0;
72691+#else
72692+ return 1;
72693+#endif
72694+}
72695+
72696+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
72697+{
72698+#ifdef CONFIG_GRKERNSEC
72699+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
72700+ return 1;
72701+ return 0;
72702+#else
72703+ return 1;
72704+#endif
72705+}
72706+
72707+EXPORT_SYMBOL(gr_is_capable);
72708+EXPORT_SYMBOL(gr_is_capable_nolog);
72709+EXPORT_SYMBOL(gr_task_is_capable);
72710+EXPORT_SYMBOL(gr_task_is_capable_nolog);
72711diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
72712new file mode 100644
72713index 0000000..06cc6ea
72714--- /dev/null
72715+++ b/grsecurity/grsec_fifo.c
72716@@ -0,0 +1,24 @@
72717+#include <linux/kernel.h>
72718+#include <linux/sched.h>
72719+#include <linux/fs.h>
72720+#include <linux/file.h>
72721+#include <linux/grinternal.h>
72722+
72723+int
72724+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
72725+ const struct dentry *dir, const int flag, const int acc_mode)
72726+{
72727+#ifdef CONFIG_GRKERNSEC_FIFO
72728+ const struct cred *cred = current_cred();
72729+
72730+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
72731+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
72732+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
72733+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
72734+ if (!inode_permission(dentry->d_inode, acc_mode))
72735+ 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));
72736+ return -EACCES;
72737+ }
72738+#endif
72739+ return 0;
72740+}
72741diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
72742new file mode 100644
72743index 0000000..8ca18bf
72744--- /dev/null
72745+++ b/grsecurity/grsec_fork.c
72746@@ -0,0 +1,23 @@
72747+#include <linux/kernel.h>
72748+#include <linux/sched.h>
72749+#include <linux/grsecurity.h>
72750+#include <linux/grinternal.h>
72751+#include <linux/errno.h>
72752+
72753+void
72754+gr_log_forkfail(const int retval)
72755+{
72756+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72757+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
72758+ switch (retval) {
72759+ case -EAGAIN:
72760+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
72761+ break;
72762+ case -ENOMEM:
72763+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
72764+ break;
72765+ }
72766+ }
72767+#endif
72768+ return;
72769+}
72770diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
72771new file mode 100644
72772index 0000000..a88e901
72773--- /dev/null
72774+++ b/grsecurity/grsec_init.c
72775@@ -0,0 +1,272 @@
72776+#include <linux/kernel.h>
72777+#include <linux/sched.h>
72778+#include <linux/mm.h>
72779+#include <linux/gracl.h>
72780+#include <linux/slab.h>
72781+#include <linux/vmalloc.h>
72782+#include <linux/percpu.h>
72783+#include <linux/module.h>
72784+
72785+int grsec_enable_ptrace_readexec;
72786+int grsec_enable_setxid;
72787+int grsec_enable_symlinkown;
72788+kgid_t grsec_symlinkown_gid;
72789+int grsec_enable_brute;
72790+int grsec_enable_link;
72791+int grsec_enable_dmesg;
72792+int grsec_enable_harden_ptrace;
72793+int grsec_enable_harden_ipc;
72794+int grsec_enable_fifo;
72795+int grsec_enable_execlog;
72796+int grsec_enable_signal;
72797+int grsec_enable_forkfail;
72798+int grsec_enable_audit_ptrace;
72799+int grsec_enable_time;
72800+int grsec_enable_group;
72801+kgid_t grsec_audit_gid;
72802+int grsec_enable_chdir;
72803+int grsec_enable_mount;
72804+int grsec_enable_rofs;
72805+int grsec_deny_new_usb;
72806+int grsec_enable_chroot_findtask;
72807+int grsec_enable_chroot_mount;
72808+int grsec_enable_chroot_shmat;
72809+int grsec_enable_chroot_fchdir;
72810+int grsec_enable_chroot_double;
72811+int grsec_enable_chroot_pivot;
72812+int grsec_enable_chroot_chdir;
72813+int grsec_enable_chroot_chmod;
72814+int grsec_enable_chroot_mknod;
72815+int grsec_enable_chroot_nice;
72816+int grsec_enable_chroot_execlog;
72817+int grsec_enable_chroot_caps;
72818+int grsec_enable_chroot_sysctl;
72819+int grsec_enable_chroot_unix;
72820+int grsec_enable_tpe;
72821+kgid_t grsec_tpe_gid;
72822+int grsec_enable_blackhole;
72823+#ifdef CONFIG_IPV6_MODULE
72824+EXPORT_SYMBOL(grsec_enable_blackhole);
72825+#endif
72826+int grsec_lastack_retries;
72827+int grsec_enable_tpe_all;
72828+int grsec_enable_tpe_invert;
72829+int grsec_enable_socket_all;
72830+kgid_t grsec_socket_all_gid;
72831+int grsec_enable_socket_client;
72832+kgid_t grsec_socket_client_gid;
72833+int grsec_enable_socket_server;
72834+kgid_t grsec_socket_server_gid;
72835+int grsec_resource_logging;
72836+int grsec_disable_privio;
72837+int grsec_enable_log_rwxmaps;
72838+int grsec_lock;
72839+
72840+DEFINE_SPINLOCK(grsec_alert_lock);
72841+unsigned long grsec_alert_wtime = 0;
72842+unsigned long grsec_alert_fyet = 0;
72843+
72844+DEFINE_SPINLOCK(grsec_audit_lock);
72845+
72846+DEFINE_RWLOCK(grsec_exec_file_lock);
72847+
72848+char *gr_shared_page[4];
72849+
72850+char *gr_alert_log_fmt;
72851+char *gr_audit_log_fmt;
72852+char *gr_alert_log_buf;
72853+char *gr_audit_log_buf;
72854+
72855+void __init
72856+grsecurity_init(void)
72857+{
72858+ int j;
72859+ /* create the per-cpu shared pages */
72860+
72861+#ifdef CONFIG_X86
72862+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
72863+#endif
72864+
72865+ for (j = 0; j < 4; j++) {
72866+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
72867+ if (gr_shared_page[j] == NULL) {
72868+ panic("Unable to allocate grsecurity shared page");
72869+ return;
72870+ }
72871+ }
72872+
72873+ /* allocate log buffers */
72874+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
72875+ if (!gr_alert_log_fmt) {
72876+ panic("Unable to allocate grsecurity alert log format buffer");
72877+ return;
72878+ }
72879+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
72880+ if (!gr_audit_log_fmt) {
72881+ panic("Unable to allocate grsecurity audit log format buffer");
72882+ return;
72883+ }
72884+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
72885+ if (!gr_alert_log_buf) {
72886+ panic("Unable to allocate grsecurity alert log buffer");
72887+ return;
72888+ }
72889+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
72890+ if (!gr_audit_log_buf) {
72891+ panic("Unable to allocate grsecurity audit log buffer");
72892+ return;
72893+ }
72894+
72895+#ifdef CONFIG_GRKERNSEC_IO
72896+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
72897+ grsec_disable_privio = 1;
72898+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
72899+ grsec_disable_privio = 1;
72900+#else
72901+ grsec_disable_privio = 0;
72902+#endif
72903+#endif
72904+
72905+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72906+ /* for backward compatibility, tpe_invert always defaults to on if
72907+ enabled in the kernel
72908+ */
72909+ grsec_enable_tpe_invert = 1;
72910+#endif
72911+
72912+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
72913+#ifndef CONFIG_GRKERNSEC_SYSCTL
72914+ grsec_lock = 1;
72915+#endif
72916+
72917+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72918+ grsec_enable_log_rwxmaps = 1;
72919+#endif
72920+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
72921+ grsec_enable_group = 1;
72922+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
72923+#endif
72924+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
72925+ grsec_enable_ptrace_readexec = 1;
72926+#endif
72927+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72928+ grsec_enable_chdir = 1;
72929+#endif
72930+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72931+ grsec_enable_harden_ptrace = 1;
72932+#endif
72933+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
72934+ grsec_enable_harden_ipc = 1;
72935+#endif
72936+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72937+ grsec_enable_mount = 1;
72938+#endif
72939+#ifdef CONFIG_GRKERNSEC_LINK
72940+ grsec_enable_link = 1;
72941+#endif
72942+#ifdef CONFIG_GRKERNSEC_BRUTE
72943+ grsec_enable_brute = 1;
72944+#endif
72945+#ifdef CONFIG_GRKERNSEC_DMESG
72946+ grsec_enable_dmesg = 1;
72947+#endif
72948+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72949+ grsec_enable_blackhole = 1;
72950+ grsec_lastack_retries = 4;
72951+#endif
72952+#ifdef CONFIG_GRKERNSEC_FIFO
72953+ grsec_enable_fifo = 1;
72954+#endif
72955+#ifdef CONFIG_GRKERNSEC_EXECLOG
72956+ grsec_enable_execlog = 1;
72957+#endif
72958+#ifdef CONFIG_GRKERNSEC_SETXID
72959+ grsec_enable_setxid = 1;
72960+#endif
72961+#ifdef CONFIG_GRKERNSEC_SIGNAL
72962+ grsec_enable_signal = 1;
72963+#endif
72964+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72965+ grsec_enable_forkfail = 1;
72966+#endif
72967+#ifdef CONFIG_GRKERNSEC_TIME
72968+ grsec_enable_time = 1;
72969+#endif
72970+#ifdef CONFIG_GRKERNSEC_RESLOG
72971+ grsec_resource_logging = 1;
72972+#endif
72973+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72974+ grsec_enable_chroot_findtask = 1;
72975+#endif
72976+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72977+ grsec_enable_chroot_unix = 1;
72978+#endif
72979+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72980+ grsec_enable_chroot_mount = 1;
72981+#endif
72982+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72983+ grsec_enable_chroot_fchdir = 1;
72984+#endif
72985+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72986+ grsec_enable_chroot_shmat = 1;
72987+#endif
72988+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72989+ grsec_enable_audit_ptrace = 1;
72990+#endif
72991+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72992+ grsec_enable_chroot_double = 1;
72993+#endif
72994+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72995+ grsec_enable_chroot_pivot = 1;
72996+#endif
72997+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72998+ grsec_enable_chroot_chdir = 1;
72999+#endif
73000+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73001+ grsec_enable_chroot_chmod = 1;
73002+#endif
73003+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73004+ grsec_enable_chroot_mknod = 1;
73005+#endif
73006+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73007+ grsec_enable_chroot_nice = 1;
73008+#endif
73009+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73010+ grsec_enable_chroot_execlog = 1;
73011+#endif
73012+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73013+ grsec_enable_chroot_caps = 1;
73014+#endif
73015+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73016+ grsec_enable_chroot_sysctl = 1;
73017+#endif
73018+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73019+ grsec_enable_symlinkown = 1;
73020+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
73021+#endif
73022+#ifdef CONFIG_GRKERNSEC_TPE
73023+ grsec_enable_tpe = 1;
73024+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
73025+#ifdef CONFIG_GRKERNSEC_TPE_ALL
73026+ grsec_enable_tpe_all = 1;
73027+#endif
73028+#endif
73029+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73030+ grsec_enable_socket_all = 1;
73031+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
73032+#endif
73033+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
73034+ grsec_enable_socket_client = 1;
73035+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
73036+#endif
73037+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
73038+ grsec_enable_socket_server = 1;
73039+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
73040+#endif
73041+#endif
73042+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
73043+ grsec_deny_new_usb = 1;
73044+#endif
73045+
73046+ return;
73047+}
73048diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
73049new file mode 100644
73050index 0000000..78d1680
73051--- /dev/null
73052+++ b/grsecurity/grsec_ipc.c
73053@@ -0,0 +1,48 @@
73054+#include <linux/kernel.h>
73055+#include <linux/mm.h>
73056+#include <linux/sched.h>
73057+#include <linux/file.h>
73058+#include <linux/ipc.h>
73059+#include <linux/ipc_namespace.h>
73060+#include <linux/grsecurity.h>
73061+#include <linux/grinternal.h>
73062+
73063+int
73064+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
73065+{
73066+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73067+ int write;
73068+ int orig_granted_mode;
73069+ kuid_t euid;
73070+ kgid_t egid;
73071+
73072+ if (!grsec_enable_harden_ipc)
73073+ return 0;
73074+
73075+ euid = current_euid();
73076+ egid = current_egid();
73077+
73078+ write = requested_mode & 00002;
73079+ orig_granted_mode = ipcp->mode;
73080+
73081+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
73082+ orig_granted_mode >>= 6;
73083+ else {
73084+ /* if likely wrong permissions, lock to user */
73085+ if (orig_granted_mode & 0007)
73086+ orig_granted_mode = 0;
73087+ /* otherwise do a egid-only check */
73088+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
73089+ orig_granted_mode >>= 3;
73090+ /* otherwise, no access */
73091+ else
73092+ orig_granted_mode = 0;
73093+ }
73094+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
73095+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
73096+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
73097+ return 0;
73098+ }
73099+#endif
73100+ return 1;
73101+}
73102diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
73103new file mode 100644
73104index 0000000..5e05e20
73105--- /dev/null
73106+++ b/grsecurity/grsec_link.c
73107@@ -0,0 +1,58 @@
73108+#include <linux/kernel.h>
73109+#include <linux/sched.h>
73110+#include <linux/fs.h>
73111+#include <linux/file.h>
73112+#include <linux/grinternal.h>
73113+
73114+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
73115+{
73116+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73117+ const struct inode *link_inode = link->dentry->d_inode;
73118+
73119+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
73120+ /* ignore root-owned links, e.g. /proc/self */
73121+ gr_is_global_nonroot(link_inode->i_uid) && target &&
73122+ !uid_eq(link_inode->i_uid, target->i_uid)) {
73123+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
73124+ return 1;
73125+ }
73126+#endif
73127+ return 0;
73128+}
73129+
73130+int
73131+gr_handle_follow_link(const struct inode *parent,
73132+ const struct inode *inode,
73133+ const struct dentry *dentry, const struct vfsmount *mnt)
73134+{
73135+#ifdef CONFIG_GRKERNSEC_LINK
73136+ const struct cred *cred = current_cred();
73137+
73138+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
73139+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
73140+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
73141+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
73142+ return -EACCES;
73143+ }
73144+#endif
73145+ return 0;
73146+}
73147+
73148+int
73149+gr_handle_hardlink(const struct dentry *dentry,
73150+ const struct vfsmount *mnt,
73151+ struct inode *inode, const int mode, const struct filename *to)
73152+{
73153+#ifdef CONFIG_GRKERNSEC_LINK
73154+ const struct cred *cred = current_cred();
73155+
73156+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
73157+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
73158+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
73159+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
73160+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
73161+ return -EPERM;
73162+ }
73163+#endif
73164+ return 0;
73165+}
73166diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
73167new file mode 100644
73168index 0000000..dbe0a6b
73169--- /dev/null
73170+++ b/grsecurity/grsec_log.c
73171@@ -0,0 +1,341 @@
73172+#include <linux/kernel.h>
73173+#include <linux/sched.h>
73174+#include <linux/file.h>
73175+#include <linux/tty.h>
73176+#include <linux/fs.h>
73177+#include <linux/mm.h>
73178+#include <linux/grinternal.h>
73179+
73180+#ifdef CONFIG_TREE_PREEMPT_RCU
73181+#define DISABLE_PREEMPT() preempt_disable()
73182+#define ENABLE_PREEMPT() preempt_enable()
73183+#else
73184+#define DISABLE_PREEMPT()
73185+#define ENABLE_PREEMPT()
73186+#endif
73187+
73188+#define BEGIN_LOCKS(x) \
73189+ DISABLE_PREEMPT(); \
73190+ rcu_read_lock(); \
73191+ read_lock(&tasklist_lock); \
73192+ read_lock(&grsec_exec_file_lock); \
73193+ if (x != GR_DO_AUDIT) \
73194+ spin_lock(&grsec_alert_lock); \
73195+ else \
73196+ spin_lock(&grsec_audit_lock)
73197+
73198+#define END_LOCKS(x) \
73199+ if (x != GR_DO_AUDIT) \
73200+ spin_unlock(&grsec_alert_lock); \
73201+ else \
73202+ spin_unlock(&grsec_audit_lock); \
73203+ read_unlock(&grsec_exec_file_lock); \
73204+ read_unlock(&tasklist_lock); \
73205+ rcu_read_unlock(); \
73206+ ENABLE_PREEMPT(); \
73207+ if (x == GR_DONT_AUDIT) \
73208+ gr_handle_alertkill(current)
73209+
73210+enum {
73211+ FLOODING,
73212+ NO_FLOODING
73213+};
73214+
73215+extern char *gr_alert_log_fmt;
73216+extern char *gr_audit_log_fmt;
73217+extern char *gr_alert_log_buf;
73218+extern char *gr_audit_log_buf;
73219+
73220+static int gr_log_start(int audit)
73221+{
73222+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
73223+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
73224+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73225+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
73226+ unsigned long curr_secs = get_seconds();
73227+
73228+ if (audit == GR_DO_AUDIT)
73229+ goto set_fmt;
73230+
73231+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
73232+ grsec_alert_wtime = curr_secs;
73233+ grsec_alert_fyet = 0;
73234+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
73235+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
73236+ grsec_alert_fyet++;
73237+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
73238+ grsec_alert_wtime = curr_secs;
73239+ grsec_alert_fyet++;
73240+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
73241+ return FLOODING;
73242+ }
73243+ else return FLOODING;
73244+
73245+set_fmt:
73246+#endif
73247+ memset(buf, 0, PAGE_SIZE);
73248+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
73249+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
73250+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73251+ } else if (current->signal->curr_ip) {
73252+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
73253+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
73254+ } else if (gr_acl_is_enabled()) {
73255+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
73256+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73257+ } else {
73258+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
73259+ strcpy(buf, fmt);
73260+ }
73261+
73262+ return NO_FLOODING;
73263+}
73264+
73265+static void gr_log_middle(int audit, const char *msg, va_list ap)
73266+ __attribute__ ((format (printf, 2, 0)));
73267+
73268+static void gr_log_middle(int audit, const char *msg, va_list ap)
73269+{
73270+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73271+ unsigned int len = strlen(buf);
73272+
73273+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73274+
73275+ return;
73276+}
73277+
73278+static void gr_log_middle_varargs(int audit, const char *msg, ...)
73279+ __attribute__ ((format (printf, 2, 3)));
73280+
73281+static void gr_log_middle_varargs(int audit, const char *msg, ...)
73282+{
73283+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73284+ unsigned int len = strlen(buf);
73285+ va_list ap;
73286+
73287+ va_start(ap, msg);
73288+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73289+ va_end(ap);
73290+
73291+ return;
73292+}
73293+
73294+static void gr_log_end(int audit, int append_default)
73295+{
73296+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73297+ if (append_default) {
73298+ struct task_struct *task = current;
73299+ struct task_struct *parent = task->real_parent;
73300+ const struct cred *cred = __task_cred(task);
73301+ const struct cred *pcred = __task_cred(parent);
73302+ unsigned int len = strlen(buf);
73303+
73304+ 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));
73305+ }
73306+
73307+ printk("%s\n", buf);
73308+
73309+ return;
73310+}
73311+
73312+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
73313+{
73314+ int logtype;
73315+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
73316+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
73317+ void *voidptr = NULL;
73318+ int num1 = 0, num2 = 0;
73319+ unsigned long ulong1 = 0, ulong2 = 0;
73320+ struct dentry *dentry = NULL;
73321+ struct vfsmount *mnt = NULL;
73322+ struct file *file = NULL;
73323+ struct task_struct *task = NULL;
73324+ struct vm_area_struct *vma = NULL;
73325+ const struct cred *cred, *pcred;
73326+ va_list ap;
73327+
73328+ BEGIN_LOCKS(audit);
73329+ logtype = gr_log_start(audit);
73330+ if (logtype == FLOODING) {
73331+ END_LOCKS(audit);
73332+ return;
73333+ }
73334+ va_start(ap, argtypes);
73335+ switch (argtypes) {
73336+ case GR_TTYSNIFF:
73337+ task = va_arg(ap, struct task_struct *);
73338+ 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));
73339+ break;
73340+ case GR_SYSCTL_HIDDEN:
73341+ str1 = va_arg(ap, char *);
73342+ gr_log_middle_varargs(audit, msg, result, str1);
73343+ break;
73344+ case GR_RBAC:
73345+ dentry = va_arg(ap, struct dentry *);
73346+ mnt = va_arg(ap, struct vfsmount *);
73347+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
73348+ break;
73349+ case GR_RBAC_STR:
73350+ dentry = va_arg(ap, struct dentry *);
73351+ mnt = va_arg(ap, struct vfsmount *);
73352+ str1 = va_arg(ap, char *);
73353+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
73354+ break;
73355+ case GR_STR_RBAC:
73356+ str1 = va_arg(ap, char *);
73357+ dentry = va_arg(ap, struct dentry *);
73358+ mnt = va_arg(ap, struct vfsmount *);
73359+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
73360+ break;
73361+ case GR_RBAC_MODE2:
73362+ dentry = va_arg(ap, struct dentry *);
73363+ mnt = va_arg(ap, struct vfsmount *);
73364+ str1 = va_arg(ap, char *);
73365+ str2 = va_arg(ap, char *);
73366+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
73367+ break;
73368+ case GR_RBAC_MODE3:
73369+ dentry = va_arg(ap, struct dentry *);
73370+ mnt = va_arg(ap, struct vfsmount *);
73371+ str1 = va_arg(ap, char *);
73372+ str2 = va_arg(ap, char *);
73373+ str3 = va_arg(ap, char *);
73374+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
73375+ break;
73376+ case GR_FILENAME:
73377+ dentry = va_arg(ap, struct dentry *);
73378+ mnt = va_arg(ap, struct vfsmount *);
73379+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
73380+ break;
73381+ case GR_STR_FILENAME:
73382+ str1 = va_arg(ap, char *);
73383+ dentry = va_arg(ap, struct dentry *);
73384+ mnt = va_arg(ap, struct vfsmount *);
73385+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
73386+ break;
73387+ case GR_FILENAME_STR:
73388+ dentry = va_arg(ap, struct dentry *);
73389+ mnt = va_arg(ap, struct vfsmount *);
73390+ str1 = va_arg(ap, char *);
73391+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
73392+ break;
73393+ case GR_FILENAME_TWO_INT:
73394+ dentry = va_arg(ap, struct dentry *);
73395+ mnt = va_arg(ap, struct vfsmount *);
73396+ num1 = va_arg(ap, int);
73397+ num2 = va_arg(ap, int);
73398+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
73399+ break;
73400+ case GR_FILENAME_TWO_INT_STR:
73401+ dentry = va_arg(ap, struct dentry *);
73402+ mnt = va_arg(ap, struct vfsmount *);
73403+ num1 = va_arg(ap, int);
73404+ num2 = va_arg(ap, int);
73405+ str1 = va_arg(ap, char *);
73406+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
73407+ break;
73408+ case GR_TEXTREL:
73409+ file = va_arg(ap, struct file *);
73410+ ulong1 = va_arg(ap, unsigned long);
73411+ ulong2 = va_arg(ap, unsigned long);
73412+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
73413+ break;
73414+ case GR_PTRACE:
73415+ task = va_arg(ap, struct task_struct *);
73416+ 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));
73417+ break;
73418+ case GR_RESOURCE:
73419+ task = va_arg(ap, struct task_struct *);
73420+ cred = __task_cred(task);
73421+ pcred = __task_cred(task->real_parent);
73422+ ulong1 = va_arg(ap, unsigned long);
73423+ str1 = va_arg(ap, char *);
73424+ ulong2 = va_arg(ap, unsigned long);
73425+ 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));
73426+ break;
73427+ case GR_CAP:
73428+ task = va_arg(ap, struct task_struct *);
73429+ cred = __task_cred(task);
73430+ pcred = __task_cred(task->real_parent);
73431+ str1 = va_arg(ap, char *);
73432+ 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));
73433+ break;
73434+ case GR_SIG:
73435+ str1 = va_arg(ap, char *);
73436+ voidptr = va_arg(ap, void *);
73437+ gr_log_middle_varargs(audit, msg, str1, voidptr);
73438+ break;
73439+ case GR_SIG2:
73440+ task = va_arg(ap, struct task_struct *);
73441+ cred = __task_cred(task);
73442+ pcred = __task_cred(task->real_parent);
73443+ num1 = va_arg(ap, int);
73444+ 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));
73445+ break;
73446+ case GR_CRASH1:
73447+ task = va_arg(ap, struct task_struct *);
73448+ cred = __task_cred(task);
73449+ pcred = __task_cred(task->real_parent);
73450+ ulong1 = va_arg(ap, unsigned long);
73451+ 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);
73452+ break;
73453+ case GR_CRASH2:
73454+ task = va_arg(ap, struct task_struct *);
73455+ cred = __task_cred(task);
73456+ pcred = __task_cred(task->real_parent);
73457+ ulong1 = va_arg(ap, unsigned long);
73458+ 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);
73459+ break;
73460+ case GR_RWXMAP:
73461+ file = va_arg(ap, struct file *);
73462+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
73463+ break;
73464+ case GR_RWXMAPVMA:
73465+ vma = va_arg(ap, struct vm_area_struct *);
73466+ if (vma->vm_file)
73467+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
73468+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
73469+ str1 = "<stack>";
73470+ else if (vma->vm_start <= current->mm->brk &&
73471+ vma->vm_end >= current->mm->start_brk)
73472+ str1 = "<heap>";
73473+ else
73474+ str1 = "<anonymous mapping>";
73475+ gr_log_middle_varargs(audit, msg, str1);
73476+ break;
73477+ case GR_PSACCT:
73478+ {
73479+ unsigned int wday, cday;
73480+ __u8 whr, chr;
73481+ __u8 wmin, cmin;
73482+ __u8 wsec, csec;
73483+ char cur_tty[64] = { 0 };
73484+ char parent_tty[64] = { 0 };
73485+
73486+ task = va_arg(ap, struct task_struct *);
73487+ wday = va_arg(ap, unsigned int);
73488+ cday = va_arg(ap, unsigned int);
73489+ whr = va_arg(ap, int);
73490+ chr = va_arg(ap, int);
73491+ wmin = va_arg(ap, int);
73492+ cmin = va_arg(ap, int);
73493+ wsec = va_arg(ap, int);
73494+ csec = va_arg(ap, int);
73495+ ulong1 = va_arg(ap, unsigned long);
73496+ cred = __task_cred(task);
73497+ pcred = __task_cred(task->real_parent);
73498+
73499+ 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));
73500+ }
73501+ break;
73502+ default:
73503+ gr_log_middle(audit, msg, ap);
73504+ }
73505+ va_end(ap);
73506+ // these don't need DEFAULTSECARGS printed on the end
73507+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
73508+ gr_log_end(audit, 0);
73509+ else
73510+ gr_log_end(audit, 1);
73511+ END_LOCKS(audit);
73512+}
73513diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
73514new file mode 100644
73515index 0000000..f536303
73516--- /dev/null
73517+++ b/grsecurity/grsec_mem.c
73518@@ -0,0 +1,40 @@
73519+#include <linux/kernel.h>
73520+#include <linux/sched.h>
73521+#include <linux/mm.h>
73522+#include <linux/mman.h>
73523+#include <linux/grinternal.h>
73524+
73525+void
73526+gr_handle_ioperm(void)
73527+{
73528+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
73529+ return;
73530+}
73531+
73532+void
73533+gr_handle_iopl(void)
73534+{
73535+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
73536+ return;
73537+}
73538+
73539+void
73540+gr_handle_mem_readwrite(u64 from, u64 to)
73541+{
73542+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
73543+ return;
73544+}
73545+
73546+void
73547+gr_handle_vm86(void)
73548+{
73549+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
73550+ return;
73551+}
73552+
73553+void
73554+gr_log_badprocpid(const char *entry)
73555+{
73556+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
73557+ return;
73558+}
73559diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
73560new file mode 100644
73561index 0000000..cd9e124
73562--- /dev/null
73563+++ b/grsecurity/grsec_mount.c
73564@@ -0,0 +1,65 @@
73565+#include <linux/kernel.h>
73566+#include <linux/sched.h>
73567+#include <linux/mount.h>
73568+#include <linux/major.h>
73569+#include <linux/grsecurity.h>
73570+#include <linux/grinternal.h>
73571+
73572+void
73573+gr_log_remount(const char *devname, const int retval)
73574+{
73575+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73576+ if (grsec_enable_mount && (retval >= 0))
73577+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
73578+#endif
73579+ return;
73580+}
73581+
73582+void
73583+gr_log_unmount(const char *devname, const int retval)
73584+{
73585+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73586+ if (grsec_enable_mount && (retval >= 0))
73587+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
73588+#endif
73589+ return;
73590+}
73591+
73592+void
73593+gr_log_mount(const char *from, const char *to, const int retval)
73594+{
73595+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73596+ if (grsec_enable_mount && (retval >= 0))
73597+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
73598+#endif
73599+ return;
73600+}
73601+
73602+int
73603+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
73604+{
73605+#ifdef CONFIG_GRKERNSEC_ROFS
73606+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
73607+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
73608+ return -EPERM;
73609+ } else
73610+ return 0;
73611+#endif
73612+ return 0;
73613+}
73614+
73615+int
73616+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
73617+{
73618+#ifdef CONFIG_GRKERNSEC_ROFS
73619+ struct inode *inode = dentry->d_inode;
73620+
73621+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
73622+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
73623+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
73624+ return -EPERM;
73625+ } else
73626+ return 0;
73627+#endif
73628+ return 0;
73629+}
73630diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
73631new file mode 100644
73632index 0000000..6ee9d50
73633--- /dev/null
73634+++ b/grsecurity/grsec_pax.c
73635@@ -0,0 +1,45 @@
73636+#include <linux/kernel.h>
73637+#include <linux/sched.h>
73638+#include <linux/mm.h>
73639+#include <linux/file.h>
73640+#include <linux/grinternal.h>
73641+#include <linux/grsecurity.h>
73642+
73643+void
73644+gr_log_textrel(struct vm_area_struct * vma)
73645+{
73646+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73647+ if (grsec_enable_log_rwxmaps)
73648+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
73649+#endif
73650+ return;
73651+}
73652+
73653+void gr_log_ptgnustack(struct file *file)
73654+{
73655+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73656+ if (grsec_enable_log_rwxmaps)
73657+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
73658+#endif
73659+ return;
73660+}
73661+
73662+void
73663+gr_log_rwxmmap(struct file *file)
73664+{
73665+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73666+ if (grsec_enable_log_rwxmaps)
73667+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
73668+#endif
73669+ return;
73670+}
73671+
73672+void
73673+gr_log_rwxmprotect(struct vm_area_struct *vma)
73674+{
73675+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73676+ if (grsec_enable_log_rwxmaps)
73677+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
73678+#endif
73679+ return;
73680+}
73681diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
73682new file mode 100644
73683index 0000000..f7f29aa
73684--- /dev/null
73685+++ b/grsecurity/grsec_ptrace.c
73686@@ -0,0 +1,30 @@
73687+#include <linux/kernel.h>
73688+#include <linux/sched.h>
73689+#include <linux/grinternal.h>
73690+#include <linux/security.h>
73691+
73692+void
73693+gr_audit_ptrace(struct task_struct *task)
73694+{
73695+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73696+ if (grsec_enable_audit_ptrace)
73697+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
73698+#endif
73699+ return;
73700+}
73701+
73702+int
73703+gr_ptrace_readexec(struct file *file, int unsafe_flags)
73704+{
73705+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73706+ const struct dentry *dentry = file->f_path.dentry;
73707+ const struct vfsmount *mnt = file->f_path.mnt;
73708+
73709+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
73710+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
73711+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
73712+ return -EACCES;
73713+ }
73714+#endif
73715+ return 0;
73716+}
73717diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
73718new file mode 100644
73719index 0000000..3860c7e
73720--- /dev/null
73721+++ b/grsecurity/grsec_sig.c
73722@@ -0,0 +1,236 @@
73723+#include <linux/kernel.h>
73724+#include <linux/sched.h>
73725+#include <linux/fs.h>
73726+#include <linux/delay.h>
73727+#include <linux/grsecurity.h>
73728+#include <linux/grinternal.h>
73729+#include <linux/hardirq.h>
73730+
73731+char *signames[] = {
73732+ [SIGSEGV] = "Segmentation fault",
73733+ [SIGILL] = "Illegal instruction",
73734+ [SIGABRT] = "Abort",
73735+ [SIGBUS] = "Invalid alignment/Bus error"
73736+};
73737+
73738+void
73739+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
73740+{
73741+#ifdef CONFIG_GRKERNSEC_SIGNAL
73742+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
73743+ (sig == SIGABRT) || (sig == SIGBUS))) {
73744+ if (task_pid_nr(t) == task_pid_nr(current)) {
73745+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
73746+ } else {
73747+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
73748+ }
73749+ }
73750+#endif
73751+ return;
73752+}
73753+
73754+int
73755+gr_handle_signal(const struct task_struct *p, const int sig)
73756+{
73757+#ifdef CONFIG_GRKERNSEC
73758+ /* ignore the 0 signal for protected task checks */
73759+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
73760+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
73761+ return -EPERM;
73762+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
73763+ return -EPERM;
73764+ }
73765+#endif
73766+ return 0;
73767+}
73768+
73769+#ifdef CONFIG_GRKERNSEC
73770+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
73771+
73772+int gr_fake_force_sig(int sig, struct task_struct *t)
73773+{
73774+ unsigned long int flags;
73775+ int ret, blocked, ignored;
73776+ struct k_sigaction *action;
73777+
73778+ spin_lock_irqsave(&t->sighand->siglock, flags);
73779+ action = &t->sighand->action[sig-1];
73780+ ignored = action->sa.sa_handler == SIG_IGN;
73781+ blocked = sigismember(&t->blocked, sig);
73782+ if (blocked || ignored) {
73783+ action->sa.sa_handler = SIG_DFL;
73784+ if (blocked) {
73785+ sigdelset(&t->blocked, sig);
73786+ recalc_sigpending_and_wake(t);
73787+ }
73788+ }
73789+ if (action->sa.sa_handler == SIG_DFL)
73790+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
73791+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
73792+
73793+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
73794+
73795+ return ret;
73796+}
73797+#endif
73798+
73799+#define GR_USER_BAN_TIME (15 * 60)
73800+#define GR_DAEMON_BRUTE_TIME (30 * 60)
73801+
73802+void gr_handle_brute_attach(int dumpable)
73803+{
73804+#ifdef CONFIG_GRKERNSEC_BRUTE
73805+ struct task_struct *p = current;
73806+ kuid_t uid = GLOBAL_ROOT_UID;
73807+ int daemon = 0;
73808+
73809+ if (!grsec_enable_brute)
73810+ return;
73811+
73812+ rcu_read_lock();
73813+ read_lock(&tasklist_lock);
73814+ read_lock(&grsec_exec_file_lock);
73815+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
73816+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
73817+ p->real_parent->brute = 1;
73818+ daemon = 1;
73819+ } else {
73820+ const struct cred *cred = __task_cred(p), *cred2;
73821+ struct task_struct *tsk, *tsk2;
73822+
73823+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
73824+ struct user_struct *user;
73825+
73826+ uid = cred->uid;
73827+
73828+ /* this is put upon execution past expiration */
73829+ user = find_user(uid);
73830+ if (user == NULL)
73831+ goto unlock;
73832+ user->suid_banned = 1;
73833+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
73834+ if (user->suid_ban_expires == ~0UL)
73835+ user->suid_ban_expires--;
73836+
73837+ /* only kill other threads of the same binary, from the same user */
73838+ do_each_thread(tsk2, tsk) {
73839+ cred2 = __task_cred(tsk);
73840+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
73841+ gr_fake_force_sig(SIGKILL, tsk);
73842+ } while_each_thread(tsk2, tsk);
73843+ }
73844+ }
73845+unlock:
73846+ read_unlock(&grsec_exec_file_lock);
73847+ read_unlock(&tasklist_lock);
73848+ rcu_read_unlock();
73849+
73850+ if (gr_is_global_nonroot(uid))
73851+ 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);
73852+ else if (daemon)
73853+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
73854+
73855+#endif
73856+ return;
73857+}
73858+
73859+void gr_handle_brute_check(void)
73860+{
73861+#ifdef CONFIG_GRKERNSEC_BRUTE
73862+ struct task_struct *p = current;
73863+
73864+ if (unlikely(p->brute)) {
73865+ if (!grsec_enable_brute)
73866+ p->brute = 0;
73867+ else if (time_before(get_seconds(), p->brute_expires))
73868+ msleep(30 * 1000);
73869+ }
73870+#endif
73871+ return;
73872+}
73873+
73874+void gr_handle_kernel_exploit(void)
73875+{
73876+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
73877+ const struct cred *cred;
73878+ struct task_struct *tsk, *tsk2;
73879+ struct user_struct *user;
73880+ kuid_t uid;
73881+
73882+ if (in_irq() || in_serving_softirq() || in_nmi())
73883+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
73884+
73885+ uid = current_uid();
73886+
73887+ if (gr_is_global_root(uid))
73888+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
73889+ else {
73890+ /* kill all the processes of this user, hold a reference
73891+ to their creds struct, and prevent them from creating
73892+ another process until system reset
73893+ */
73894+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
73895+ GR_GLOBAL_UID(uid));
73896+ /* we intentionally leak this ref */
73897+ user = get_uid(current->cred->user);
73898+ if (user)
73899+ user->kernel_banned = 1;
73900+
73901+ /* kill all processes of this user */
73902+ read_lock(&tasklist_lock);
73903+ do_each_thread(tsk2, tsk) {
73904+ cred = __task_cred(tsk);
73905+ if (uid_eq(cred->uid, uid))
73906+ gr_fake_force_sig(SIGKILL, tsk);
73907+ } while_each_thread(tsk2, tsk);
73908+ read_unlock(&tasklist_lock);
73909+ }
73910+#endif
73911+}
73912+
73913+#ifdef CONFIG_GRKERNSEC_BRUTE
73914+static bool suid_ban_expired(struct user_struct *user)
73915+{
73916+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
73917+ user->suid_banned = 0;
73918+ user->suid_ban_expires = 0;
73919+ free_uid(user);
73920+ return true;
73921+ }
73922+
73923+ return false;
73924+}
73925+#endif
73926+
73927+int gr_process_kernel_exec_ban(void)
73928+{
73929+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
73930+ if (unlikely(current->cred->user->kernel_banned))
73931+ return -EPERM;
73932+#endif
73933+ return 0;
73934+}
73935+
73936+int gr_process_kernel_setuid_ban(struct user_struct *user)
73937+{
73938+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
73939+ if (unlikely(user->kernel_banned))
73940+ gr_fake_force_sig(SIGKILL, current);
73941+#endif
73942+ return 0;
73943+}
73944+
73945+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
73946+{
73947+#ifdef CONFIG_GRKERNSEC_BRUTE
73948+ struct user_struct *user = current->cred->user;
73949+ if (unlikely(user->suid_banned)) {
73950+ if (suid_ban_expired(user))
73951+ return 0;
73952+ /* disallow execution of suid binaries only */
73953+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
73954+ return -EPERM;
73955+ }
73956+#endif
73957+ return 0;
73958+}
73959diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
73960new file mode 100644
73961index 0000000..4030d57
73962--- /dev/null
73963+++ b/grsecurity/grsec_sock.c
73964@@ -0,0 +1,244 @@
73965+#include <linux/kernel.h>
73966+#include <linux/module.h>
73967+#include <linux/sched.h>
73968+#include <linux/file.h>
73969+#include <linux/net.h>
73970+#include <linux/in.h>
73971+#include <linux/ip.h>
73972+#include <net/sock.h>
73973+#include <net/inet_sock.h>
73974+#include <linux/grsecurity.h>
73975+#include <linux/grinternal.h>
73976+#include <linux/gracl.h>
73977+
73978+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
73979+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
73980+
73981+EXPORT_SYMBOL(gr_search_udp_recvmsg);
73982+EXPORT_SYMBOL(gr_search_udp_sendmsg);
73983+
73984+#ifdef CONFIG_UNIX_MODULE
73985+EXPORT_SYMBOL(gr_acl_handle_unix);
73986+EXPORT_SYMBOL(gr_acl_handle_mknod);
73987+EXPORT_SYMBOL(gr_handle_chroot_unix);
73988+EXPORT_SYMBOL(gr_handle_create);
73989+#endif
73990+
73991+#ifdef CONFIG_GRKERNSEC
73992+#define gr_conn_table_size 32749
73993+struct conn_table_entry {
73994+ struct conn_table_entry *next;
73995+ struct signal_struct *sig;
73996+};
73997+
73998+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
73999+DEFINE_SPINLOCK(gr_conn_table_lock);
74000+
74001+extern const char * gr_socktype_to_name(unsigned char type);
74002+extern const char * gr_proto_to_name(unsigned char proto);
74003+extern const char * gr_sockfamily_to_name(unsigned char family);
74004+
74005+static __inline__ int
74006+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
74007+{
74008+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
74009+}
74010+
74011+static __inline__ int
74012+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
74013+ __u16 sport, __u16 dport)
74014+{
74015+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
74016+ sig->gr_sport == sport && sig->gr_dport == dport))
74017+ return 1;
74018+ else
74019+ return 0;
74020+}
74021+
74022+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
74023+{
74024+ struct conn_table_entry **match;
74025+ unsigned int index;
74026+
74027+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74028+ sig->gr_sport, sig->gr_dport,
74029+ gr_conn_table_size);
74030+
74031+ newent->sig = sig;
74032+
74033+ match = &gr_conn_table[index];
74034+ newent->next = *match;
74035+ *match = newent;
74036+
74037+ return;
74038+}
74039+
74040+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
74041+{
74042+ struct conn_table_entry *match, *last = NULL;
74043+ unsigned int index;
74044+
74045+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74046+ sig->gr_sport, sig->gr_dport,
74047+ gr_conn_table_size);
74048+
74049+ match = gr_conn_table[index];
74050+ while (match && !conn_match(match->sig,
74051+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
74052+ sig->gr_dport)) {
74053+ last = match;
74054+ match = match->next;
74055+ }
74056+
74057+ if (match) {
74058+ if (last)
74059+ last->next = match->next;
74060+ else
74061+ gr_conn_table[index] = NULL;
74062+ kfree(match);
74063+ }
74064+
74065+ return;
74066+}
74067+
74068+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
74069+ __u16 sport, __u16 dport)
74070+{
74071+ struct conn_table_entry *match;
74072+ unsigned int index;
74073+
74074+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
74075+
74076+ match = gr_conn_table[index];
74077+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
74078+ match = match->next;
74079+
74080+ if (match)
74081+ return match->sig;
74082+ else
74083+ return NULL;
74084+}
74085+
74086+#endif
74087+
74088+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
74089+{
74090+#ifdef CONFIG_GRKERNSEC
74091+ struct signal_struct *sig = task->signal;
74092+ struct conn_table_entry *newent;
74093+
74094+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
74095+ if (newent == NULL)
74096+ return;
74097+ /* no bh lock needed since we are called with bh disabled */
74098+ spin_lock(&gr_conn_table_lock);
74099+ gr_del_task_from_ip_table_nolock(sig);
74100+ sig->gr_saddr = inet->inet_rcv_saddr;
74101+ sig->gr_daddr = inet->inet_daddr;
74102+ sig->gr_sport = inet->inet_sport;
74103+ sig->gr_dport = inet->inet_dport;
74104+ gr_add_to_task_ip_table_nolock(sig, newent);
74105+ spin_unlock(&gr_conn_table_lock);
74106+#endif
74107+ return;
74108+}
74109+
74110+void gr_del_task_from_ip_table(struct task_struct *task)
74111+{
74112+#ifdef CONFIG_GRKERNSEC
74113+ spin_lock_bh(&gr_conn_table_lock);
74114+ gr_del_task_from_ip_table_nolock(task->signal);
74115+ spin_unlock_bh(&gr_conn_table_lock);
74116+#endif
74117+ return;
74118+}
74119+
74120+void
74121+gr_attach_curr_ip(const struct sock *sk)
74122+{
74123+#ifdef CONFIG_GRKERNSEC
74124+ struct signal_struct *p, *set;
74125+ const struct inet_sock *inet = inet_sk(sk);
74126+
74127+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
74128+ return;
74129+
74130+ set = current->signal;
74131+
74132+ spin_lock_bh(&gr_conn_table_lock);
74133+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
74134+ inet->inet_dport, inet->inet_sport);
74135+ if (unlikely(p != NULL)) {
74136+ set->curr_ip = p->curr_ip;
74137+ set->used_accept = 1;
74138+ gr_del_task_from_ip_table_nolock(p);
74139+ spin_unlock_bh(&gr_conn_table_lock);
74140+ return;
74141+ }
74142+ spin_unlock_bh(&gr_conn_table_lock);
74143+
74144+ set->curr_ip = inet->inet_daddr;
74145+ set->used_accept = 1;
74146+#endif
74147+ return;
74148+}
74149+
74150+int
74151+gr_handle_sock_all(const int family, const int type, const int protocol)
74152+{
74153+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74154+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
74155+ (family != AF_UNIX)) {
74156+ if (family == AF_INET)
74157+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
74158+ else
74159+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
74160+ return -EACCES;
74161+ }
74162+#endif
74163+ return 0;
74164+}
74165+
74166+int
74167+gr_handle_sock_server(const struct sockaddr *sck)
74168+{
74169+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74170+ if (grsec_enable_socket_server &&
74171+ in_group_p(grsec_socket_server_gid) &&
74172+ sck && (sck->sa_family != AF_UNIX) &&
74173+ (sck->sa_family != AF_LOCAL)) {
74174+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74175+ return -EACCES;
74176+ }
74177+#endif
74178+ return 0;
74179+}
74180+
74181+int
74182+gr_handle_sock_server_other(const struct sock *sck)
74183+{
74184+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74185+ if (grsec_enable_socket_server &&
74186+ in_group_p(grsec_socket_server_gid) &&
74187+ sck && (sck->sk_family != AF_UNIX) &&
74188+ (sck->sk_family != AF_LOCAL)) {
74189+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74190+ return -EACCES;
74191+ }
74192+#endif
74193+ return 0;
74194+}
74195+
74196+int
74197+gr_handle_sock_client(const struct sockaddr *sck)
74198+{
74199+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74200+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
74201+ sck && (sck->sa_family != AF_UNIX) &&
74202+ (sck->sa_family != AF_LOCAL)) {
74203+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
74204+ return -EACCES;
74205+ }
74206+#endif
74207+ return 0;
74208+}
74209diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
74210new file mode 100644
74211index 0000000..8159888
74212--- /dev/null
74213+++ b/grsecurity/grsec_sysctl.c
74214@@ -0,0 +1,479 @@
74215+#include <linux/kernel.h>
74216+#include <linux/sched.h>
74217+#include <linux/sysctl.h>
74218+#include <linux/grsecurity.h>
74219+#include <linux/grinternal.h>
74220+
74221+int
74222+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
74223+{
74224+#ifdef CONFIG_GRKERNSEC_SYSCTL
74225+ if (dirname == NULL || name == NULL)
74226+ return 0;
74227+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
74228+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
74229+ return -EACCES;
74230+ }
74231+#endif
74232+ return 0;
74233+}
74234+
74235+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
74236+static int __maybe_unused __read_only one = 1;
74237+#endif
74238+
74239+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
74240+ defined(CONFIG_GRKERNSEC_DENYUSB)
74241+struct ctl_table grsecurity_table[] = {
74242+#ifdef CONFIG_GRKERNSEC_SYSCTL
74243+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
74244+#ifdef CONFIG_GRKERNSEC_IO
74245+ {
74246+ .procname = "disable_priv_io",
74247+ .data = &grsec_disable_privio,
74248+ .maxlen = sizeof(int),
74249+ .mode = 0600,
74250+ .proc_handler = &proc_dointvec,
74251+ },
74252+#endif
74253+#endif
74254+#ifdef CONFIG_GRKERNSEC_LINK
74255+ {
74256+ .procname = "linking_restrictions",
74257+ .data = &grsec_enable_link,
74258+ .maxlen = sizeof(int),
74259+ .mode = 0600,
74260+ .proc_handler = &proc_dointvec,
74261+ },
74262+#endif
74263+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74264+ {
74265+ .procname = "enforce_symlinksifowner",
74266+ .data = &grsec_enable_symlinkown,
74267+ .maxlen = sizeof(int),
74268+ .mode = 0600,
74269+ .proc_handler = &proc_dointvec,
74270+ },
74271+ {
74272+ .procname = "symlinkown_gid",
74273+ .data = &grsec_symlinkown_gid,
74274+ .maxlen = sizeof(int),
74275+ .mode = 0600,
74276+ .proc_handler = &proc_dointvec,
74277+ },
74278+#endif
74279+#ifdef CONFIG_GRKERNSEC_BRUTE
74280+ {
74281+ .procname = "deter_bruteforce",
74282+ .data = &grsec_enable_brute,
74283+ .maxlen = sizeof(int),
74284+ .mode = 0600,
74285+ .proc_handler = &proc_dointvec,
74286+ },
74287+#endif
74288+#ifdef CONFIG_GRKERNSEC_FIFO
74289+ {
74290+ .procname = "fifo_restrictions",
74291+ .data = &grsec_enable_fifo,
74292+ .maxlen = sizeof(int),
74293+ .mode = 0600,
74294+ .proc_handler = &proc_dointvec,
74295+ },
74296+#endif
74297+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74298+ {
74299+ .procname = "ptrace_readexec",
74300+ .data = &grsec_enable_ptrace_readexec,
74301+ .maxlen = sizeof(int),
74302+ .mode = 0600,
74303+ .proc_handler = &proc_dointvec,
74304+ },
74305+#endif
74306+#ifdef CONFIG_GRKERNSEC_SETXID
74307+ {
74308+ .procname = "consistent_setxid",
74309+ .data = &grsec_enable_setxid,
74310+ .maxlen = sizeof(int),
74311+ .mode = 0600,
74312+ .proc_handler = &proc_dointvec,
74313+ },
74314+#endif
74315+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74316+ {
74317+ .procname = "ip_blackhole",
74318+ .data = &grsec_enable_blackhole,
74319+ .maxlen = sizeof(int),
74320+ .mode = 0600,
74321+ .proc_handler = &proc_dointvec,
74322+ },
74323+ {
74324+ .procname = "lastack_retries",
74325+ .data = &grsec_lastack_retries,
74326+ .maxlen = sizeof(int),
74327+ .mode = 0600,
74328+ .proc_handler = &proc_dointvec,
74329+ },
74330+#endif
74331+#ifdef CONFIG_GRKERNSEC_EXECLOG
74332+ {
74333+ .procname = "exec_logging",
74334+ .data = &grsec_enable_execlog,
74335+ .maxlen = sizeof(int),
74336+ .mode = 0600,
74337+ .proc_handler = &proc_dointvec,
74338+ },
74339+#endif
74340+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74341+ {
74342+ .procname = "rwxmap_logging",
74343+ .data = &grsec_enable_log_rwxmaps,
74344+ .maxlen = sizeof(int),
74345+ .mode = 0600,
74346+ .proc_handler = &proc_dointvec,
74347+ },
74348+#endif
74349+#ifdef CONFIG_GRKERNSEC_SIGNAL
74350+ {
74351+ .procname = "signal_logging",
74352+ .data = &grsec_enable_signal,
74353+ .maxlen = sizeof(int),
74354+ .mode = 0600,
74355+ .proc_handler = &proc_dointvec,
74356+ },
74357+#endif
74358+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74359+ {
74360+ .procname = "forkfail_logging",
74361+ .data = &grsec_enable_forkfail,
74362+ .maxlen = sizeof(int),
74363+ .mode = 0600,
74364+ .proc_handler = &proc_dointvec,
74365+ },
74366+#endif
74367+#ifdef CONFIG_GRKERNSEC_TIME
74368+ {
74369+ .procname = "timechange_logging",
74370+ .data = &grsec_enable_time,
74371+ .maxlen = sizeof(int),
74372+ .mode = 0600,
74373+ .proc_handler = &proc_dointvec,
74374+ },
74375+#endif
74376+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74377+ {
74378+ .procname = "chroot_deny_shmat",
74379+ .data = &grsec_enable_chroot_shmat,
74380+ .maxlen = sizeof(int),
74381+ .mode = 0600,
74382+ .proc_handler = &proc_dointvec,
74383+ },
74384+#endif
74385+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74386+ {
74387+ .procname = "chroot_deny_unix",
74388+ .data = &grsec_enable_chroot_unix,
74389+ .maxlen = sizeof(int),
74390+ .mode = 0600,
74391+ .proc_handler = &proc_dointvec,
74392+ },
74393+#endif
74394+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74395+ {
74396+ .procname = "chroot_deny_mount",
74397+ .data = &grsec_enable_chroot_mount,
74398+ .maxlen = sizeof(int),
74399+ .mode = 0600,
74400+ .proc_handler = &proc_dointvec,
74401+ },
74402+#endif
74403+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74404+ {
74405+ .procname = "chroot_deny_fchdir",
74406+ .data = &grsec_enable_chroot_fchdir,
74407+ .maxlen = sizeof(int),
74408+ .mode = 0600,
74409+ .proc_handler = &proc_dointvec,
74410+ },
74411+#endif
74412+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74413+ {
74414+ .procname = "chroot_deny_chroot",
74415+ .data = &grsec_enable_chroot_double,
74416+ .maxlen = sizeof(int),
74417+ .mode = 0600,
74418+ .proc_handler = &proc_dointvec,
74419+ },
74420+#endif
74421+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74422+ {
74423+ .procname = "chroot_deny_pivot",
74424+ .data = &grsec_enable_chroot_pivot,
74425+ .maxlen = sizeof(int),
74426+ .mode = 0600,
74427+ .proc_handler = &proc_dointvec,
74428+ },
74429+#endif
74430+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74431+ {
74432+ .procname = "chroot_enforce_chdir",
74433+ .data = &grsec_enable_chroot_chdir,
74434+ .maxlen = sizeof(int),
74435+ .mode = 0600,
74436+ .proc_handler = &proc_dointvec,
74437+ },
74438+#endif
74439+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74440+ {
74441+ .procname = "chroot_deny_chmod",
74442+ .data = &grsec_enable_chroot_chmod,
74443+ .maxlen = sizeof(int),
74444+ .mode = 0600,
74445+ .proc_handler = &proc_dointvec,
74446+ },
74447+#endif
74448+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74449+ {
74450+ .procname = "chroot_deny_mknod",
74451+ .data = &grsec_enable_chroot_mknod,
74452+ .maxlen = sizeof(int),
74453+ .mode = 0600,
74454+ .proc_handler = &proc_dointvec,
74455+ },
74456+#endif
74457+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74458+ {
74459+ .procname = "chroot_restrict_nice",
74460+ .data = &grsec_enable_chroot_nice,
74461+ .maxlen = sizeof(int),
74462+ .mode = 0600,
74463+ .proc_handler = &proc_dointvec,
74464+ },
74465+#endif
74466+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74467+ {
74468+ .procname = "chroot_execlog",
74469+ .data = &grsec_enable_chroot_execlog,
74470+ .maxlen = sizeof(int),
74471+ .mode = 0600,
74472+ .proc_handler = &proc_dointvec,
74473+ },
74474+#endif
74475+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74476+ {
74477+ .procname = "chroot_caps",
74478+ .data = &grsec_enable_chroot_caps,
74479+ .maxlen = sizeof(int),
74480+ .mode = 0600,
74481+ .proc_handler = &proc_dointvec,
74482+ },
74483+#endif
74484+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74485+ {
74486+ .procname = "chroot_deny_sysctl",
74487+ .data = &grsec_enable_chroot_sysctl,
74488+ .maxlen = sizeof(int),
74489+ .mode = 0600,
74490+ .proc_handler = &proc_dointvec,
74491+ },
74492+#endif
74493+#ifdef CONFIG_GRKERNSEC_TPE
74494+ {
74495+ .procname = "tpe",
74496+ .data = &grsec_enable_tpe,
74497+ .maxlen = sizeof(int),
74498+ .mode = 0600,
74499+ .proc_handler = &proc_dointvec,
74500+ },
74501+ {
74502+ .procname = "tpe_gid",
74503+ .data = &grsec_tpe_gid,
74504+ .maxlen = sizeof(int),
74505+ .mode = 0600,
74506+ .proc_handler = &proc_dointvec,
74507+ },
74508+#endif
74509+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74510+ {
74511+ .procname = "tpe_invert",
74512+ .data = &grsec_enable_tpe_invert,
74513+ .maxlen = sizeof(int),
74514+ .mode = 0600,
74515+ .proc_handler = &proc_dointvec,
74516+ },
74517+#endif
74518+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74519+ {
74520+ .procname = "tpe_restrict_all",
74521+ .data = &grsec_enable_tpe_all,
74522+ .maxlen = sizeof(int),
74523+ .mode = 0600,
74524+ .proc_handler = &proc_dointvec,
74525+ },
74526+#endif
74527+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74528+ {
74529+ .procname = "socket_all",
74530+ .data = &grsec_enable_socket_all,
74531+ .maxlen = sizeof(int),
74532+ .mode = 0600,
74533+ .proc_handler = &proc_dointvec,
74534+ },
74535+ {
74536+ .procname = "socket_all_gid",
74537+ .data = &grsec_socket_all_gid,
74538+ .maxlen = sizeof(int),
74539+ .mode = 0600,
74540+ .proc_handler = &proc_dointvec,
74541+ },
74542+#endif
74543+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74544+ {
74545+ .procname = "socket_client",
74546+ .data = &grsec_enable_socket_client,
74547+ .maxlen = sizeof(int),
74548+ .mode = 0600,
74549+ .proc_handler = &proc_dointvec,
74550+ },
74551+ {
74552+ .procname = "socket_client_gid",
74553+ .data = &grsec_socket_client_gid,
74554+ .maxlen = sizeof(int),
74555+ .mode = 0600,
74556+ .proc_handler = &proc_dointvec,
74557+ },
74558+#endif
74559+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74560+ {
74561+ .procname = "socket_server",
74562+ .data = &grsec_enable_socket_server,
74563+ .maxlen = sizeof(int),
74564+ .mode = 0600,
74565+ .proc_handler = &proc_dointvec,
74566+ },
74567+ {
74568+ .procname = "socket_server_gid",
74569+ .data = &grsec_socket_server_gid,
74570+ .maxlen = sizeof(int),
74571+ .mode = 0600,
74572+ .proc_handler = &proc_dointvec,
74573+ },
74574+#endif
74575+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74576+ {
74577+ .procname = "audit_group",
74578+ .data = &grsec_enable_group,
74579+ .maxlen = sizeof(int),
74580+ .mode = 0600,
74581+ .proc_handler = &proc_dointvec,
74582+ },
74583+ {
74584+ .procname = "audit_gid",
74585+ .data = &grsec_audit_gid,
74586+ .maxlen = sizeof(int),
74587+ .mode = 0600,
74588+ .proc_handler = &proc_dointvec,
74589+ },
74590+#endif
74591+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74592+ {
74593+ .procname = "audit_chdir",
74594+ .data = &grsec_enable_chdir,
74595+ .maxlen = sizeof(int),
74596+ .mode = 0600,
74597+ .proc_handler = &proc_dointvec,
74598+ },
74599+#endif
74600+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74601+ {
74602+ .procname = "audit_mount",
74603+ .data = &grsec_enable_mount,
74604+ .maxlen = sizeof(int),
74605+ .mode = 0600,
74606+ .proc_handler = &proc_dointvec,
74607+ },
74608+#endif
74609+#ifdef CONFIG_GRKERNSEC_DMESG
74610+ {
74611+ .procname = "dmesg",
74612+ .data = &grsec_enable_dmesg,
74613+ .maxlen = sizeof(int),
74614+ .mode = 0600,
74615+ .proc_handler = &proc_dointvec,
74616+ },
74617+#endif
74618+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74619+ {
74620+ .procname = "chroot_findtask",
74621+ .data = &grsec_enable_chroot_findtask,
74622+ .maxlen = sizeof(int),
74623+ .mode = 0600,
74624+ .proc_handler = &proc_dointvec,
74625+ },
74626+#endif
74627+#ifdef CONFIG_GRKERNSEC_RESLOG
74628+ {
74629+ .procname = "resource_logging",
74630+ .data = &grsec_resource_logging,
74631+ .maxlen = sizeof(int),
74632+ .mode = 0600,
74633+ .proc_handler = &proc_dointvec,
74634+ },
74635+#endif
74636+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74637+ {
74638+ .procname = "audit_ptrace",
74639+ .data = &grsec_enable_audit_ptrace,
74640+ .maxlen = sizeof(int),
74641+ .mode = 0600,
74642+ .proc_handler = &proc_dointvec,
74643+ },
74644+#endif
74645+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74646+ {
74647+ .procname = "harden_ptrace",
74648+ .data = &grsec_enable_harden_ptrace,
74649+ .maxlen = sizeof(int),
74650+ .mode = 0600,
74651+ .proc_handler = &proc_dointvec,
74652+ },
74653+#endif
74654+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74655+ {
74656+ .procname = "harden_ipc",
74657+ .data = &grsec_enable_harden_ipc,
74658+ .maxlen = sizeof(int),
74659+ .mode = 0600,
74660+ .proc_handler = &proc_dointvec,
74661+ },
74662+#endif
74663+ {
74664+ .procname = "grsec_lock",
74665+ .data = &grsec_lock,
74666+ .maxlen = sizeof(int),
74667+ .mode = 0600,
74668+ .proc_handler = &proc_dointvec,
74669+ },
74670+#endif
74671+#ifdef CONFIG_GRKERNSEC_ROFS
74672+ {
74673+ .procname = "romount_protect",
74674+ .data = &grsec_enable_rofs,
74675+ .maxlen = sizeof(int),
74676+ .mode = 0600,
74677+ .proc_handler = &proc_dointvec_minmax,
74678+ .extra1 = &one,
74679+ .extra2 = &one,
74680+ },
74681+#endif
74682+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
74683+ {
74684+ .procname = "deny_new_usb",
74685+ .data = &grsec_deny_new_usb,
74686+ .maxlen = sizeof(int),
74687+ .mode = 0600,
74688+ .proc_handler = &proc_dointvec,
74689+ },
74690+#endif
74691+ { }
74692+};
74693+#endif
74694diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
74695new file mode 100644
74696index 0000000..0dc13c3
74697--- /dev/null
74698+++ b/grsecurity/grsec_time.c
74699@@ -0,0 +1,16 @@
74700+#include <linux/kernel.h>
74701+#include <linux/sched.h>
74702+#include <linux/grinternal.h>
74703+#include <linux/module.h>
74704+
74705+void
74706+gr_log_timechange(void)
74707+{
74708+#ifdef CONFIG_GRKERNSEC_TIME
74709+ if (grsec_enable_time)
74710+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
74711+#endif
74712+ return;
74713+}
74714+
74715+EXPORT_SYMBOL(gr_log_timechange);
74716diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
74717new file mode 100644
74718index 0000000..ee57dcf
74719--- /dev/null
74720+++ b/grsecurity/grsec_tpe.c
74721@@ -0,0 +1,73 @@
74722+#include <linux/kernel.h>
74723+#include <linux/sched.h>
74724+#include <linux/file.h>
74725+#include <linux/fs.h>
74726+#include <linux/grinternal.h>
74727+
74728+extern int gr_acl_tpe_check(void);
74729+
74730+int
74731+gr_tpe_allow(const struct file *file)
74732+{
74733+#ifdef CONFIG_GRKERNSEC
74734+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
74735+ const struct cred *cred = current_cred();
74736+ char *msg = NULL;
74737+ char *msg2 = NULL;
74738+
74739+ // never restrict root
74740+ if (gr_is_global_root(cred->uid))
74741+ return 1;
74742+
74743+ if (grsec_enable_tpe) {
74744+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74745+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
74746+ msg = "not being in trusted group";
74747+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
74748+ msg = "being in untrusted group";
74749+#else
74750+ if (in_group_p(grsec_tpe_gid))
74751+ msg = "being in untrusted group";
74752+#endif
74753+ }
74754+ if (!msg && gr_acl_tpe_check())
74755+ msg = "being in untrusted role";
74756+
74757+ // not in any affected group/role
74758+ if (!msg)
74759+ goto next_check;
74760+
74761+ if (gr_is_global_nonroot(inode->i_uid))
74762+ msg2 = "file in non-root-owned directory";
74763+ else if (inode->i_mode & S_IWOTH)
74764+ msg2 = "file in world-writable directory";
74765+ else if (inode->i_mode & S_IWGRP)
74766+ msg2 = "file in group-writable directory";
74767+
74768+ if (msg && msg2) {
74769+ char fullmsg[70] = {0};
74770+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
74771+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
74772+ return 0;
74773+ }
74774+ msg = NULL;
74775+next_check:
74776+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74777+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
74778+ return 1;
74779+
74780+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
74781+ msg = "directory not owned by user";
74782+ else if (inode->i_mode & S_IWOTH)
74783+ msg = "file in world-writable directory";
74784+ else if (inode->i_mode & S_IWGRP)
74785+ msg = "file in group-writable directory";
74786+
74787+ if (msg) {
74788+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
74789+ return 0;
74790+ }
74791+#endif
74792+#endif
74793+ return 1;
74794+}
74795diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
74796new file mode 100644
74797index 0000000..ae02d8e
74798--- /dev/null
74799+++ b/grsecurity/grsec_usb.c
74800@@ -0,0 +1,15 @@
74801+#include <linux/kernel.h>
74802+#include <linux/grinternal.h>
74803+#include <linux/module.h>
74804+
74805+int gr_handle_new_usb(void)
74806+{
74807+#ifdef CONFIG_GRKERNSEC_DENYUSB
74808+ if (grsec_deny_new_usb) {
74809+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
74810+ return 1;
74811+ }
74812+#endif
74813+ return 0;
74814+}
74815+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
74816diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
74817new file mode 100644
74818index 0000000..9f7b1ac
74819--- /dev/null
74820+++ b/grsecurity/grsum.c
74821@@ -0,0 +1,61 @@
74822+#include <linux/err.h>
74823+#include <linux/kernel.h>
74824+#include <linux/sched.h>
74825+#include <linux/mm.h>
74826+#include <linux/scatterlist.h>
74827+#include <linux/crypto.h>
74828+#include <linux/gracl.h>
74829+
74830+
74831+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
74832+#error "crypto and sha256 must be built into the kernel"
74833+#endif
74834+
74835+int
74836+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
74837+{
74838+ char *p;
74839+ struct crypto_hash *tfm;
74840+ struct hash_desc desc;
74841+ struct scatterlist sg;
74842+ unsigned char temp_sum[GR_SHA_LEN];
74843+ volatile int retval = 0;
74844+ volatile int dummy = 0;
74845+ unsigned int i;
74846+
74847+ sg_init_table(&sg, 1);
74848+
74849+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
74850+ if (IS_ERR(tfm)) {
74851+ /* should never happen, since sha256 should be built in */
74852+ return 1;
74853+ }
74854+
74855+ desc.tfm = tfm;
74856+ desc.flags = 0;
74857+
74858+ crypto_hash_init(&desc);
74859+
74860+ p = salt;
74861+ sg_set_buf(&sg, p, GR_SALT_LEN);
74862+ crypto_hash_update(&desc, &sg, sg.length);
74863+
74864+ p = entry->pw;
74865+ sg_set_buf(&sg, p, strlen(p));
74866+
74867+ crypto_hash_update(&desc, &sg, sg.length);
74868+
74869+ crypto_hash_final(&desc, temp_sum);
74870+
74871+ memset(entry->pw, 0, GR_PW_LEN);
74872+
74873+ for (i = 0; i < GR_SHA_LEN; i++)
74874+ if (sum[i] != temp_sum[i])
74875+ retval = 1;
74876+ else
74877+ dummy = 1; // waste a cycle
74878+
74879+ crypto_free_hash(tfm);
74880+
74881+ return retval;
74882+}
74883diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
74884index 77ff547..181834f 100644
74885--- a/include/asm-generic/4level-fixup.h
74886+++ b/include/asm-generic/4level-fixup.h
74887@@ -13,8 +13,10 @@
74888 #define pmd_alloc(mm, pud, address) \
74889 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
74890 NULL: pmd_offset(pud, address))
74891+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
74892
74893 #define pud_alloc(mm, pgd, address) (pgd)
74894+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
74895 #define pud_offset(pgd, start) (pgd)
74896 #define pud_none(pud) 0
74897 #define pud_bad(pud) 0
74898diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
74899index b7babf0..97f4c4f 100644
74900--- a/include/asm-generic/atomic-long.h
74901+++ b/include/asm-generic/atomic-long.h
74902@@ -22,6 +22,12 @@
74903
74904 typedef atomic64_t atomic_long_t;
74905
74906+#ifdef CONFIG_PAX_REFCOUNT
74907+typedef atomic64_unchecked_t atomic_long_unchecked_t;
74908+#else
74909+typedef atomic64_t atomic_long_unchecked_t;
74910+#endif
74911+
74912 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
74913
74914 static inline long atomic_long_read(atomic_long_t *l)
74915@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
74916 return (long)atomic64_read(v);
74917 }
74918
74919+#ifdef CONFIG_PAX_REFCOUNT
74920+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
74921+{
74922+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74923+
74924+ return (long)atomic64_read_unchecked(v);
74925+}
74926+#endif
74927+
74928 static inline void atomic_long_set(atomic_long_t *l, long i)
74929 {
74930 atomic64_t *v = (atomic64_t *)l;
74931@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
74932 atomic64_set(v, i);
74933 }
74934
74935+#ifdef CONFIG_PAX_REFCOUNT
74936+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
74937+{
74938+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74939+
74940+ atomic64_set_unchecked(v, i);
74941+}
74942+#endif
74943+
74944 static inline void atomic_long_inc(atomic_long_t *l)
74945 {
74946 atomic64_t *v = (atomic64_t *)l;
74947@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
74948 atomic64_inc(v);
74949 }
74950
74951+#ifdef CONFIG_PAX_REFCOUNT
74952+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
74953+{
74954+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74955+
74956+ atomic64_inc_unchecked(v);
74957+}
74958+#endif
74959+
74960 static inline void atomic_long_dec(atomic_long_t *l)
74961 {
74962 atomic64_t *v = (atomic64_t *)l;
74963@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
74964 atomic64_dec(v);
74965 }
74966
74967+#ifdef CONFIG_PAX_REFCOUNT
74968+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
74969+{
74970+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74971+
74972+ atomic64_dec_unchecked(v);
74973+}
74974+#endif
74975+
74976 static inline void atomic_long_add(long i, atomic_long_t *l)
74977 {
74978 atomic64_t *v = (atomic64_t *)l;
74979@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
74980 atomic64_add(i, v);
74981 }
74982
74983+#ifdef CONFIG_PAX_REFCOUNT
74984+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
74985+{
74986+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
74987+
74988+ atomic64_add_unchecked(i, v);
74989+}
74990+#endif
74991+
74992 static inline void atomic_long_sub(long i, atomic_long_t *l)
74993 {
74994 atomic64_t *v = (atomic64_t *)l;
74995@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
74996 atomic64_sub(i, v);
74997 }
74998
74999+#ifdef CONFIG_PAX_REFCOUNT
75000+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75001+{
75002+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75003+
75004+ atomic64_sub_unchecked(i, v);
75005+}
75006+#endif
75007+
75008 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75009 {
75010 atomic64_t *v = (atomic64_t *)l;
75011@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
75012 return atomic64_add_negative(i, v);
75013 }
75014
75015-static inline long atomic_long_add_return(long i, atomic_long_t *l)
75016+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
75017 {
75018 atomic64_t *v = (atomic64_t *)l;
75019
75020 return (long)atomic64_add_return(i, v);
75021 }
75022
75023+#ifdef CONFIG_PAX_REFCOUNT
75024+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75025+{
75026+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75027+
75028+ return (long)atomic64_add_return_unchecked(i, v);
75029+}
75030+#endif
75031+
75032 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75033 {
75034 atomic64_t *v = (atomic64_t *)l;
75035@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75036 return (long)atomic64_inc_return(v);
75037 }
75038
75039+#ifdef CONFIG_PAX_REFCOUNT
75040+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75041+{
75042+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75043+
75044+ return (long)atomic64_inc_return_unchecked(v);
75045+}
75046+#endif
75047+
75048 static inline long atomic_long_dec_return(atomic_long_t *l)
75049 {
75050 atomic64_t *v = (atomic64_t *)l;
75051@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75052
75053 typedef atomic_t atomic_long_t;
75054
75055+#ifdef CONFIG_PAX_REFCOUNT
75056+typedef atomic_unchecked_t atomic_long_unchecked_t;
75057+#else
75058+typedef atomic_t atomic_long_unchecked_t;
75059+#endif
75060+
75061 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
75062 static inline long atomic_long_read(atomic_long_t *l)
75063 {
75064@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75065 return (long)atomic_read(v);
75066 }
75067
75068+#ifdef CONFIG_PAX_REFCOUNT
75069+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75070+{
75071+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75072+
75073+ return (long)atomic_read_unchecked(v);
75074+}
75075+#endif
75076+
75077 static inline void atomic_long_set(atomic_long_t *l, long i)
75078 {
75079 atomic_t *v = (atomic_t *)l;
75080@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75081 atomic_set(v, i);
75082 }
75083
75084+#ifdef CONFIG_PAX_REFCOUNT
75085+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75086+{
75087+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75088+
75089+ atomic_set_unchecked(v, i);
75090+}
75091+#endif
75092+
75093 static inline void atomic_long_inc(atomic_long_t *l)
75094 {
75095 atomic_t *v = (atomic_t *)l;
75096@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75097 atomic_inc(v);
75098 }
75099
75100+#ifdef CONFIG_PAX_REFCOUNT
75101+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75102+{
75103+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75104+
75105+ atomic_inc_unchecked(v);
75106+}
75107+#endif
75108+
75109 static inline void atomic_long_dec(atomic_long_t *l)
75110 {
75111 atomic_t *v = (atomic_t *)l;
75112@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75113 atomic_dec(v);
75114 }
75115
75116+#ifdef CONFIG_PAX_REFCOUNT
75117+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75118+{
75119+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75120+
75121+ atomic_dec_unchecked(v);
75122+}
75123+#endif
75124+
75125 static inline void atomic_long_add(long i, atomic_long_t *l)
75126 {
75127 atomic_t *v = (atomic_t *)l;
75128@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75129 atomic_add(i, v);
75130 }
75131
75132+#ifdef CONFIG_PAX_REFCOUNT
75133+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75134+{
75135+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75136+
75137+ atomic_add_unchecked(i, v);
75138+}
75139+#endif
75140+
75141 static inline void atomic_long_sub(long i, atomic_long_t *l)
75142 {
75143 atomic_t *v = (atomic_t *)l;
75144@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75145 atomic_sub(i, v);
75146 }
75147
75148+#ifdef CONFIG_PAX_REFCOUNT
75149+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75150+{
75151+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75152+
75153+ atomic_sub_unchecked(i, v);
75154+}
75155+#endif
75156+
75157 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75158 {
75159 atomic_t *v = (atomic_t *)l;
75160@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
75161 return (long)atomic_add_return(i, v);
75162 }
75163
75164+#ifdef CONFIG_PAX_REFCOUNT
75165+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75166+{
75167+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75168+
75169+ return (long)atomic_add_return_unchecked(i, v);
75170+}
75171+
75172+#endif
75173+
75174 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75175 {
75176 atomic_t *v = (atomic_t *)l;
75177@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75178 return (long)atomic_inc_return(v);
75179 }
75180
75181+#ifdef CONFIG_PAX_REFCOUNT
75182+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75183+{
75184+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75185+
75186+ return (long)atomic_inc_return_unchecked(v);
75187+}
75188+#endif
75189+
75190 static inline long atomic_long_dec_return(atomic_long_t *l)
75191 {
75192 atomic_t *v = (atomic_t *)l;
75193@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75194
75195 #endif /* BITS_PER_LONG == 64 */
75196
75197+#ifdef CONFIG_PAX_REFCOUNT
75198+static inline void pax_refcount_needs_these_functions(void)
75199+{
75200+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
75201+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
75202+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
75203+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
75204+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
75205+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
75206+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
75207+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
75208+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
75209+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
75210+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
75211+#ifdef CONFIG_X86
75212+ atomic_clear_mask_unchecked(0, NULL);
75213+ atomic_set_mask_unchecked(0, NULL);
75214+#endif
75215+
75216+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
75217+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
75218+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
75219+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
75220+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
75221+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
75222+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
75223+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
75224+}
75225+#else
75226+#define atomic_read_unchecked(v) atomic_read(v)
75227+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
75228+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
75229+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
75230+#define atomic_inc_unchecked(v) atomic_inc(v)
75231+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
75232+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
75233+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
75234+#define atomic_dec_unchecked(v) atomic_dec(v)
75235+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
75236+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
75237+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
75238+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
75239+
75240+#define atomic_long_read_unchecked(v) atomic_long_read(v)
75241+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
75242+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
75243+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
75244+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
75245+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
75246+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
75247+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
75248+#endif
75249+
75250 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
75251diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
75252index 33bd2de..f31bff97 100644
75253--- a/include/asm-generic/atomic.h
75254+++ b/include/asm-generic/atomic.h
75255@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
75256 * Atomically clears the bits set in @mask from @v
75257 */
75258 #ifndef atomic_clear_mask
75259-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
75260+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
75261 {
75262 unsigned long flags;
75263
75264diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
75265index b18ce4f..2ee2843 100644
75266--- a/include/asm-generic/atomic64.h
75267+++ b/include/asm-generic/atomic64.h
75268@@ -16,6 +16,8 @@ typedef struct {
75269 long long counter;
75270 } atomic64_t;
75271
75272+typedef atomic64_t atomic64_unchecked_t;
75273+
75274 #define ATOMIC64_INIT(i) { (i) }
75275
75276 extern long long atomic64_read(const atomic64_t *v);
75277@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
75278 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
75279 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
75280
75281+#define atomic64_read_unchecked(v) atomic64_read(v)
75282+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
75283+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
75284+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
75285+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
75286+#define atomic64_inc_unchecked(v) atomic64_inc(v)
75287+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
75288+#define atomic64_dec_unchecked(v) atomic64_dec(v)
75289+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
75290+
75291 #endif /* _ASM_GENERIC_ATOMIC64_H */
75292diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
75293index a60a7cc..0fe12f2 100644
75294--- a/include/asm-generic/bitops/__fls.h
75295+++ b/include/asm-generic/bitops/__fls.h
75296@@ -9,7 +9,7 @@
75297 *
75298 * Undefined if no set bit exists, so code should check against 0 first.
75299 */
75300-static __always_inline unsigned long __fls(unsigned long word)
75301+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
75302 {
75303 int num = BITS_PER_LONG - 1;
75304
75305diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
75306index 0576d1f..dad6c71 100644
75307--- a/include/asm-generic/bitops/fls.h
75308+++ b/include/asm-generic/bitops/fls.h
75309@@ -9,7 +9,7 @@
75310 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
75311 */
75312
75313-static __always_inline int fls(int x)
75314+static __always_inline int __intentional_overflow(-1) fls(int x)
75315 {
75316 int r = 32;
75317
75318diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
75319index b097cf8..3d40e14 100644
75320--- a/include/asm-generic/bitops/fls64.h
75321+++ b/include/asm-generic/bitops/fls64.h
75322@@ -15,7 +15,7 @@
75323 * at position 64.
75324 */
75325 #if BITS_PER_LONG == 32
75326-static __always_inline int fls64(__u64 x)
75327+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75328 {
75329 __u32 h = x >> 32;
75330 if (h)
75331@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
75332 return fls(x);
75333 }
75334 #elif BITS_PER_LONG == 64
75335-static __always_inline int fls64(__u64 x)
75336+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75337 {
75338 if (x == 0)
75339 return 0;
75340diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
75341index 1bfcfe5..e04c5c9 100644
75342--- a/include/asm-generic/cache.h
75343+++ b/include/asm-generic/cache.h
75344@@ -6,7 +6,7 @@
75345 * cache lines need to provide their own cache.h.
75346 */
75347
75348-#define L1_CACHE_SHIFT 5
75349-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
75350+#define L1_CACHE_SHIFT 5UL
75351+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
75352
75353 #endif /* __ASM_GENERIC_CACHE_H */
75354diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
75355index 0d68a1e..b74a761 100644
75356--- a/include/asm-generic/emergency-restart.h
75357+++ b/include/asm-generic/emergency-restart.h
75358@@ -1,7 +1,7 @@
75359 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
75360 #define _ASM_GENERIC_EMERGENCY_RESTART_H
75361
75362-static inline void machine_emergency_restart(void)
75363+static inline __noreturn void machine_emergency_restart(void)
75364 {
75365 machine_restart(NULL);
75366 }
75367diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
75368index 90f99c7..00ce236 100644
75369--- a/include/asm-generic/kmap_types.h
75370+++ b/include/asm-generic/kmap_types.h
75371@@ -2,9 +2,9 @@
75372 #define _ASM_GENERIC_KMAP_TYPES_H
75373
75374 #ifdef __WITH_KM_FENCE
75375-# define KM_TYPE_NR 41
75376+# define KM_TYPE_NR 42
75377 #else
75378-# define KM_TYPE_NR 20
75379+# define KM_TYPE_NR 21
75380 #endif
75381
75382 #endif
75383diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
75384index 9ceb03b..62b0b8f 100644
75385--- a/include/asm-generic/local.h
75386+++ b/include/asm-generic/local.h
75387@@ -23,24 +23,37 @@ typedef struct
75388 atomic_long_t a;
75389 } local_t;
75390
75391+typedef struct {
75392+ atomic_long_unchecked_t a;
75393+} local_unchecked_t;
75394+
75395 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
75396
75397 #define local_read(l) atomic_long_read(&(l)->a)
75398+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
75399 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
75400+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
75401 #define local_inc(l) atomic_long_inc(&(l)->a)
75402+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
75403 #define local_dec(l) atomic_long_dec(&(l)->a)
75404+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
75405 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
75406+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
75407 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
75408+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
75409
75410 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
75411 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
75412 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
75413 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
75414 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
75415+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
75416 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
75417 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
75418+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
75419
75420 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75421+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75422 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
75423 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
75424 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
75425diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
75426index 725612b..9cc513a 100644
75427--- a/include/asm-generic/pgtable-nopmd.h
75428+++ b/include/asm-generic/pgtable-nopmd.h
75429@@ -1,14 +1,19 @@
75430 #ifndef _PGTABLE_NOPMD_H
75431 #define _PGTABLE_NOPMD_H
75432
75433-#ifndef __ASSEMBLY__
75434-
75435 #include <asm-generic/pgtable-nopud.h>
75436
75437-struct mm_struct;
75438-
75439 #define __PAGETABLE_PMD_FOLDED
75440
75441+#define PMD_SHIFT PUD_SHIFT
75442+#define PTRS_PER_PMD 1
75443+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
75444+#define PMD_MASK (~(PMD_SIZE-1))
75445+
75446+#ifndef __ASSEMBLY__
75447+
75448+struct mm_struct;
75449+
75450 /*
75451 * Having the pmd type consist of a pud gets the size right, and allows
75452 * us to conceptually access the pud entry that this pmd is folded into
75453@@ -16,11 +21,6 @@ struct mm_struct;
75454 */
75455 typedef struct { pud_t pud; } pmd_t;
75456
75457-#define PMD_SHIFT PUD_SHIFT
75458-#define PTRS_PER_PMD 1
75459-#define PMD_SIZE (1UL << PMD_SHIFT)
75460-#define PMD_MASK (~(PMD_SIZE-1))
75461-
75462 /*
75463 * The "pud_xxx()" functions here are trivial for a folded two-level
75464 * setup: the pmd is never bad, and a pmd always exists (as it's folded
75465diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
75466index 810431d..0ec4804f 100644
75467--- a/include/asm-generic/pgtable-nopud.h
75468+++ b/include/asm-generic/pgtable-nopud.h
75469@@ -1,10 +1,15 @@
75470 #ifndef _PGTABLE_NOPUD_H
75471 #define _PGTABLE_NOPUD_H
75472
75473-#ifndef __ASSEMBLY__
75474-
75475 #define __PAGETABLE_PUD_FOLDED
75476
75477+#define PUD_SHIFT PGDIR_SHIFT
75478+#define PTRS_PER_PUD 1
75479+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
75480+#define PUD_MASK (~(PUD_SIZE-1))
75481+
75482+#ifndef __ASSEMBLY__
75483+
75484 /*
75485 * Having the pud type consist of a pgd gets the size right, and allows
75486 * us to conceptually access the pgd entry that this pud is folded into
75487@@ -12,11 +17,6 @@
75488 */
75489 typedef struct { pgd_t pgd; } pud_t;
75490
75491-#define PUD_SHIFT PGDIR_SHIFT
75492-#define PTRS_PER_PUD 1
75493-#define PUD_SIZE (1UL << PUD_SHIFT)
75494-#define PUD_MASK (~(PUD_SIZE-1))
75495-
75496 /*
75497 * The "pgd_xxx()" functions here are trivial for a folded two-level
75498 * setup: the pud is never bad, and a pud always exists (as it's folded
75499@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
75500 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
75501
75502 #define pgd_populate(mm, pgd, pud) do { } while (0)
75503+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
75504 /*
75505 * (puds are folded into pgds so this doesn't get actually called,
75506 * but the define is needed for a generic inline function.)
75507diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
75508index db09234..86683e3 100644
75509--- a/include/asm-generic/pgtable.h
75510+++ b/include/asm-generic/pgtable.h
75511@@ -736,6 +736,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
75512 }
75513 #endif /* CONFIG_NUMA_BALANCING */
75514
75515+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
75516+#ifdef CONFIG_PAX_KERNEXEC
75517+#error KERNEXEC requires pax_open_kernel
75518+#else
75519+static inline unsigned long pax_open_kernel(void) { return 0; }
75520+#endif
75521+#endif
75522+
75523+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
75524+#ifdef CONFIG_PAX_KERNEXEC
75525+#error KERNEXEC requires pax_close_kernel
75526+#else
75527+static inline unsigned long pax_close_kernel(void) { return 0; }
75528+#endif
75529+#endif
75530+
75531 #endif /* CONFIG_MMU */
75532
75533 #endif /* !__ASSEMBLY__ */
75534diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
75535index dc1269c..48a4f51 100644
75536--- a/include/asm-generic/uaccess.h
75537+++ b/include/asm-generic/uaccess.h
75538@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
75539 return __clear_user(to, n);
75540 }
75541
75542+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
75543+#ifdef CONFIG_PAX_MEMORY_UDEREF
75544+#error UDEREF requires pax_open_userland
75545+#else
75546+static inline unsigned long pax_open_userland(void) { return 0; }
75547+#endif
75548+#endif
75549+
75550+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
75551+#ifdef CONFIG_PAX_MEMORY_UDEREF
75552+#error UDEREF requires pax_close_userland
75553+#else
75554+static inline unsigned long pax_close_userland(void) { return 0; }
75555+#endif
75556+#endif
75557+
75558 #endif /* __ASM_GENERIC_UACCESS_H */
75559diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
75560index bc2121f..2f41f9a 100644
75561--- a/include/asm-generic/vmlinux.lds.h
75562+++ b/include/asm-generic/vmlinux.lds.h
75563@@ -232,6 +232,7 @@
75564 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
75565 VMLINUX_SYMBOL(__start_rodata) = .; \
75566 *(.rodata) *(.rodata.*) \
75567+ *(.data..read_only) \
75568 *(__vermagic) /* Kernel version magic */ \
75569 . = ALIGN(8); \
75570 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
75571@@ -716,17 +717,18 @@
75572 * section in the linker script will go there too. @phdr should have
75573 * a leading colon.
75574 *
75575- * Note that this macros defines __per_cpu_load as an absolute symbol.
75576+ * Note that this macros defines per_cpu_load as an absolute symbol.
75577 * If there is no need to put the percpu section at a predetermined
75578 * address, use PERCPU_SECTION.
75579 */
75580 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
75581- VMLINUX_SYMBOL(__per_cpu_load) = .; \
75582- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
75583+ per_cpu_load = .; \
75584+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
75585 - LOAD_OFFSET) { \
75586+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
75587 PERCPU_INPUT(cacheline) \
75588 } phdr \
75589- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
75590+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
75591
75592 /**
75593 * PERCPU_SECTION - define output section for percpu area, simple version
75594diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
75595index e73c19e..5b89e00 100644
75596--- a/include/crypto/algapi.h
75597+++ b/include/crypto/algapi.h
75598@@ -34,7 +34,7 @@ struct crypto_type {
75599 unsigned int maskclear;
75600 unsigned int maskset;
75601 unsigned int tfmsize;
75602-};
75603+} __do_const;
75604
75605 struct crypto_instance {
75606 struct crypto_alg alg;
75607diff --git a/include/drm/drmP.h b/include/drm/drmP.h
75608index 1d4a920..53a3229 100644
75609--- a/include/drm/drmP.h
75610+++ b/include/drm/drmP.h
75611@@ -66,6 +66,7 @@
75612 #include <linux/workqueue.h>
75613 #include <linux/poll.h>
75614 #include <asm/pgalloc.h>
75615+#include <asm/local.h>
75616 #include <drm/drm.h>
75617 #include <drm/drm_sarea.h>
75618 #include <drm/drm_vma_manager.h>
75619@@ -278,10 +279,12 @@ do { \
75620 * \param cmd command.
75621 * \param arg argument.
75622 */
75623-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
75624+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
75625+ struct drm_file *file_priv);
75626+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
75627 struct drm_file *file_priv);
75628
75629-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75630+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
75631 unsigned long arg);
75632
75633 #define DRM_IOCTL_NR(n) _IOC_NR(n)
75634@@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75635 struct drm_ioctl_desc {
75636 unsigned int cmd;
75637 int flags;
75638- drm_ioctl_t *func;
75639+ drm_ioctl_t func;
75640 unsigned int cmd_drv;
75641 const char *name;
75642-};
75643+} __do_const;
75644
75645 /**
75646 * Creates a driver or general drm_ioctl_desc array entry for the given
75647@@ -1013,7 +1016,7 @@ struct drm_info_list {
75648 int (*show)(struct seq_file*, void*); /** show callback */
75649 u32 driver_features; /**< Required driver features for this entry */
75650 void *data;
75651-};
75652+} __do_const;
75653
75654 /**
75655 * debugfs node structure. This structure represents a debugfs file.
75656@@ -1097,7 +1100,7 @@ struct drm_device {
75657
75658 /** \name Usage Counters */
75659 /*@{ */
75660- int open_count; /**< Outstanding files open */
75661+ local_t open_count; /**< Outstanding files open */
75662 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
75663 atomic_t vma_count; /**< Outstanding vma areas open */
75664 int buf_use; /**< Buffers in use -- cannot alloc */
75665diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
75666index ef6ad3a..be34b16 100644
75667--- a/include/drm/drm_crtc_helper.h
75668+++ b/include/drm/drm_crtc_helper.h
75669@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
75670 struct drm_connector *connector);
75671 /* disable encoder when not in use - more explicit than dpms off */
75672 void (*disable)(struct drm_encoder *encoder);
75673-};
75674+} __no_const;
75675
75676 /**
75677 * drm_connector_helper_funcs - helper operations for connectors
75678diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
75679index 940ece4..8cb727f 100644
75680--- a/include/drm/i915_pciids.h
75681+++ b/include/drm/i915_pciids.h
75682@@ -37,7 +37,7 @@
75683 */
75684 #define INTEL_VGA_DEVICE(id, info) { \
75685 0x8086, id, \
75686- ~0, ~0, \
75687+ PCI_ANY_ID, PCI_ANY_ID, \
75688 0x030000, 0xff0000, \
75689 (unsigned long) info }
75690
75691diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
75692index 72dcbe8..8db58d7 100644
75693--- a/include/drm/ttm/ttm_memory.h
75694+++ b/include/drm/ttm/ttm_memory.h
75695@@ -48,7 +48,7 @@
75696
75697 struct ttm_mem_shrink {
75698 int (*do_shrink) (struct ttm_mem_shrink *);
75699-};
75700+} __no_const;
75701
75702 /**
75703 * struct ttm_mem_global - Global memory accounting structure.
75704diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
75705index 4b840e8..155d235 100644
75706--- a/include/keys/asymmetric-subtype.h
75707+++ b/include/keys/asymmetric-subtype.h
75708@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
75709 /* Verify the signature on a key of this subtype (optional) */
75710 int (*verify_signature)(const struct key *key,
75711 const struct public_key_signature *sig);
75712-};
75713+} __do_const;
75714
75715 /**
75716 * asymmetric_key_subtype - Get the subtype from an asymmetric key
75717diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
75718index c1da539..1dcec55 100644
75719--- a/include/linux/atmdev.h
75720+++ b/include/linux/atmdev.h
75721@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
75722 #endif
75723
75724 struct k_atm_aal_stats {
75725-#define __HANDLE_ITEM(i) atomic_t i
75726+#define __HANDLE_ITEM(i) atomic_unchecked_t i
75727 __AAL_STAT_ITEMS
75728 #undef __HANDLE_ITEM
75729 };
75730@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
75731 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
75732 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
75733 struct module *owner;
75734-};
75735+} __do_const ;
75736
75737 struct atmphy_ops {
75738 int (*start)(struct atm_dev *dev);
75739diff --git a/include/linux/audit.h b/include/linux/audit.h
75740index a406419..c2bb164 100644
75741--- a/include/linux/audit.h
75742+++ b/include/linux/audit.h
75743@@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
75744 extern unsigned int audit_serial(void);
75745 extern int auditsc_get_stamp(struct audit_context *ctx,
75746 struct timespec *t, unsigned int *serial);
75747-extern int audit_set_loginuid(kuid_t loginuid);
75748+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
75749
75750 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
75751 {
75752diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
75753index fd8bf32..2cccd5a 100644
75754--- a/include/linux/binfmts.h
75755+++ b/include/linux/binfmts.h
75756@@ -74,8 +74,10 @@ struct linux_binfmt {
75757 int (*load_binary)(struct linux_binprm *);
75758 int (*load_shlib)(struct file *);
75759 int (*core_dump)(struct coredump_params *cprm);
75760+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
75761+ void (*handle_mmap)(struct file *);
75762 unsigned long min_coredump; /* minimal dump size */
75763-};
75764+} __do_const;
75765
75766 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
75767
75768diff --git a/include/linux/bitops.h b/include/linux/bitops.h
75769index abc9ca7..e54ee27 100644
75770--- a/include/linux/bitops.h
75771+++ b/include/linux/bitops.h
75772@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
75773 * @word: value to rotate
75774 * @shift: bits to roll
75775 */
75776-static inline __u32 rol32(__u32 word, unsigned int shift)
75777+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
75778 {
75779 return (word << shift) | (word >> (32 - shift));
75780 }
75781@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
75782 * @word: value to rotate
75783 * @shift: bits to roll
75784 */
75785-static inline __u32 ror32(__u32 word, unsigned int shift)
75786+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
75787 {
75788 return (word >> shift) | (word << (32 - shift));
75789 }
75790@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
75791 return (__s32)(value << shift) >> shift;
75792 }
75793
75794-static inline unsigned fls_long(unsigned long l)
75795+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
75796 {
75797 if (sizeof(l) == 4)
75798 return fls(l);
75799diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
75800index 1b135d4..59fc876 100644
75801--- a/include/linux/blkdev.h
75802+++ b/include/linux/blkdev.h
75803@@ -1578,7 +1578,7 @@ struct block_device_operations {
75804 /* this callback is with swap_lock and sometimes page table lock held */
75805 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
75806 struct module *owner;
75807-};
75808+} __do_const;
75809
75810 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
75811 unsigned long);
75812diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
75813index afc1343..9735539 100644
75814--- a/include/linux/blktrace_api.h
75815+++ b/include/linux/blktrace_api.h
75816@@ -25,7 +25,7 @@ struct blk_trace {
75817 struct dentry *dropped_file;
75818 struct dentry *msg_file;
75819 struct list_head running_list;
75820- atomic_t dropped;
75821+ atomic_unchecked_t dropped;
75822 };
75823
75824 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
75825diff --git a/include/linux/cache.h b/include/linux/cache.h
75826index 4c57065..40346da 100644
75827--- a/include/linux/cache.h
75828+++ b/include/linux/cache.h
75829@@ -16,6 +16,14 @@
75830 #define __read_mostly
75831 #endif
75832
75833+#ifndef __read_only
75834+#ifdef CONFIG_PAX_KERNEXEC
75835+#error KERNEXEC requires __read_only
75836+#else
75837+#define __read_only __read_mostly
75838+#endif
75839+#endif
75840+
75841 #ifndef ____cacheline_aligned
75842 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
75843 #endif
75844diff --git a/include/linux/capability.h b/include/linux/capability.h
75845index a6ee1f9..e1ca49d 100644
75846--- a/include/linux/capability.h
75847+++ b/include/linux/capability.h
75848@@ -212,8 +212,13 @@ extern bool capable(int cap);
75849 extern bool ns_capable(struct user_namespace *ns, int cap);
75850 extern bool inode_capable(const struct inode *inode, int cap);
75851 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
75852+extern bool capable_nolog(int cap);
75853+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
75854+extern bool inode_capable_nolog(const struct inode *inode, int cap);
75855
75856 /* audit system wants to get cap info from files as well */
75857 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
75858
75859+extern int is_privileged_binary(const struct dentry *dentry);
75860+
75861 #endif /* !_LINUX_CAPABILITY_H */
75862diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
75863index 8609d57..86e4d79 100644
75864--- a/include/linux/cdrom.h
75865+++ b/include/linux/cdrom.h
75866@@ -87,7 +87,6 @@ struct cdrom_device_ops {
75867
75868 /* driver specifications */
75869 const int capability; /* capability flags */
75870- int n_minors; /* number of active minor devices */
75871 /* handle uniform packets for scsi type devices (scsi,atapi) */
75872 int (*generic_packet) (struct cdrom_device_info *,
75873 struct packet_command *);
75874diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
75875index 4ce9056..86caac6 100644
75876--- a/include/linux/cleancache.h
75877+++ b/include/linux/cleancache.h
75878@@ -31,7 +31,7 @@ struct cleancache_ops {
75879 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
75880 void (*invalidate_inode)(int, struct cleancache_filekey);
75881 void (*invalidate_fs)(int);
75882-};
75883+} __no_const;
75884
75885 extern struct cleancache_ops *
75886 cleancache_register_ops(struct cleancache_ops *ops);
75887diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
75888index 7e59253..d6e4cae 100644
75889--- a/include/linux/clk-provider.h
75890+++ b/include/linux/clk-provider.h
75891@@ -141,6 +141,7 @@ struct clk_ops {
75892 unsigned long);
75893 void (*init)(struct clk_hw *hw);
75894 };
75895+typedef struct clk_ops __no_const clk_ops_no_const;
75896
75897 /**
75898 * struct clk_init_data - holds init data that's common to all clocks and is
75899diff --git a/include/linux/compat.h b/include/linux/compat.h
75900index eb8a49d..6b66ed9 100644
75901--- a/include/linux/compat.h
75902+++ b/include/linux/compat.h
75903@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
75904 compat_size_t __user *len_ptr);
75905
75906 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
75907-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
75908+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
75909 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
75910 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
75911 compat_ssize_t msgsz, int msgflg);
75912@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
75913 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
75914 compat_ulong_t addr, compat_ulong_t data);
75915 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
75916- compat_long_t addr, compat_long_t data);
75917+ compat_ulong_t addr, compat_ulong_t data);
75918
75919 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
75920 /*
75921diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
75922index ded4299..ddcbe31 100644
75923--- a/include/linux/compiler-gcc4.h
75924+++ b/include/linux/compiler-gcc4.h
75925@@ -39,9 +39,34 @@
75926 # define __compiletime_warning(message) __attribute__((warning(message)))
75927 # define __compiletime_error(message) __attribute__((error(message)))
75928 #endif /* __CHECKER__ */
75929+
75930+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
75931+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
75932+#define __bos0(ptr) __bos((ptr), 0)
75933+#define __bos1(ptr) __bos((ptr), 1)
75934 #endif /* GCC_VERSION >= 40300 */
75935
75936 #if GCC_VERSION >= 40500
75937+
75938+#ifdef RANDSTRUCT_PLUGIN
75939+#define __randomize_layout __attribute__((randomize_layout))
75940+#define __no_randomize_layout __attribute__((no_randomize_layout))
75941+#endif
75942+
75943+#ifdef CONSTIFY_PLUGIN
75944+#define __no_const __attribute__((no_const))
75945+#define __do_const __attribute__((do_const))
75946+#endif
75947+
75948+#ifdef SIZE_OVERFLOW_PLUGIN
75949+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
75950+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
75951+#endif
75952+
75953+#ifdef LATENT_ENTROPY_PLUGIN
75954+#define __latent_entropy __attribute__((latent_entropy))
75955+#endif
75956+
75957 /*
75958 * Mark a position in code as unreachable. This can be used to
75959 * suppress control flow warnings after asm blocks that transfer
75960diff --git a/include/linux/compiler.h b/include/linux/compiler.h
75961index 92669cd..cc564c0 100644
75962--- a/include/linux/compiler.h
75963+++ b/include/linux/compiler.h
75964@@ -5,11 +5,14 @@
75965
75966 #ifdef __CHECKER__
75967 # define __user __attribute__((noderef, address_space(1)))
75968+# define __force_user __force __user
75969 # define __kernel __attribute__((address_space(0)))
75970+# define __force_kernel __force __kernel
75971 # define __safe __attribute__((safe))
75972 # define __force __attribute__((force))
75973 # define __nocast __attribute__((nocast))
75974 # define __iomem __attribute__((noderef, address_space(2)))
75975+# define __force_iomem __force __iomem
75976 # define __must_hold(x) __attribute__((context(x,1,1)))
75977 # define __acquires(x) __attribute__((context(x,0,1)))
75978 # define __releases(x) __attribute__((context(x,1,0)))
75979@@ -17,20 +20,37 @@
75980 # define __release(x) __context__(x,-1)
75981 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
75982 # define __percpu __attribute__((noderef, address_space(3)))
75983+# define __force_percpu __force __percpu
75984 #ifdef CONFIG_SPARSE_RCU_POINTER
75985 # define __rcu __attribute__((noderef, address_space(4)))
75986+# define __force_rcu __force __rcu
75987 #else
75988 # define __rcu
75989+# define __force_rcu
75990 #endif
75991 extern void __chk_user_ptr(const volatile void __user *);
75992 extern void __chk_io_ptr(const volatile void __iomem *);
75993 #else
75994-# define __user
75995-# define __kernel
75996+# ifdef CHECKER_PLUGIN
75997+//# define __user
75998+//# define __force_user
75999+//# define __kernel
76000+//# define __force_kernel
76001+# else
76002+# ifdef STRUCTLEAK_PLUGIN
76003+# define __user __attribute__((user))
76004+# else
76005+# define __user
76006+# endif
76007+# define __force_user
76008+# define __kernel
76009+# define __force_kernel
76010+# endif
76011 # define __safe
76012 # define __force
76013 # define __nocast
76014 # define __iomem
76015+# define __force_iomem
76016 # define __chk_user_ptr(x) (void)0
76017 # define __chk_io_ptr(x) (void)0
76018 # define __builtin_warning(x, y...) (1)
76019@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
76020 # define __release(x) (void)0
76021 # define __cond_lock(x,c) (c)
76022 # define __percpu
76023+# define __force_percpu
76024 # define __rcu
76025+# define __force_rcu
76026 #endif
76027
76028 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
76029@@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76030 # define __attribute_const__ /* unimplemented */
76031 #endif
76032
76033+#ifndef __randomize_layout
76034+# define __randomize_layout
76035+#endif
76036+
76037+#ifndef __no_randomize_layout
76038+# define __no_randomize_layout
76039+#endif
76040+
76041+#ifndef __no_const
76042+# define __no_const
76043+#endif
76044+
76045+#ifndef __do_const
76046+# define __do_const
76047+#endif
76048+
76049+#ifndef __size_overflow
76050+# define __size_overflow(...)
76051+#endif
76052+
76053+#ifndef __intentional_overflow
76054+# define __intentional_overflow(...)
76055+#endif
76056+
76057+#ifndef __latent_entropy
76058+# define __latent_entropy
76059+#endif
76060+
76061 /*
76062 * Tell gcc if a function is cold. The compiler will assume any path
76063 * directly leading to the call is unlikely.
76064@@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76065 #define __cold
76066 #endif
76067
76068+#ifndef __alloc_size
76069+#define __alloc_size(...)
76070+#endif
76071+
76072+#ifndef __bos
76073+#define __bos(ptr, arg)
76074+#endif
76075+
76076+#ifndef __bos0
76077+#define __bos0(ptr)
76078+#endif
76079+
76080+#ifndef __bos1
76081+#define __bos1(ptr)
76082+#endif
76083+
76084 /* Simple shorthand for a section definition */
76085 #ifndef __section
76086 # define __section(S) __attribute__ ((__section__(#S)))
76087@@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76088 * use is to mediate communication between process-level code and irq/NMI
76089 * handlers, all running on the same CPU.
76090 */
76091-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
76092+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
76093+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
76094
76095 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
76096 #ifdef CONFIG_KPROBES
76097diff --git a/include/linux/completion.h b/include/linux/completion.h
76098index 5d5aaae..0ea9b84 100644
76099--- a/include/linux/completion.h
76100+++ b/include/linux/completion.h
76101@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
76102
76103 extern void wait_for_completion(struct completion *);
76104 extern void wait_for_completion_io(struct completion *);
76105-extern int wait_for_completion_interruptible(struct completion *x);
76106-extern int wait_for_completion_killable(struct completion *x);
76107+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
76108+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
76109 extern unsigned long wait_for_completion_timeout(struct completion *x,
76110- unsigned long timeout);
76111+ unsigned long timeout) __intentional_overflow(-1);
76112 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
76113- unsigned long timeout);
76114+ unsigned long timeout) __intentional_overflow(-1);
76115 extern long wait_for_completion_interruptible_timeout(
76116- struct completion *x, unsigned long timeout);
76117+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76118 extern long wait_for_completion_killable_timeout(
76119- struct completion *x, unsigned long timeout);
76120+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76121 extern bool try_wait_for_completion(struct completion *x);
76122 extern bool completion_done(struct completion *x);
76123
76124diff --git a/include/linux/configfs.h b/include/linux/configfs.h
76125index 34025df..d94bbbc 100644
76126--- a/include/linux/configfs.h
76127+++ b/include/linux/configfs.h
76128@@ -125,7 +125,7 @@ struct configfs_attribute {
76129 const char *ca_name;
76130 struct module *ca_owner;
76131 umode_t ca_mode;
76132-};
76133+} __do_const;
76134
76135 /*
76136 * Users often need to create attribute structures for their configurable
76137diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
76138index dc196bb..c55a50f 100644
76139--- a/include/linux/cpufreq.h
76140+++ b/include/linux/cpufreq.h
76141@@ -189,6 +189,7 @@ struct global_attr {
76142 ssize_t (*store)(struct kobject *a, struct attribute *b,
76143 const char *c, size_t count);
76144 };
76145+typedef struct global_attr __no_const global_attr_no_const;
76146
76147 #define define_one_global_ro(_name) \
76148 static struct global_attr _name = \
76149@@ -225,7 +226,7 @@ struct cpufreq_driver {
76150 int (*suspend) (struct cpufreq_policy *policy);
76151 int (*resume) (struct cpufreq_policy *policy);
76152 struct freq_attr **attr;
76153-};
76154+} __do_const;
76155
76156 /* flags */
76157 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
76158diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
76159index 50fcbb0..9d2dbd9 100644
76160--- a/include/linux/cpuidle.h
76161+++ b/include/linux/cpuidle.h
76162@@ -50,7 +50,8 @@ struct cpuidle_state {
76163 int index);
76164
76165 int (*enter_dead) (struct cpuidle_device *dev, int index);
76166-};
76167+} __do_const;
76168+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
76169
76170 /* Idle State Flags */
76171 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
76172@@ -192,7 +193,7 @@ struct cpuidle_governor {
76173 void (*reflect) (struct cpuidle_device *dev, int index);
76174
76175 struct module *owner;
76176-};
76177+} __do_const;
76178
76179 #ifdef CONFIG_CPU_IDLE
76180 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
76181diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
76182index d08e4d2..95fad61 100644
76183--- a/include/linux/cpumask.h
76184+++ b/include/linux/cpumask.h
76185@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76186 }
76187
76188 /* Valid inputs for n are -1 and 0. */
76189-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76190+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76191 {
76192 return n+1;
76193 }
76194
76195-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76196+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76197 {
76198 return n+1;
76199 }
76200
76201-static inline unsigned int cpumask_next_and(int n,
76202+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
76203 const struct cpumask *srcp,
76204 const struct cpumask *andp)
76205 {
76206@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76207 *
76208 * Returns >= nr_cpu_ids if no further cpus set.
76209 */
76210-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76211+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76212 {
76213 /* -1 is a legal arg here. */
76214 if (n != -1)
76215@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76216 *
76217 * Returns >= nr_cpu_ids if no further cpus unset.
76218 */
76219-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76220+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76221 {
76222 /* -1 is a legal arg here. */
76223 if (n != -1)
76224@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76225 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
76226 }
76227
76228-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
76229+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
76230 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
76231
76232 /**
76233diff --git a/include/linux/cred.h b/include/linux/cred.h
76234index 04421e8..117e17a 100644
76235--- a/include/linux/cred.h
76236+++ b/include/linux/cred.h
76237@@ -35,7 +35,7 @@ struct group_info {
76238 int nblocks;
76239 kgid_t small_block[NGROUPS_SMALL];
76240 kgid_t *blocks[0];
76241-};
76242+} __randomize_layout;
76243
76244 /**
76245 * get_group_info - Get a reference to a group info structure
76246@@ -136,7 +136,7 @@ struct cred {
76247 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
76248 struct group_info *group_info; /* supplementary groups for euid/fsgid */
76249 struct rcu_head rcu; /* RCU deletion hook */
76250-};
76251+} __randomize_layout;
76252
76253 extern void __put_cred(struct cred *);
76254 extern void exit_creds(struct task_struct *);
76255@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
76256 static inline void validate_process_creds(void)
76257 {
76258 }
76259+static inline void validate_task_creds(struct task_struct *task)
76260+{
76261+}
76262 #endif
76263
76264 /**
76265diff --git a/include/linux/crypto.h b/include/linux/crypto.h
76266index b92eadf..b4ecdc1 100644
76267--- a/include/linux/crypto.h
76268+++ b/include/linux/crypto.h
76269@@ -373,7 +373,7 @@ struct cipher_tfm {
76270 const u8 *key, unsigned int keylen);
76271 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76272 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76273-};
76274+} __no_const;
76275
76276 struct hash_tfm {
76277 int (*init)(struct hash_desc *desc);
76278@@ -394,13 +394,13 @@ struct compress_tfm {
76279 int (*cot_decompress)(struct crypto_tfm *tfm,
76280 const u8 *src, unsigned int slen,
76281 u8 *dst, unsigned int *dlen);
76282-};
76283+} __no_const;
76284
76285 struct rng_tfm {
76286 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
76287 unsigned int dlen);
76288 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
76289-};
76290+} __no_const;
76291
76292 #define crt_ablkcipher crt_u.ablkcipher
76293 #define crt_aead crt_u.aead
76294diff --git a/include/linux/ctype.h b/include/linux/ctype.h
76295index 653589e..4ef254a 100644
76296--- a/include/linux/ctype.h
76297+++ b/include/linux/ctype.h
76298@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
76299 * Fast implementation of tolower() for internal usage. Do not use in your
76300 * code.
76301 */
76302-static inline char _tolower(const char c)
76303+static inline unsigned char _tolower(const unsigned char c)
76304 {
76305 return c | 0x20;
76306 }
76307diff --git a/include/linux/dcache.h b/include/linux/dcache.h
76308index bf72e9a..4ca7927 100644
76309--- a/include/linux/dcache.h
76310+++ b/include/linux/dcache.h
76311@@ -133,7 +133,7 @@ struct dentry {
76312 } d_u;
76313 struct list_head d_subdirs; /* our children */
76314 struct hlist_node d_alias; /* inode alias list */
76315-};
76316+} __randomize_layout;
76317
76318 /*
76319 * dentry->d_lock spinlock nesting subclasses:
76320diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
76321index 7925bf0..d5143d2 100644
76322--- a/include/linux/decompress/mm.h
76323+++ b/include/linux/decompress/mm.h
76324@@ -77,7 +77,7 @@ static void free(void *where)
76325 * warnings when not needed (indeed large_malloc / large_free are not
76326 * needed by inflate */
76327
76328-#define malloc(a) kmalloc(a, GFP_KERNEL)
76329+#define malloc(a) kmalloc((a), GFP_KERNEL)
76330 #define free(a) kfree(a)
76331
76332 #define large_malloc(a) vmalloc(a)
76333diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
76334index d48dc00..211ee54 100644
76335--- a/include/linux/devfreq.h
76336+++ b/include/linux/devfreq.h
76337@@ -114,7 +114,7 @@ struct devfreq_governor {
76338 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
76339 int (*event_handler)(struct devfreq *devfreq,
76340 unsigned int event, void *data);
76341-};
76342+} __do_const;
76343
76344 /**
76345 * struct devfreq - Device devfreq structure
76346diff --git a/include/linux/device.h b/include/linux/device.h
76347index 952b010..d5b7691 100644
76348--- a/include/linux/device.h
76349+++ b/include/linux/device.h
76350@@ -310,7 +310,7 @@ struct subsys_interface {
76351 struct list_head node;
76352 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
76353 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
76354-};
76355+} __do_const;
76356
76357 int subsys_interface_register(struct subsys_interface *sif);
76358 void subsys_interface_unregister(struct subsys_interface *sif);
76359@@ -506,7 +506,7 @@ struct device_type {
76360 void (*release)(struct device *dev);
76361
76362 const struct dev_pm_ops *pm;
76363-};
76364+} __do_const;
76365
76366 /* interface for exporting device attributes */
76367 struct device_attribute {
76368@@ -516,11 +516,12 @@ struct device_attribute {
76369 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
76370 const char *buf, size_t count);
76371 };
76372+typedef struct device_attribute __no_const device_attribute_no_const;
76373
76374 struct dev_ext_attribute {
76375 struct device_attribute attr;
76376 void *var;
76377-};
76378+} __do_const;
76379
76380 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
76381 char *buf);
76382diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
76383index fd4aee2..1f28db9 100644
76384--- a/include/linux/dma-mapping.h
76385+++ b/include/linux/dma-mapping.h
76386@@ -54,7 +54,7 @@ struct dma_map_ops {
76387 u64 (*get_required_mask)(struct device *dev);
76388 #endif
76389 int is_phys;
76390-};
76391+} __do_const;
76392
76393 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
76394
76395diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
76396index 41cf0c3..f3b771c 100644
76397--- a/include/linux/dmaengine.h
76398+++ b/include/linux/dmaengine.h
76399@@ -1114,9 +1114,9 @@ struct dma_pinned_list {
76400 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
76401 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
76402
76403-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76404+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76405 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
76406-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76407+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76408 struct dma_pinned_list *pinned_list, struct page *page,
76409 unsigned int offset, size_t len);
76410
76411diff --git a/include/linux/efi.h b/include/linux/efi.h
76412index 11ce678..7b8c69c 100644
76413--- a/include/linux/efi.h
76414+++ b/include/linux/efi.h
76415@@ -764,6 +764,7 @@ struct efivar_operations {
76416 efi_set_variable_t *set_variable;
76417 efi_query_variable_store_t *query_variable_store;
76418 };
76419+typedef struct efivar_operations __no_const efivar_operations_no_const;
76420
76421 struct efivars {
76422 /*
76423diff --git a/include/linux/elf.h b/include/linux/elf.h
76424index 67a5fa7..b817372 100644
76425--- a/include/linux/elf.h
76426+++ b/include/linux/elf.h
76427@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
76428 #define elf_note elf32_note
76429 #define elf_addr_t Elf32_Off
76430 #define Elf_Half Elf32_Half
76431+#define elf_dyn Elf32_Dyn
76432
76433 #else
76434
76435@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
76436 #define elf_note elf64_note
76437 #define elf_addr_t Elf64_Off
76438 #define Elf_Half Elf64_Half
76439+#define elf_dyn Elf64_Dyn
76440
76441 #endif
76442
76443diff --git a/include/linux/err.h b/include/linux/err.h
76444index 15f92e0..e825a8e 100644
76445--- a/include/linux/err.h
76446+++ b/include/linux/err.h
76447@@ -19,12 +19,12 @@
76448
76449 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
76450
76451-static inline void * __must_check ERR_PTR(long error)
76452+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
76453 {
76454 return (void *) error;
76455 }
76456
76457-static inline long __must_check PTR_ERR(__force const void *ptr)
76458+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
76459 {
76460 return (long) ptr;
76461 }
76462diff --git a/include/linux/extcon.h b/include/linux/extcon.h
76463index 21c59af..6057a03 100644
76464--- a/include/linux/extcon.h
76465+++ b/include/linux/extcon.h
76466@@ -135,7 +135,7 @@ struct extcon_dev {
76467 /* /sys/class/extcon/.../mutually_exclusive/... */
76468 struct attribute_group attr_g_muex;
76469 struct attribute **attrs_muex;
76470- struct device_attribute *d_attrs_muex;
76471+ device_attribute_no_const *d_attrs_muex;
76472 };
76473
76474 /**
76475diff --git a/include/linux/fb.h b/include/linux/fb.h
76476index 70c4836..ff3daec 100644
76477--- a/include/linux/fb.h
76478+++ b/include/linux/fb.h
76479@@ -304,7 +304,7 @@ struct fb_ops {
76480 /* called at KDB enter and leave time to prepare the console */
76481 int (*fb_debug_enter)(struct fb_info *info);
76482 int (*fb_debug_leave)(struct fb_info *info);
76483-};
76484+} __do_const;
76485
76486 #ifdef CONFIG_FB_TILEBLITTING
76487 #define FB_TILE_CURSOR_NONE 0
76488diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
76489index 085197b..0fa6f0b 100644
76490--- a/include/linux/fdtable.h
76491+++ b/include/linux/fdtable.h
76492@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
76493 void put_files_struct(struct files_struct *fs);
76494 void reset_files_struct(struct files_struct *);
76495 int unshare_files(struct files_struct **);
76496-struct files_struct *dup_fd(struct files_struct *, int *);
76497+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
76498 void do_close_on_exec(struct files_struct *);
76499 int iterate_fd(struct files_struct *, unsigned,
76500 int (*)(const void *, struct file *, unsigned),
76501diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
76502index 8293262..2b3b8bd 100644
76503--- a/include/linux/frontswap.h
76504+++ b/include/linux/frontswap.h
76505@@ -11,7 +11,7 @@ struct frontswap_ops {
76506 int (*load)(unsigned, pgoff_t, struct page *);
76507 void (*invalidate_page)(unsigned, pgoff_t);
76508 void (*invalidate_area)(unsigned);
76509-};
76510+} __no_const;
76511
76512 extern bool frontswap_enabled;
76513 extern struct frontswap_ops *
76514diff --git a/include/linux/fs.h b/include/linux/fs.h
76515index 121f11f..0f2a863 100644
76516--- a/include/linux/fs.h
76517+++ b/include/linux/fs.h
76518@@ -423,7 +423,7 @@ struct address_space {
76519 spinlock_t private_lock; /* for use by the address_space */
76520 struct list_head private_list; /* ditto */
76521 void *private_data; /* ditto */
76522-} __attribute__((aligned(sizeof(long))));
76523+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
76524 /*
76525 * On most architectures that alignment is already the case; but
76526 * must be enforced here for CRIS, to let the least significant bit
76527@@ -466,7 +466,7 @@ struct block_device {
76528 int bd_fsfreeze_count;
76529 /* Mutex for freeze */
76530 struct mutex bd_fsfreeze_mutex;
76531-};
76532+} __randomize_layout;
76533
76534 /*
76535 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
76536@@ -610,7 +610,7 @@ struct inode {
76537 atomic_t i_readcount; /* struct files open RO */
76538 #endif
76539 void *i_private; /* fs or device private pointer */
76540-};
76541+} __randomize_layout;
76542
76543 static inline int inode_unhashed(struct inode *inode)
76544 {
76545@@ -808,7 +808,7 @@ struct file {
76546 #ifdef CONFIG_DEBUG_WRITECOUNT
76547 unsigned long f_mnt_write_state;
76548 #endif
76549-};
76550+} __randomize_layout;
76551
76552 struct file_handle {
76553 __u32 handle_bytes;
76554@@ -978,7 +978,7 @@ struct file_lock {
76555 int state; /* state of grant or error if -ve */
76556 } afs;
76557 } fl_u;
76558-};
76559+} __randomize_layout;
76560
76561 /* The following constant reflects the upper bound of the file/locking space */
76562 #ifndef OFFSET_MAX
76563@@ -1325,7 +1325,7 @@ struct super_block {
76564 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
76565 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
76566 struct rcu_head rcu;
76567-};
76568+} __randomize_layout;
76569
76570 extern struct timespec current_fs_time(struct super_block *sb);
76571
76572@@ -1547,7 +1547,8 @@ struct file_operations {
76573 long (*fallocate)(struct file *file, int mode, loff_t offset,
76574 loff_t len);
76575 int (*show_fdinfo)(struct seq_file *m, struct file *f);
76576-};
76577+} __do_const __randomize_layout;
76578+typedef struct file_operations __no_const file_operations_no_const;
76579
76580 struct inode_operations {
76581 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
76582@@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
76583 return !IS_DEADDIR(inode);
76584 }
76585
76586+static inline bool is_sidechannel_device(const struct inode *inode)
76587+{
76588+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
76589+ umode_t mode = inode->i_mode;
76590+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
76591+#else
76592+ return false;
76593+#endif
76594+}
76595+
76596 #endif /* _LINUX_FS_H */
76597diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
76598index 0efc3e6..fd23610 100644
76599--- a/include/linux/fs_struct.h
76600+++ b/include/linux/fs_struct.h
76601@@ -6,13 +6,13 @@
76602 #include <linux/seqlock.h>
76603
76604 struct fs_struct {
76605- int users;
76606+ atomic_t users;
76607 spinlock_t lock;
76608 seqcount_t seq;
76609 int umask;
76610 int in_exec;
76611 struct path root, pwd;
76612-};
76613+} __randomize_layout;
76614
76615 extern struct kmem_cache *fs_cachep;
76616
76617diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
76618index 7714849..a4a5c7a 100644
76619--- a/include/linux/fscache-cache.h
76620+++ b/include/linux/fscache-cache.h
76621@@ -113,7 +113,7 @@ struct fscache_operation {
76622 fscache_operation_release_t release;
76623 };
76624
76625-extern atomic_t fscache_op_debug_id;
76626+extern atomic_unchecked_t fscache_op_debug_id;
76627 extern void fscache_op_work_func(struct work_struct *work);
76628
76629 extern void fscache_enqueue_operation(struct fscache_operation *);
76630@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
76631 INIT_WORK(&op->work, fscache_op_work_func);
76632 atomic_set(&op->usage, 1);
76633 op->state = FSCACHE_OP_ST_INITIALISED;
76634- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
76635+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
76636 op->processor = processor;
76637 op->release = release;
76638 INIT_LIST_HEAD(&op->pend_link);
76639diff --git a/include/linux/fscache.h b/include/linux/fscache.h
76640index 115bb81..e7b812b 100644
76641--- a/include/linux/fscache.h
76642+++ b/include/linux/fscache.h
76643@@ -152,7 +152,7 @@ struct fscache_cookie_def {
76644 * - this is mandatory for any object that may have data
76645 */
76646 void (*now_uncached)(void *cookie_netfs_data);
76647-};
76648+} __do_const;
76649
76650 /*
76651 * fscache cached network filesystem type
76652diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
76653index 1c804b0..1432c2b 100644
76654--- a/include/linux/fsnotify.h
76655+++ b/include/linux/fsnotify.h
76656@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
76657 struct inode *inode = file_inode(file);
76658 __u32 mask = FS_ACCESS;
76659
76660+ if (is_sidechannel_device(inode))
76661+ return;
76662+
76663 if (S_ISDIR(inode->i_mode))
76664 mask |= FS_ISDIR;
76665
76666@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
76667 struct inode *inode = file_inode(file);
76668 __u32 mask = FS_MODIFY;
76669
76670+ if (is_sidechannel_device(inode))
76671+ return;
76672+
76673 if (S_ISDIR(inode->i_mode))
76674 mask |= FS_ISDIR;
76675
76676@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
76677 */
76678 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
76679 {
76680- return kstrdup(name, GFP_KERNEL);
76681+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
76682 }
76683
76684 /*
76685diff --git a/include/linux/genhd.h b/include/linux/genhd.h
76686index 9f3c275..8bdff5d 100644
76687--- a/include/linux/genhd.h
76688+++ b/include/linux/genhd.h
76689@@ -194,7 +194,7 @@ struct gendisk {
76690 struct kobject *slave_dir;
76691
76692 struct timer_rand_state *random;
76693- atomic_t sync_io; /* RAID */
76694+ atomic_unchecked_t sync_io; /* RAID */
76695 struct disk_events *ev;
76696 #ifdef CONFIG_BLK_DEV_INTEGRITY
76697 struct blk_integrity *integrity;
76698@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
76699 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
76700
76701 /* drivers/char/random.c */
76702-extern void add_disk_randomness(struct gendisk *disk);
76703+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
76704 extern void rand_initialize_disk(struct gendisk *disk);
76705
76706 static inline sector_t get_start_sect(struct block_device *bdev)
76707diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
76708index c0894dd..2fbf10c 100644
76709--- a/include/linux/genl_magic_func.h
76710+++ b/include/linux/genl_magic_func.h
76711@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
76712 },
76713
76714 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
76715-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
76716+static struct genl_ops ZZZ_genl_ops[] = {
76717 #include GENL_MAGIC_INCLUDE_FILE
76718 };
76719
76720diff --git a/include/linux/gfp.h b/include/linux/gfp.h
76721index 9b4dd49..61fd41d 100644
76722--- a/include/linux/gfp.h
76723+++ b/include/linux/gfp.h
76724@@ -35,6 +35,13 @@ struct vm_area_struct;
76725 #define ___GFP_NO_KSWAPD 0x400000u
76726 #define ___GFP_OTHER_NODE 0x800000u
76727 #define ___GFP_WRITE 0x1000000u
76728+
76729+#ifdef CONFIG_PAX_USERCOPY_SLABS
76730+#define ___GFP_USERCOPY 0x2000000u
76731+#else
76732+#define ___GFP_USERCOPY 0
76733+#endif
76734+
76735 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
76736
76737 /*
76738@@ -92,6 +99,7 @@ struct vm_area_struct;
76739 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
76740 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
76741 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
76742+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
76743
76744 /*
76745 * This may seem redundant, but it's a way of annotating false positives vs.
76746@@ -99,7 +107,7 @@ struct vm_area_struct;
76747 */
76748 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
76749
76750-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
76751+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
76752 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
76753
76754 /* This equals 0, but use constants in case they ever change */
76755@@ -153,6 +161,8 @@ struct vm_area_struct;
76756 /* 4GB DMA on some platforms */
76757 #define GFP_DMA32 __GFP_DMA32
76758
76759+#define GFP_USERCOPY __GFP_USERCOPY
76760+
76761 /* Convert GFP flags to their corresponding migrate type */
76762 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
76763 {
76764diff --git a/include/linux/gracl.h b/include/linux/gracl.h
76765new file mode 100644
76766index 0000000..edb2cb6
76767--- /dev/null
76768+++ b/include/linux/gracl.h
76769@@ -0,0 +1,340 @@
76770+#ifndef GR_ACL_H
76771+#define GR_ACL_H
76772+
76773+#include <linux/grdefs.h>
76774+#include <linux/resource.h>
76775+#include <linux/capability.h>
76776+#include <linux/dcache.h>
76777+#include <asm/resource.h>
76778+
76779+/* Major status information */
76780+
76781+#define GR_VERSION "grsecurity 3.0"
76782+#define GRSECURITY_VERSION 0x3000
76783+
76784+enum {
76785+ GR_SHUTDOWN = 0,
76786+ GR_ENABLE = 1,
76787+ GR_SPROLE = 2,
76788+ GR_OLDRELOAD = 3,
76789+ GR_SEGVMOD = 4,
76790+ GR_STATUS = 5,
76791+ GR_UNSPROLE = 6,
76792+ GR_PASSSET = 7,
76793+ GR_SPROLEPAM = 8,
76794+ GR_RELOAD = 9,
76795+};
76796+
76797+/* Password setup definitions
76798+ * kernel/grhash.c */
76799+enum {
76800+ GR_PW_LEN = 128,
76801+ GR_SALT_LEN = 16,
76802+ GR_SHA_LEN = 32,
76803+};
76804+
76805+enum {
76806+ GR_SPROLE_LEN = 64,
76807+};
76808+
76809+enum {
76810+ GR_NO_GLOB = 0,
76811+ GR_REG_GLOB,
76812+ GR_CREATE_GLOB
76813+};
76814+
76815+#define GR_NLIMITS 32
76816+
76817+/* Begin Data Structures */
76818+
76819+struct sprole_pw {
76820+ unsigned char *rolename;
76821+ unsigned char salt[GR_SALT_LEN];
76822+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
76823+};
76824+
76825+struct name_entry {
76826+ __u32 key;
76827+ ino_t inode;
76828+ dev_t device;
76829+ char *name;
76830+ __u16 len;
76831+ __u8 deleted;
76832+ struct name_entry *prev;
76833+ struct name_entry *next;
76834+};
76835+
76836+struct inodev_entry {
76837+ struct name_entry *nentry;
76838+ struct inodev_entry *prev;
76839+ struct inodev_entry *next;
76840+};
76841+
76842+struct acl_role_db {
76843+ struct acl_role_label **r_hash;
76844+ __u32 r_size;
76845+};
76846+
76847+struct inodev_db {
76848+ struct inodev_entry **i_hash;
76849+ __u32 i_size;
76850+};
76851+
76852+struct name_db {
76853+ struct name_entry **n_hash;
76854+ __u32 n_size;
76855+};
76856+
76857+struct crash_uid {
76858+ uid_t uid;
76859+ unsigned long expires;
76860+};
76861+
76862+struct gr_hash_struct {
76863+ void **table;
76864+ void **nametable;
76865+ void *first;
76866+ __u32 table_size;
76867+ __u32 used_size;
76868+ int type;
76869+};
76870+
76871+/* Userspace Grsecurity ACL data structures */
76872+
76873+struct acl_subject_label {
76874+ char *filename;
76875+ ino_t inode;
76876+ dev_t device;
76877+ __u32 mode;
76878+ kernel_cap_t cap_mask;
76879+ kernel_cap_t cap_lower;
76880+ kernel_cap_t cap_invert_audit;
76881+
76882+ struct rlimit res[GR_NLIMITS];
76883+ __u32 resmask;
76884+
76885+ __u8 user_trans_type;
76886+ __u8 group_trans_type;
76887+ uid_t *user_transitions;
76888+ gid_t *group_transitions;
76889+ __u16 user_trans_num;
76890+ __u16 group_trans_num;
76891+
76892+ __u32 sock_families[2];
76893+ __u32 ip_proto[8];
76894+ __u32 ip_type;
76895+ struct acl_ip_label **ips;
76896+ __u32 ip_num;
76897+ __u32 inaddr_any_override;
76898+
76899+ __u32 crashes;
76900+ unsigned long expires;
76901+
76902+ struct acl_subject_label *parent_subject;
76903+ struct gr_hash_struct *hash;
76904+ struct acl_subject_label *prev;
76905+ struct acl_subject_label *next;
76906+
76907+ struct acl_object_label **obj_hash;
76908+ __u32 obj_hash_size;
76909+ __u16 pax_flags;
76910+};
76911+
76912+struct role_allowed_ip {
76913+ __u32 addr;
76914+ __u32 netmask;
76915+
76916+ struct role_allowed_ip *prev;
76917+ struct role_allowed_ip *next;
76918+};
76919+
76920+struct role_transition {
76921+ char *rolename;
76922+
76923+ struct role_transition *prev;
76924+ struct role_transition *next;
76925+};
76926+
76927+struct acl_role_label {
76928+ char *rolename;
76929+ uid_t uidgid;
76930+ __u16 roletype;
76931+
76932+ __u16 auth_attempts;
76933+ unsigned long expires;
76934+
76935+ struct acl_subject_label *root_label;
76936+ struct gr_hash_struct *hash;
76937+
76938+ struct acl_role_label *prev;
76939+ struct acl_role_label *next;
76940+
76941+ struct role_transition *transitions;
76942+ struct role_allowed_ip *allowed_ips;
76943+ uid_t *domain_children;
76944+ __u16 domain_child_num;
76945+
76946+ umode_t umask;
76947+
76948+ struct acl_subject_label **subj_hash;
76949+ __u32 subj_hash_size;
76950+};
76951+
76952+struct user_acl_role_db {
76953+ struct acl_role_label **r_table;
76954+ __u32 num_pointers; /* Number of allocations to track */
76955+ __u32 num_roles; /* Number of roles */
76956+ __u32 num_domain_children; /* Number of domain children */
76957+ __u32 num_subjects; /* Number of subjects */
76958+ __u32 num_objects; /* Number of objects */
76959+};
76960+
76961+struct acl_object_label {
76962+ char *filename;
76963+ ino_t inode;
76964+ dev_t device;
76965+ __u32 mode;
76966+
76967+ struct acl_subject_label *nested;
76968+ struct acl_object_label *globbed;
76969+
76970+ /* next two structures not used */
76971+
76972+ struct acl_object_label *prev;
76973+ struct acl_object_label *next;
76974+};
76975+
76976+struct acl_ip_label {
76977+ char *iface;
76978+ __u32 addr;
76979+ __u32 netmask;
76980+ __u16 low, high;
76981+ __u8 mode;
76982+ __u32 type;
76983+ __u32 proto[8];
76984+
76985+ /* next two structures not used */
76986+
76987+ struct acl_ip_label *prev;
76988+ struct acl_ip_label *next;
76989+};
76990+
76991+struct gr_arg {
76992+ struct user_acl_role_db role_db;
76993+ unsigned char pw[GR_PW_LEN];
76994+ unsigned char salt[GR_SALT_LEN];
76995+ unsigned char sum[GR_SHA_LEN];
76996+ unsigned char sp_role[GR_SPROLE_LEN];
76997+ struct sprole_pw *sprole_pws;
76998+ dev_t segv_device;
76999+ ino_t segv_inode;
77000+ uid_t segv_uid;
77001+ __u16 num_sprole_pws;
77002+ __u16 mode;
77003+};
77004+
77005+struct gr_arg_wrapper {
77006+ struct gr_arg *arg;
77007+ __u32 version;
77008+ __u32 size;
77009+};
77010+
77011+struct subject_map {
77012+ struct acl_subject_label *user;
77013+ struct acl_subject_label *kernel;
77014+ struct subject_map *prev;
77015+ struct subject_map *next;
77016+};
77017+
77018+struct acl_subj_map_db {
77019+ struct subject_map **s_hash;
77020+ __u32 s_size;
77021+};
77022+
77023+struct gr_policy_state {
77024+ struct sprole_pw **acl_special_roles;
77025+ __u16 num_sprole_pws;
77026+ struct acl_role_label *kernel_role;
77027+ struct acl_role_label *role_list;
77028+ struct acl_role_label *default_role;
77029+ struct acl_role_db acl_role_set;
77030+ struct acl_subj_map_db subj_map_set;
77031+ struct name_db name_set;
77032+ struct inodev_db inodev_set;
77033+};
77034+
77035+struct gr_alloc_state {
77036+ unsigned long alloc_stack_next;
77037+ unsigned long alloc_stack_size;
77038+ void **alloc_stack;
77039+};
77040+
77041+struct gr_reload_state {
77042+ struct gr_policy_state oldpolicy;
77043+ struct gr_alloc_state oldalloc;
77044+ struct gr_policy_state newpolicy;
77045+ struct gr_alloc_state newalloc;
77046+ struct gr_policy_state *oldpolicy_ptr;
77047+ struct gr_alloc_state *oldalloc_ptr;
77048+ unsigned char oldmode;
77049+};
77050+
77051+/* End Data Structures Section */
77052+
77053+/* Hash functions generated by empirical testing by Brad Spengler
77054+ Makes good use of the low bits of the inode. Generally 0-1 times
77055+ in loop for successful match. 0-3 for unsuccessful match.
77056+ Shift/add algorithm with modulus of table size and an XOR*/
77057+
77058+static __inline__ unsigned int
77059+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
77060+{
77061+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
77062+}
77063+
77064+ static __inline__ unsigned int
77065+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
77066+{
77067+ return ((const unsigned long)userp % sz);
77068+}
77069+
77070+static __inline__ unsigned int
77071+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
77072+{
77073+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
77074+}
77075+
77076+static __inline__ unsigned int
77077+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
77078+{
77079+ return full_name_hash((const unsigned char *)name, len) % sz;
77080+}
77081+
77082+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
77083+ subj = NULL; \
77084+ iter = 0; \
77085+ while (iter < role->subj_hash_size) { \
77086+ if (subj == NULL) \
77087+ subj = role->subj_hash[iter]; \
77088+ if (subj == NULL) { \
77089+ iter++; \
77090+ continue; \
77091+ }
77092+
77093+#define FOR_EACH_SUBJECT_END(subj,iter) \
77094+ subj = subj->next; \
77095+ if (subj == NULL) \
77096+ iter++; \
77097+ }
77098+
77099+
77100+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
77101+ subj = role->hash->first; \
77102+ while (subj != NULL) {
77103+
77104+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
77105+ subj = subj->next; \
77106+ }
77107+
77108+#endif
77109+
77110diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
77111new file mode 100644
77112index 0000000..33ebd1f
77113--- /dev/null
77114+++ b/include/linux/gracl_compat.h
77115@@ -0,0 +1,156 @@
77116+#ifndef GR_ACL_COMPAT_H
77117+#define GR_ACL_COMPAT_H
77118+
77119+#include <linux/resource.h>
77120+#include <asm/resource.h>
77121+
77122+struct sprole_pw_compat {
77123+ compat_uptr_t rolename;
77124+ unsigned char salt[GR_SALT_LEN];
77125+ unsigned char sum[GR_SHA_LEN];
77126+};
77127+
77128+struct gr_hash_struct_compat {
77129+ compat_uptr_t table;
77130+ compat_uptr_t nametable;
77131+ compat_uptr_t first;
77132+ __u32 table_size;
77133+ __u32 used_size;
77134+ int type;
77135+};
77136+
77137+struct acl_subject_label_compat {
77138+ compat_uptr_t filename;
77139+ compat_ino_t inode;
77140+ __u32 device;
77141+ __u32 mode;
77142+ kernel_cap_t cap_mask;
77143+ kernel_cap_t cap_lower;
77144+ kernel_cap_t cap_invert_audit;
77145+
77146+ struct compat_rlimit res[GR_NLIMITS];
77147+ __u32 resmask;
77148+
77149+ __u8 user_trans_type;
77150+ __u8 group_trans_type;
77151+ compat_uptr_t user_transitions;
77152+ compat_uptr_t group_transitions;
77153+ __u16 user_trans_num;
77154+ __u16 group_trans_num;
77155+
77156+ __u32 sock_families[2];
77157+ __u32 ip_proto[8];
77158+ __u32 ip_type;
77159+ compat_uptr_t ips;
77160+ __u32 ip_num;
77161+ __u32 inaddr_any_override;
77162+
77163+ __u32 crashes;
77164+ compat_ulong_t expires;
77165+
77166+ compat_uptr_t parent_subject;
77167+ compat_uptr_t hash;
77168+ compat_uptr_t prev;
77169+ compat_uptr_t next;
77170+
77171+ compat_uptr_t obj_hash;
77172+ __u32 obj_hash_size;
77173+ __u16 pax_flags;
77174+};
77175+
77176+struct role_allowed_ip_compat {
77177+ __u32 addr;
77178+ __u32 netmask;
77179+
77180+ compat_uptr_t prev;
77181+ compat_uptr_t next;
77182+};
77183+
77184+struct role_transition_compat {
77185+ compat_uptr_t rolename;
77186+
77187+ compat_uptr_t prev;
77188+ compat_uptr_t next;
77189+};
77190+
77191+struct acl_role_label_compat {
77192+ compat_uptr_t rolename;
77193+ uid_t uidgid;
77194+ __u16 roletype;
77195+
77196+ __u16 auth_attempts;
77197+ compat_ulong_t expires;
77198+
77199+ compat_uptr_t root_label;
77200+ compat_uptr_t hash;
77201+
77202+ compat_uptr_t prev;
77203+ compat_uptr_t next;
77204+
77205+ compat_uptr_t transitions;
77206+ compat_uptr_t allowed_ips;
77207+ compat_uptr_t domain_children;
77208+ __u16 domain_child_num;
77209+
77210+ umode_t umask;
77211+
77212+ compat_uptr_t subj_hash;
77213+ __u32 subj_hash_size;
77214+};
77215+
77216+struct user_acl_role_db_compat {
77217+ compat_uptr_t r_table;
77218+ __u32 num_pointers;
77219+ __u32 num_roles;
77220+ __u32 num_domain_children;
77221+ __u32 num_subjects;
77222+ __u32 num_objects;
77223+};
77224+
77225+struct acl_object_label_compat {
77226+ compat_uptr_t filename;
77227+ compat_ino_t inode;
77228+ __u32 device;
77229+ __u32 mode;
77230+
77231+ compat_uptr_t nested;
77232+ compat_uptr_t globbed;
77233+
77234+ compat_uptr_t prev;
77235+ compat_uptr_t next;
77236+};
77237+
77238+struct acl_ip_label_compat {
77239+ compat_uptr_t iface;
77240+ __u32 addr;
77241+ __u32 netmask;
77242+ __u16 low, high;
77243+ __u8 mode;
77244+ __u32 type;
77245+ __u32 proto[8];
77246+
77247+ compat_uptr_t prev;
77248+ compat_uptr_t next;
77249+};
77250+
77251+struct gr_arg_compat {
77252+ struct user_acl_role_db_compat role_db;
77253+ unsigned char pw[GR_PW_LEN];
77254+ unsigned char salt[GR_SALT_LEN];
77255+ unsigned char sum[GR_SHA_LEN];
77256+ unsigned char sp_role[GR_SPROLE_LEN];
77257+ compat_uptr_t sprole_pws;
77258+ __u32 segv_device;
77259+ compat_ino_t segv_inode;
77260+ uid_t segv_uid;
77261+ __u16 num_sprole_pws;
77262+ __u16 mode;
77263+};
77264+
77265+struct gr_arg_wrapper_compat {
77266+ compat_uptr_t arg;
77267+ __u32 version;
77268+ __u32 size;
77269+};
77270+
77271+#endif
77272diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
77273new file mode 100644
77274index 0000000..323ecf2
77275--- /dev/null
77276+++ b/include/linux/gralloc.h
77277@@ -0,0 +1,9 @@
77278+#ifndef __GRALLOC_H
77279+#define __GRALLOC_H
77280+
77281+void acl_free_all(void);
77282+int acl_alloc_stack_init(unsigned long size);
77283+void *acl_alloc(unsigned long len);
77284+void *acl_alloc_num(unsigned long num, unsigned long len);
77285+
77286+#endif
77287diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
77288new file mode 100644
77289index 0000000..be66033
77290--- /dev/null
77291+++ b/include/linux/grdefs.h
77292@@ -0,0 +1,140 @@
77293+#ifndef GRDEFS_H
77294+#define GRDEFS_H
77295+
77296+/* Begin grsecurity status declarations */
77297+
77298+enum {
77299+ GR_READY = 0x01,
77300+ GR_STATUS_INIT = 0x00 // disabled state
77301+};
77302+
77303+/* Begin ACL declarations */
77304+
77305+/* Role flags */
77306+
77307+enum {
77308+ GR_ROLE_USER = 0x0001,
77309+ GR_ROLE_GROUP = 0x0002,
77310+ GR_ROLE_DEFAULT = 0x0004,
77311+ GR_ROLE_SPECIAL = 0x0008,
77312+ GR_ROLE_AUTH = 0x0010,
77313+ GR_ROLE_NOPW = 0x0020,
77314+ GR_ROLE_GOD = 0x0040,
77315+ GR_ROLE_LEARN = 0x0080,
77316+ GR_ROLE_TPE = 0x0100,
77317+ GR_ROLE_DOMAIN = 0x0200,
77318+ GR_ROLE_PAM = 0x0400,
77319+ GR_ROLE_PERSIST = 0x0800
77320+};
77321+
77322+/* ACL Subject and Object mode flags */
77323+enum {
77324+ GR_DELETED = 0x80000000
77325+};
77326+
77327+/* ACL Object-only mode flags */
77328+enum {
77329+ GR_READ = 0x00000001,
77330+ GR_APPEND = 0x00000002,
77331+ GR_WRITE = 0x00000004,
77332+ GR_EXEC = 0x00000008,
77333+ GR_FIND = 0x00000010,
77334+ GR_INHERIT = 0x00000020,
77335+ GR_SETID = 0x00000040,
77336+ GR_CREATE = 0x00000080,
77337+ GR_DELETE = 0x00000100,
77338+ GR_LINK = 0x00000200,
77339+ GR_AUDIT_READ = 0x00000400,
77340+ GR_AUDIT_APPEND = 0x00000800,
77341+ GR_AUDIT_WRITE = 0x00001000,
77342+ GR_AUDIT_EXEC = 0x00002000,
77343+ GR_AUDIT_FIND = 0x00004000,
77344+ GR_AUDIT_INHERIT= 0x00008000,
77345+ GR_AUDIT_SETID = 0x00010000,
77346+ GR_AUDIT_CREATE = 0x00020000,
77347+ GR_AUDIT_DELETE = 0x00040000,
77348+ GR_AUDIT_LINK = 0x00080000,
77349+ GR_PTRACERD = 0x00100000,
77350+ GR_NOPTRACE = 0x00200000,
77351+ GR_SUPPRESS = 0x00400000,
77352+ GR_NOLEARN = 0x00800000,
77353+ GR_INIT_TRANSFER= 0x01000000
77354+};
77355+
77356+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
77357+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
77358+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
77359+
77360+/* ACL subject-only mode flags */
77361+enum {
77362+ GR_KILL = 0x00000001,
77363+ GR_VIEW = 0x00000002,
77364+ GR_PROTECTED = 0x00000004,
77365+ GR_LEARN = 0x00000008,
77366+ GR_OVERRIDE = 0x00000010,
77367+ /* just a placeholder, this mode is only used in userspace */
77368+ GR_DUMMY = 0x00000020,
77369+ GR_PROTSHM = 0x00000040,
77370+ GR_KILLPROC = 0x00000080,
77371+ GR_KILLIPPROC = 0x00000100,
77372+ /* just a placeholder, this mode is only used in userspace */
77373+ GR_NOTROJAN = 0x00000200,
77374+ GR_PROTPROCFD = 0x00000400,
77375+ GR_PROCACCT = 0x00000800,
77376+ GR_RELAXPTRACE = 0x00001000,
77377+ //GR_NESTED = 0x00002000,
77378+ GR_INHERITLEARN = 0x00004000,
77379+ GR_PROCFIND = 0x00008000,
77380+ GR_POVERRIDE = 0x00010000,
77381+ GR_KERNELAUTH = 0x00020000,
77382+ GR_ATSECURE = 0x00040000,
77383+ GR_SHMEXEC = 0x00080000
77384+};
77385+
77386+enum {
77387+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
77388+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
77389+ GR_PAX_ENABLE_MPROTECT = 0x0004,
77390+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
77391+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
77392+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
77393+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
77394+ GR_PAX_DISABLE_MPROTECT = 0x0400,
77395+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
77396+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
77397+};
77398+
77399+enum {
77400+ GR_ID_USER = 0x01,
77401+ GR_ID_GROUP = 0x02,
77402+};
77403+
77404+enum {
77405+ GR_ID_ALLOW = 0x01,
77406+ GR_ID_DENY = 0x02,
77407+};
77408+
77409+#define GR_CRASH_RES 31
77410+#define GR_UIDTABLE_MAX 500
77411+
77412+/* begin resource learning section */
77413+enum {
77414+ GR_RLIM_CPU_BUMP = 60,
77415+ GR_RLIM_FSIZE_BUMP = 50000,
77416+ GR_RLIM_DATA_BUMP = 10000,
77417+ GR_RLIM_STACK_BUMP = 1000,
77418+ GR_RLIM_CORE_BUMP = 10000,
77419+ GR_RLIM_RSS_BUMP = 500000,
77420+ GR_RLIM_NPROC_BUMP = 1,
77421+ GR_RLIM_NOFILE_BUMP = 5,
77422+ GR_RLIM_MEMLOCK_BUMP = 50000,
77423+ GR_RLIM_AS_BUMP = 500000,
77424+ GR_RLIM_LOCKS_BUMP = 2,
77425+ GR_RLIM_SIGPENDING_BUMP = 5,
77426+ GR_RLIM_MSGQUEUE_BUMP = 10000,
77427+ GR_RLIM_NICE_BUMP = 1,
77428+ GR_RLIM_RTPRIO_BUMP = 1,
77429+ GR_RLIM_RTTIME_BUMP = 1000000
77430+};
77431+
77432+#endif
77433diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
77434new file mode 100644
77435index 0000000..d25522e
77436--- /dev/null
77437+++ b/include/linux/grinternal.h
77438@@ -0,0 +1,229 @@
77439+#ifndef __GRINTERNAL_H
77440+#define __GRINTERNAL_H
77441+
77442+#ifdef CONFIG_GRKERNSEC
77443+
77444+#include <linux/fs.h>
77445+#include <linux/mnt_namespace.h>
77446+#include <linux/nsproxy.h>
77447+#include <linux/gracl.h>
77448+#include <linux/grdefs.h>
77449+#include <linux/grmsg.h>
77450+
77451+void gr_add_learn_entry(const char *fmt, ...)
77452+ __attribute__ ((format (printf, 1, 2)));
77453+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
77454+ const struct vfsmount *mnt);
77455+__u32 gr_check_create(const struct dentry *new_dentry,
77456+ const struct dentry *parent,
77457+ const struct vfsmount *mnt, const __u32 mode);
77458+int gr_check_protected_task(const struct task_struct *task);
77459+__u32 to_gr_audit(const __u32 reqmode);
77460+int gr_set_acls(const int type);
77461+int gr_acl_is_enabled(void);
77462+char gr_roletype_to_char(void);
77463+
77464+void gr_handle_alertkill(struct task_struct *task);
77465+char *gr_to_filename(const struct dentry *dentry,
77466+ const struct vfsmount *mnt);
77467+char *gr_to_filename1(const struct dentry *dentry,
77468+ const struct vfsmount *mnt);
77469+char *gr_to_filename2(const struct dentry *dentry,
77470+ const struct vfsmount *mnt);
77471+char *gr_to_filename3(const struct dentry *dentry,
77472+ const struct vfsmount *mnt);
77473+
77474+extern int grsec_enable_ptrace_readexec;
77475+extern int grsec_enable_harden_ptrace;
77476+extern int grsec_enable_link;
77477+extern int grsec_enable_fifo;
77478+extern int grsec_enable_execve;
77479+extern int grsec_enable_shm;
77480+extern int grsec_enable_execlog;
77481+extern int grsec_enable_signal;
77482+extern int grsec_enable_audit_ptrace;
77483+extern int grsec_enable_forkfail;
77484+extern int grsec_enable_time;
77485+extern int grsec_enable_rofs;
77486+extern int grsec_deny_new_usb;
77487+extern int grsec_enable_chroot_shmat;
77488+extern int grsec_enable_chroot_mount;
77489+extern int grsec_enable_chroot_double;
77490+extern int grsec_enable_chroot_pivot;
77491+extern int grsec_enable_chroot_chdir;
77492+extern int grsec_enable_chroot_chmod;
77493+extern int grsec_enable_chroot_mknod;
77494+extern int grsec_enable_chroot_fchdir;
77495+extern int grsec_enable_chroot_nice;
77496+extern int grsec_enable_chroot_execlog;
77497+extern int grsec_enable_chroot_caps;
77498+extern int grsec_enable_chroot_sysctl;
77499+extern int grsec_enable_chroot_unix;
77500+extern int grsec_enable_symlinkown;
77501+extern kgid_t grsec_symlinkown_gid;
77502+extern int grsec_enable_tpe;
77503+extern kgid_t grsec_tpe_gid;
77504+extern int grsec_enable_tpe_all;
77505+extern int grsec_enable_tpe_invert;
77506+extern int grsec_enable_socket_all;
77507+extern kgid_t grsec_socket_all_gid;
77508+extern int grsec_enable_socket_client;
77509+extern kgid_t grsec_socket_client_gid;
77510+extern int grsec_enable_socket_server;
77511+extern kgid_t grsec_socket_server_gid;
77512+extern kgid_t grsec_audit_gid;
77513+extern int grsec_enable_group;
77514+extern int grsec_enable_log_rwxmaps;
77515+extern int grsec_enable_mount;
77516+extern int grsec_enable_chdir;
77517+extern int grsec_resource_logging;
77518+extern int grsec_enable_blackhole;
77519+extern int grsec_lastack_retries;
77520+extern int grsec_enable_brute;
77521+extern int grsec_enable_harden_ipc;
77522+extern int grsec_lock;
77523+
77524+extern spinlock_t grsec_alert_lock;
77525+extern unsigned long grsec_alert_wtime;
77526+extern unsigned long grsec_alert_fyet;
77527+
77528+extern spinlock_t grsec_audit_lock;
77529+
77530+extern rwlock_t grsec_exec_file_lock;
77531+
77532+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
77533+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
77534+ (tsk)->exec_file->f_path.mnt) : "/")
77535+
77536+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
77537+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
77538+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77539+
77540+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
77541+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
77542+ (tsk)->exec_file->f_path.mnt) : "/")
77543+
77544+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
77545+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
77546+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77547+
77548+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
77549+
77550+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
77551+
77552+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
77553+{
77554+ if (file1 && file2) {
77555+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
77556+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
77557+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
77558+ return true;
77559+ }
77560+
77561+ return false;
77562+}
77563+
77564+#define GR_CHROOT_CAPS {{ \
77565+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
77566+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
77567+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
77568+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
77569+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
77570+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
77571+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
77572+
77573+#define security_learn(normal_msg,args...) \
77574+({ \
77575+ read_lock(&grsec_exec_file_lock); \
77576+ gr_add_learn_entry(normal_msg "\n", ## args); \
77577+ read_unlock(&grsec_exec_file_lock); \
77578+})
77579+
77580+enum {
77581+ GR_DO_AUDIT,
77582+ GR_DONT_AUDIT,
77583+ /* used for non-audit messages that we shouldn't kill the task on */
77584+ GR_DONT_AUDIT_GOOD
77585+};
77586+
77587+enum {
77588+ GR_TTYSNIFF,
77589+ GR_RBAC,
77590+ GR_RBAC_STR,
77591+ GR_STR_RBAC,
77592+ GR_RBAC_MODE2,
77593+ GR_RBAC_MODE3,
77594+ GR_FILENAME,
77595+ GR_SYSCTL_HIDDEN,
77596+ GR_NOARGS,
77597+ GR_ONE_INT,
77598+ GR_ONE_INT_TWO_STR,
77599+ GR_ONE_STR,
77600+ GR_STR_INT,
77601+ GR_TWO_STR_INT,
77602+ GR_TWO_INT,
77603+ GR_TWO_U64,
77604+ GR_THREE_INT,
77605+ GR_FIVE_INT_TWO_STR,
77606+ GR_TWO_STR,
77607+ GR_THREE_STR,
77608+ GR_FOUR_STR,
77609+ GR_STR_FILENAME,
77610+ GR_FILENAME_STR,
77611+ GR_FILENAME_TWO_INT,
77612+ GR_FILENAME_TWO_INT_STR,
77613+ GR_TEXTREL,
77614+ GR_PTRACE,
77615+ GR_RESOURCE,
77616+ GR_CAP,
77617+ GR_SIG,
77618+ GR_SIG2,
77619+ GR_CRASH1,
77620+ GR_CRASH2,
77621+ GR_PSACCT,
77622+ GR_RWXMAP,
77623+ GR_RWXMAPVMA
77624+};
77625+
77626+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
77627+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
77628+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
77629+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
77630+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
77631+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
77632+#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)
77633+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
77634+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
77635+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
77636+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
77637+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
77638+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
77639+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
77640+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
77641+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
77642+#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)
77643+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
77644+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
77645+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
77646+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
77647+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
77648+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
77649+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
77650+#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)
77651+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
77652+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
77653+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
77654+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
77655+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
77656+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
77657+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
77658+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
77659+#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)
77660+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
77661+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
77662+
77663+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
77664+
77665+#endif
77666+
77667+#endif
77668diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
77669new file mode 100644
77670index 0000000..195cbe4
77671--- /dev/null
77672+++ b/include/linux/grmsg.h
77673@@ -0,0 +1,115 @@
77674+#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"
77675+#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"
77676+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
77677+#define GR_STOPMOD_MSG "denied modification of module state by "
77678+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
77679+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
77680+#define GR_IOPERM_MSG "denied use of ioperm() by "
77681+#define GR_IOPL_MSG "denied use of iopl() by "
77682+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
77683+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
77684+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
77685+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
77686+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
77687+#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"
77688+#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"
77689+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
77690+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
77691+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
77692+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
77693+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
77694+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
77695+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
77696+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
77697+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
77698+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
77699+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
77700+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
77701+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
77702+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
77703+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
77704+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
77705+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
77706+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
77707+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
77708+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
77709+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
77710+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
77711+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
77712+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
77713+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
77714+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
77715+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
77716+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
77717+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
77718+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
77719+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
77720+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
77721+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
77722+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
77723+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
77724+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
77725+#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"
77726+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
77727+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
77728+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
77729+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
77730+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
77731+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
77732+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
77733+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
77734+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
77735+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
77736+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
77737+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
77738+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
77739+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
77740+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
77741+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
77742+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
77743+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
77744+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
77745+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
77746+#define GR_FAILFORK_MSG "failed fork with errno %s by "
77747+#define GR_NICE_CHROOT_MSG "denied priority change by "
77748+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
77749+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
77750+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
77751+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
77752+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
77753+#define GR_TIME_MSG "time set by "
77754+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
77755+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
77756+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
77757+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
77758+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
77759+#define GR_BIND_MSG "denied bind() by "
77760+#define GR_CONNECT_MSG "denied connect() by "
77761+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
77762+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
77763+#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"
77764+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
77765+#define GR_CAP_ACL_MSG "use of %s denied for "
77766+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
77767+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
77768+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
77769+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
77770+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
77771+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
77772+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
77773+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
77774+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
77775+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
77776+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
77777+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
77778+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
77779+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
77780+#define GR_VM86_MSG "denied use of vm86 by "
77781+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
77782+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
77783+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
77784+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
77785+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
77786+#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 "
77787+#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 "
77788+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
77789diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
77790new file mode 100644
77791index 0000000..d8b5b48
77792--- /dev/null
77793+++ b/include/linux/grsecurity.h
77794@@ -0,0 +1,245 @@
77795+#ifndef GR_SECURITY_H
77796+#define GR_SECURITY_H
77797+#include <linux/fs.h>
77798+#include <linux/fs_struct.h>
77799+#include <linux/binfmts.h>
77800+#include <linux/gracl.h>
77801+
77802+/* notify of brain-dead configs */
77803+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77804+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
77805+#endif
77806+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
77807+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
77808+#endif
77809+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
77810+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
77811+#endif
77812+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
77813+#error "CONFIG_PAX enabled, but no PaX options are enabled."
77814+#endif
77815+
77816+int gr_handle_new_usb(void);
77817+
77818+void gr_handle_brute_attach(int dumpable);
77819+void gr_handle_brute_check(void);
77820+void gr_handle_kernel_exploit(void);
77821+
77822+char gr_roletype_to_char(void);
77823+
77824+int gr_acl_enable_at_secure(void);
77825+
77826+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
77827+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
77828+
77829+void gr_del_task_from_ip_table(struct task_struct *p);
77830+
77831+int gr_pid_is_chrooted(struct task_struct *p);
77832+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
77833+int gr_handle_chroot_nice(void);
77834+int gr_handle_chroot_sysctl(const int op);
77835+int gr_handle_chroot_setpriority(struct task_struct *p,
77836+ const int niceval);
77837+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
77838+int gr_handle_chroot_chroot(const struct dentry *dentry,
77839+ const struct vfsmount *mnt);
77840+void gr_handle_chroot_chdir(const struct path *path);
77841+int gr_handle_chroot_chmod(const struct dentry *dentry,
77842+ const struct vfsmount *mnt, const int mode);
77843+int gr_handle_chroot_mknod(const struct dentry *dentry,
77844+ const struct vfsmount *mnt, const int mode);
77845+int gr_handle_chroot_mount(const struct dentry *dentry,
77846+ const struct vfsmount *mnt,
77847+ const char *dev_name);
77848+int gr_handle_chroot_pivot(void);
77849+int gr_handle_chroot_unix(const pid_t pid);
77850+
77851+int gr_handle_rawio(const struct inode *inode);
77852+
77853+void gr_handle_ioperm(void);
77854+void gr_handle_iopl(void);
77855+
77856+umode_t gr_acl_umask(void);
77857+
77858+int gr_tpe_allow(const struct file *file);
77859+
77860+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
77861+void gr_clear_chroot_entries(struct task_struct *task);
77862+
77863+void gr_log_forkfail(const int retval);
77864+void gr_log_timechange(void);
77865+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
77866+void gr_log_chdir(const struct dentry *dentry,
77867+ const struct vfsmount *mnt);
77868+void gr_log_chroot_exec(const struct dentry *dentry,
77869+ const struct vfsmount *mnt);
77870+void gr_log_remount(const char *devname, const int retval);
77871+void gr_log_unmount(const char *devname, const int retval);
77872+void gr_log_mount(const char *from, const char *to, const int retval);
77873+void gr_log_textrel(struct vm_area_struct *vma);
77874+void gr_log_ptgnustack(struct file *file);
77875+void gr_log_rwxmmap(struct file *file);
77876+void gr_log_rwxmprotect(struct vm_area_struct *vma);
77877+
77878+int gr_handle_follow_link(const struct inode *parent,
77879+ const struct inode *inode,
77880+ const struct dentry *dentry,
77881+ const struct vfsmount *mnt);
77882+int gr_handle_fifo(const struct dentry *dentry,
77883+ const struct vfsmount *mnt,
77884+ const struct dentry *dir, const int flag,
77885+ const int acc_mode);
77886+int gr_handle_hardlink(const struct dentry *dentry,
77887+ const struct vfsmount *mnt,
77888+ struct inode *inode,
77889+ const int mode, const struct filename *to);
77890+
77891+int gr_is_capable(const int cap);
77892+int gr_is_capable_nolog(const int cap);
77893+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77894+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
77895+
77896+void gr_copy_label(struct task_struct *tsk);
77897+void gr_handle_crash(struct task_struct *task, const int sig);
77898+int gr_handle_signal(const struct task_struct *p, const int sig);
77899+int gr_check_crash_uid(const kuid_t uid);
77900+int gr_check_protected_task(const struct task_struct *task);
77901+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
77902+int gr_acl_handle_mmap(const struct file *file,
77903+ const unsigned long prot);
77904+int gr_acl_handle_mprotect(const struct file *file,
77905+ const unsigned long prot);
77906+int gr_check_hidden_task(const struct task_struct *tsk);
77907+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
77908+ const struct vfsmount *mnt);
77909+__u32 gr_acl_handle_utime(const struct dentry *dentry,
77910+ const struct vfsmount *mnt);
77911+__u32 gr_acl_handle_access(const struct dentry *dentry,
77912+ const struct vfsmount *mnt, const int fmode);
77913+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
77914+ const struct vfsmount *mnt, umode_t *mode);
77915+__u32 gr_acl_handle_chown(const struct dentry *dentry,
77916+ const struct vfsmount *mnt);
77917+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
77918+ const struct vfsmount *mnt);
77919+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
77920+ const struct vfsmount *mnt);
77921+int gr_handle_ptrace(struct task_struct *task, const long request);
77922+int gr_handle_proc_ptrace(struct task_struct *task);
77923+__u32 gr_acl_handle_execve(const struct dentry *dentry,
77924+ const struct vfsmount *mnt);
77925+int gr_check_crash_exec(const struct file *filp);
77926+int gr_acl_is_enabled(void);
77927+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
77928+ const kgid_t gid);
77929+int gr_set_proc_label(const struct dentry *dentry,
77930+ const struct vfsmount *mnt,
77931+ const int unsafe_flags);
77932+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
77933+ const struct vfsmount *mnt);
77934+__u32 gr_acl_handle_open(const struct dentry *dentry,
77935+ const struct vfsmount *mnt, int acc_mode);
77936+__u32 gr_acl_handle_creat(const struct dentry *dentry,
77937+ const struct dentry *p_dentry,
77938+ const struct vfsmount *p_mnt,
77939+ int open_flags, int acc_mode, const int imode);
77940+void gr_handle_create(const struct dentry *dentry,
77941+ const struct vfsmount *mnt);
77942+void gr_handle_proc_create(const struct dentry *dentry,
77943+ const struct inode *inode);
77944+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
77945+ const struct dentry *parent_dentry,
77946+ const struct vfsmount *parent_mnt,
77947+ const int mode);
77948+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
77949+ const struct dentry *parent_dentry,
77950+ const struct vfsmount *parent_mnt);
77951+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
77952+ const struct vfsmount *mnt);
77953+void gr_handle_delete(const ino_t ino, const dev_t dev);
77954+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
77955+ const struct vfsmount *mnt);
77956+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
77957+ const struct dentry *parent_dentry,
77958+ const struct vfsmount *parent_mnt,
77959+ const struct filename *from);
77960+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
77961+ const struct dentry *parent_dentry,
77962+ const struct vfsmount *parent_mnt,
77963+ const struct dentry *old_dentry,
77964+ const struct vfsmount *old_mnt, const struct filename *to);
77965+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
77966+int gr_acl_handle_rename(struct dentry *new_dentry,
77967+ struct dentry *parent_dentry,
77968+ const struct vfsmount *parent_mnt,
77969+ struct dentry *old_dentry,
77970+ struct inode *old_parent_inode,
77971+ struct vfsmount *old_mnt, const struct filename *newname);
77972+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
77973+ struct dentry *old_dentry,
77974+ struct dentry *new_dentry,
77975+ struct vfsmount *mnt, const __u8 replace);
77976+__u32 gr_check_link(const struct dentry *new_dentry,
77977+ const struct dentry *parent_dentry,
77978+ const struct vfsmount *parent_mnt,
77979+ const struct dentry *old_dentry,
77980+ const struct vfsmount *old_mnt);
77981+int gr_acl_handle_filldir(const struct file *file, const char *name,
77982+ const unsigned int namelen, const ino_t ino);
77983+
77984+__u32 gr_acl_handle_unix(const struct dentry *dentry,
77985+ const struct vfsmount *mnt);
77986+void gr_acl_handle_exit(void);
77987+void gr_acl_handle_psacct(struct task_struct *task, const long code);
77988+int gr_acl_handle_procpidmem(const struct task_struct *task);
77989+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
77990+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
77991+void gr_audit_ptrace(struct task_struct *task);
77992+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
77993+void gr_put_exec_file(struct task_struct *task);
77994+
77995+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
77996+
77997+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
77998+extern void gr_learn_resource(const struct task_struct *task, const int res,
77999+ const unsigned long wanted, const int gt);
78000+#else
78001+static inline void gr_learn_resource(const struct task_struct *task, const int res,
78002+ const unsigned long wanted, const int gt)
78003+{
78004+}
78005+#endif
78006+
78007+#ifdef CONFIG_GRKERNSEC_RESLOG
78008+extern void gr_log_resource(const struct task_struct *task, const int res,
78009+ const unsigned long wanted, const int gt);
78010+#else
78011+static inline void gr_log_resource(const struct task_struct *task, const int res,
78012+ const unsigned long wanted, const int gt)
78013+{
78014+}
78015+#endif
78016+
78017+#ifdef CONFIG_GRKERNSEC
78018+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
78019+void gr_handle_vm86(void);
78020+void gr_handle_mem_readwrite(u64 from, u64 to);
78021+
78022+void gr_log_badprocpid(const char *entry);
78023+
78024+extern int grsec_enable_dmesg;
78025+extern int grsec_disable_privio;
78026+
78027+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78028+extern kgid_t grsec_proc_gid;
78029+#endif
78030+
78031+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78032+extern int grsec_enable_chroot_findtask;
78033+#endif
78034+#ifdef CONFIG_GRKERNSEC_SETXID
78035+extern int grsec_enable_setxid;
78036+#endif
78037+#endif
78038+
78039+#endif
78040diff --git a/include/linux/grsock.h b/include/linux/grsock.h
78041new file mode 100644
78042index 0000000..e7ffaaf
78043--- /dev/null
78044+++ b/include/linux/grsock.h
78045@@ -0,0 +1,19 @@
78046+#ifndef __GRSOCK_H
78047+#define __GRSOCK_H
78048+
78049+extern void gr_attach_curr_ip(const struct sock *sk);
78050+extern int gr_handle_sock_all(const int family, const int type,
78051+ const int protocol);
78052+extern int gr_handle_sock_server(const struct sockaddr *sck);
78053+extern int gr_handle_sock_server_other(const struct sock *sck);
78054+extern int gr_handle_sock_client(const struct sockaddr *sck);
78055+extern int gr_search_connect(struct socket * sock,
78056+ struct sockaddr_in * addr);
78057+extern int gr_search_bind(struct socket * sock,
78058+ struct sockaddr_in * addr);
78059+extern int gr_search_listen(struct socket * sock);
78060+extern int gr_search_accept(struct socket * sock);
78061+extern int gr_search_socket(const int domain, const int type,
78062+ const int protocol);
78063+
78064+#endif
78065diff --git a/include/linux/highmem.h b/include/linux/highmem.h
78066index 7fb31da..08b5114 100644
78067--- a/include/linux/highmem.h
78068+++ b/include/linux/highmem.h
78069@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
78070 kunmap_atomic(kaddr);
78071 }
78072
78073+static inline void sanitize_highpage(struct page *page)
78074+{
78075+ void *kaddr;
78076+ unsigned long flags;
78077+
78078+ local_irq_save(flags);
78079+ kaddr = kmap_atomic(page);
78080+ clear_page(kaddr);
78081+ kunmap_atomic(kaddr);
78082+ local_irq_restore(flags);
78083+}
78084+
78085 static inline void zero_user_segments(struct page *page,
78086 unsigned start1, unsigned end1,
78087 unsigned start2, unsigned end2)
78088diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
78089index 1c7b89a..7dda400 100644
78090--- a/include/linux/hwmon-sysfs.h
78091+++ b/include/linux/hwmon-sysfs.h
78092@@ -25,7 +25,8 @@
78093 struct sensor_device_attribute{
78094 struct device_attribute dev_attr;
78095 int index;
78096-};
78097+} __do_const;
78098+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
78099 #define to_sensor_dev_attr(_dev_attr) \
78100 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
78101
78102@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
78103 struct device_attribute dev_attr;
78104 u8 index;
78105 u8 nr;
78106-};
78107+} __do_const;
78108+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
78109 #define to_sensor_dev_attr_2(_dev_attr) \
78110 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
78111
78112diff --git a/include/linux/i2c.h b/include/linux/i2c.h
78113index d9c8dbd3..def6e5a 100644
78114--- a/include/linux/i2c.h
78115+++ b/include/linux/i2c.h
78116@@ -364,6 +364,7 @@ struct i2c_algorithm {
78117 /* To determine what the adapter supports */
78118 u32 (*functionality) (struct i2c_adapter *);
78119 };
78120+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
78121
78122 /**
78123 * struct i2c_bus_recovery_info - I2C bus recovery information
78124diff --git a/include/linux/i2o.h b/include/linux/i2o.h
78125index d23c3c2..eb63c81 100644
78126--- a/include/linux/i2o.h
78127+++ b/include/linux/i2o.h
78128@@ -565,7 +565,7 @@ struct i2o_controller {
78129 struct i2o_device *exec; /* Executive */
78130 #if BITS_PER_LONG == 64
78131 spinlock_t context_list_lock; /* lock for context_list */
78132- atomic_t context_list_counter; /* needed for unique contexts */
78133+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
78134 struct list_head context_list; /* list of context id's
78135 and pointers */
78136 #endif
78137diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
78138index aff7ad8..3942bbd 100644
78139--- a/include/linux/if_pppox.h
78140+++ b/include/linux/if_pppox.h
78141@@ -76,7 +76,7 @@ struct pppox_proto {
78142 int (*ioctl)(struct socket *sock, unsigned int cmd,
78143 unsigned long arg);
78144 struct module *owner;
78145-};
78146+} __do_const;
78147
78148 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
78149 extern void unregister_pppox_proto(int proto_num);
78150diff --git a/include/linux/init.h b/include/linux/init.h
78151index 8e68a64..3f977a0 100644
78152--- a/include/linux/init.h
78153+++ b/include/linux/init.h
78154@@ -37,9 +37,17 @@
78155 * section.
78156 */
78157
78158+#define add_init_latent_entropy __latent_entropy
78159+
78160+#ifdef CONFIG_MEMORY_HOTPLUG
78161+#define add_meminit_latent_entropy
78162+#else
78163+#define add_meminit_latent_entropy __latent_entropy
78164+#endif
78165+
78166 /* These are for everybody (although not all archs will actually
78167 discard it in modules) */
78168-#define __init __section(.init.text) __cold notrace
78169+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
78170 #define __initdata __section(.init.data)
78171 #define __initconst __constsection(.init.rodata)
78172 #define __exitdata __section(.exit.data)
78173@@ -100,7 +108,7 @@
78174 #define __cpuexitconst
78175
78176 /* Used for MEMORY_HOTPLUG */
78177-#define __meminit __section(.meminit.text) __cold notrace
78178+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
78179 #define __meminitdata __section(.meminit.data)
78180 #define __meminitconst __constsection(.meminit.rodata)
78181 #define __memexit __section(.memexit.text) __exitused __cold notrace
78182diff --git a/include/linux/init_task.h b/include/linux/init_task.h
78183index b0ed422..d79ea23 100644
78184--- a/include/linux/init_task.h
78185+++ b/include/linux/init_task.h
78186@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
78187
78188 #define INIT_TASK_COMM "swapper"
78189
78190+#ifdef CONFIG_X86
78191+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
78192+#else
78193+#define INIT_TASK_THREAD_INFO
78194+#endif
78195+
78196 /*
78197 * INIT_TASK is used to set up the first task table, touch at
78198 * your own risk!. Base=0, limit=0x1fffff (=2MB)
78199@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
78200 RCU_POINTER_INITIALIZER(cred, &init_cred), \
78201 .comm = INIT_TASK_COMM, \
78202 .thread = INIT_THREAD, \
78203+ INIT_TASK_THREAD_INFO \
78204 .fs = &init_fs, \
78205 .files = &init_files, \
78206 .signal = &init_signals, \
78207diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
78208index db43b58..5d5084b 100644
78209--- a/include/linux/interrupt.h
78210+++ b/include/linux/interrupt.h
78211@@ -360,7 +360,7 @@ enum
78212 /* map softirq index to softirq name. update 'softirq_to_name' in
78213 * kernel/softirq.c when adding a new softirq.
78214 */
78215-extern char *softirq_to_name[NR_SOFTIRQS];
78216+extern const char * const softirq_to_name[NR_SOFTIRQS];
78217
78218 /* softirq mask and active fields moved to irq_cpustat_t in
78219 * asm/hardirq.h to get better cache usage. KAO
78220@@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
78221
78222 struct softirq_action
78223 {
78224- void (*action)(struct softirq_action *);
78225-};
78226+ void (*action)(void);
78227+} __no_const;
78228
78229 asmlinkage void do_softirq(void);
78230 asmlinkage void __do_softirq(void);
78231@@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
78232 }
78233 #endif
78234
78235-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
78236+extern void open_softirq(int nr, void (*action)(void));
78237 extern void softirq_init(void);
78238 extern void __raise_softirq_irqoff(unsigned int nr);
78239
78240diff --git a/include/linux/iommu.h b/include/linux/iommu.h
78241index a444c79..8c41ea9 100644
78242--- a/include/linux/iommu.h
78243+++ b/include/linux/iommu.h
78244@@ -130,7 +130,7 @@ struct iommu_ops {
78245 u32 (*domain_get_windows)(struct iommu_domain *domain);
78246
78247 unsigned long pgsize_bitmap;
78248-};
78249+} __do_const;
78250
78251 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
78252 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
78253diff --git a/include/linux/ioport.h b/include/linux/ioport.h
78254index 89b7c24..382af74 100644
78255--- a/include/linux/ioport.h
78256+++ b/include/linux/ioport.h
78257@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
78258 int adjust_resource(struct resource *res, resource_size_t start,
78259 resource_size_t size);
78260 resource_size_t resource_alignment(struct resource *res);
78261-static inline resource_size_t resource_size(const struct resource *res)
78262+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
78263 {
78264 return res->end - res->start + 1;
78265 }
78266diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
78267index f6c82de..de8619e 100644
78268--- a/include/linux/ipc_namespace.h
78269+++ b/include/linux/ipc_namespace.h
78270@@ -70,7 +70,7 @@ struct ipc_namespace {
78271 struct user_namespace *user_ns;
78272
78273 unsigned int proc_inum;
78274-};
78275+} __randomize_layout;
78276
78277 extern struct ipc_namespace init_ipc_ns;
78278 extern atomic_t nr_ipc_ns;
78279diff --git a/include/linux/irq.h b/include/linux/irq.h
78280index 7dc1003..407327b 100644
78281--- a/include/linux/irq.h
78282+++ b/include/linux/irq.h
78283@@ -338,7 +338,8 @@ struct irq_chip {
78284 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
78285
78286 unsigned long flags;
78287-};
78288+} __do_const;
78289+typedef struct irq_chip __no_const irq_chip_no_const;
78290
78291 /*
78292 * irq_chip specific flags
78293diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
78294index cac496b..ffa0567 100644
78295--- a/include/linux/irqchip/arm-gic.h
78296+++ b/include/linux/irqchip/arm-gic.h
78297@@ -61,9 +61,11 @@
78298
78299 #ifndef __ASSEMBLY__
78300
78301+#include <linux/irq.h>
78302+
78303 struct device_node;
78304
78305-extern struct irq_chip gic_arch_extn;
78306+extern irq_chip_no_const gic_arch_extn;
78307
78308 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
78309 u32 offset, struct device_node *);
78310diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
78311index d235e88..8ccbe74 100644
78312--- a/include/linux/jiffies.h
78313+++ b/include/linux/jiffies.h
78314@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
78315 /*
78316 * Convert various time units to each other:
78317 */
78318-extern unsigned int jiffies_to_msecs(const unsigned long j);
78319-extern unsigned int jiffies_to_usecs(const unsigned long j);
78320-extern unsigned long msecs_to_jiffies(const unsigned int m);
78321-extern unsigned long usecs_to_jiffies(const unsigned int u);
78322-extern unsigned long timespec_to_jiffies(const struct timespec *value);
78323+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
78324+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
78325+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
78326+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
78327+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
78328 extern void jiffies_to_timespec(const unsigned long jiffies,
78329 struct timespec *value);
78330-extern unsigned long timeval_to_jiffies(const struct timeval *value);
78331+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
78332 extern void jiffies_to_timeval(const unsigned long jiffies,
78333 struct timeval *value);
78334
78335diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
78336index 6883e19..e854fcb 100644
78337--- a/include/linux/kallsyms.h
78338+++ b/include/linux/kallsyms.h
78339@@ -15,7 +15,8 @@
78340
78341 struct module;
78342
78343-#ifdef CONFIG_KALLSYMS
78344+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
78345+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
78346 /* Lookup the address for a symbol. Returns 0 if not found. */
78347 unsigned long kallsyms_lookup_name(const char *name);
78348
78349@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
78350 /* Stupid that this does nothing, but I didn't create this mess. */
78351 #define __print_symbol(fmt, addr)
78352 #endif /*CONFIG_KALLSYMS*/
78353+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
78354+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
78355+extern unsigned long kallsyms_lookup_name(const char *name);
78356+extern void __print_symbol(const char *fmt, unsigned long address);
78357+extern int sprint_backtrace(char *buffer, unsigned long address);
78358+extern int sprint_symbol(char *buffer, unsigned long address);
78359+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
78360+const char *kallsyms_lookup(unsigned long addr,
78361+ unsigned long *symbolsize,
78362+ unsigned long *offset,
78363+ char **modname, char *namebuf);
78364+extern int kallsyms_lookup_size_offset(unsigned long addr,
78365+ unsigned long *symbolsize,
78366+ unsigned long *offset);
78367+#endif
78368
78369 /* This macro allows us to keep printk typechecking */
78370 static __printf(1, 2)
78371diff --git a/include/linux/key-type.h b/include/linux/key-type.h
78372index a74c3a8..28d3f21 100644
78373--- a/include/linux/key-type.h
78374+++ b/include/linux/key-type.h
78375@@ -131,7 +131,7 @@ struct key_type {
78376 /* internal fields */
78377 struct list_head link; /* link in types list */
78378 struct lock_class_key lock_class; /* key->sem lock class */
78379-};
78380+} __do_const;
78381
78382 extern struct key_type key_type_keyring;
78383
78384diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
78385index dfb4f2f..7927e62 100644
78386--- a/include/linux/kgdb.h
78387+++ b/include/linux/kgdb.h
78388@@ -52,7 +52,7 @@ extern int kgdb_connected;
78389 extern int kgdb_io_module_registered;
78390
78391 extern atomic_t kgdb_setting_breakpoint;
78392-extern atomic_t kgdb_cpu_doing_single_step;
78393+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
78394
78395 extern struct task_struct *kgdb_usethread;
78396 extern struct task_struct *kgdb_contthread;
78397@@ -254,7 +254,7 @@ struct kgdb_arch {
78398 void (*correct_hw_break)(void);
78399
78400 void (*enable_nmi)(bool on);
78401-};
78402+} __do_const;
78403
78404 /**
78405 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
78406@@ -279,7 +279,7 @@ struct kgdb_io {
78407 void (*pre_exception) (void);
78408 void (*post_exception) (void);
78409 int is_console;
78410-};
78411+} __do_const;
78412
78413 extern struct kgdb_arch arch_kgdb_ops;
78414
78415diff --git a/include/linux/kmod.h b/include/linux/kmod.h
78416index 0555cc6..40116ce 100644
78417--- a/include/linux/kmod.h
78418+++ b/include/linux/kmod.h
78419@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
78420 * usually useless though. */
78421 extern __printf(2, 3)
78422 int __request_module(bool wait, const char *name, ...);
78423+extern __printf(3, 4)
78424+int ___request_module(bool wait, char *param_name, const char *name, ...);
78425 #define request_module(mod...) __request_module(true, mod)
78426 #define request_module_nowait(mod...) __request_module(false, mod)
78427 #define try_then_request_module(x, mod...) \
78428@@ -57,6 +59,9 @@ struct subprocess_info {
78429 struct work_struct work;
78430 struct completion *complete;
78431 char *path;
78432+#ifdef CONFIG_GRKERNSEC
78433+ char *origpath;
78434+#endif
78435 char **argv;
78436 char **envp;
78437 int wait;
78438diff --git a/include/linux/kobject.h b/include/linux/kobject.h
78439index e7ba650..0af3acb 100644
78440--- a/include/linux/kobject.h
78441+++ b/include/linux/kobject.h
78442@@ -116,7 +116,7 @@ struct kobj_type {
78443 struct attribute **default_attrs;
78444 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
78445 const void *(*namespace)(struct kobject *kobj);
78446-};
78447+} __do_const;
78448
78449 struct kobj_uevent_env {
78450 char *envp[UEVENT_NUM_ENVP];
78451@@ -139,6 +139,7 @@ struct kobj_attribute {
78452 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
78453 const char *buf, size_t count);
78454 };
78455+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
78456
78457 extern const struct sysfs_ops kobj_sysfs_ops;
78458
78459@@ -166,7 +167,7 @@ struct kset {
78460 spinlock_t list_lock;
78461 struct kobject kobj;
78462 const struct kset_uevent_ops *uevent_ops;
78463-};
78464+} __randomize_layout;
78465
78466 extern void kset_init(struct kset *kset);
78467 extern int __must_check kset_register(struct kset *kset);
78468diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
78469index df32d25..fb52e27 100644
78470--- a/include/linux/kobject_ns.h
78471+++ b/include/linux/kobject_ns.h
78472@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
78473 const void *(*netlink_ns)(struct sock *sk);
78474 const void *(*initial_ns)(void);
78475 void (*drop_ns)(void *);
78476-};
78477+} __do_const;
78478
78479 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
78480 int kobj_ns_type_registered(enum kobj_ns_type type);
78481diff --git a/include/linux/kref.h b/include/linux/kref.h
78482index 484604d..0f6c5b6 100644
78483--- a/include/linux/kref.h
78484+++ b/include/linux/kref.h
78485@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
78486 static inline int kref_sub(struct kref *kref, unsigned int count,
78487 void (*release)(struct kref *kref))
78488 {
78489- WARN_ON(release == NULL);
78490+ BUG_ON(release == NULL);
78491
78492 if (atomic_sub_and_test((int) count, &kref->refcount)) {
78493 release(kref);
78494diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
78495index 9523d2a..16c0424 100644
78496--- a/include/linux/kvm_host.h
78497+++ b/include/linux/kvm_host.h
78498@@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
78499 {
78500 }
78501 #endif
78502-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78503+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78504 struct module *module);
78505 void kvm_exit(void);
78506
78507@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
78508 struct kvm_guest_debug *dbg);
78509 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
78510
78511-int kvm_arch_init(void *opaque);
78512+int kvm_arch_init(const void *opaque);
78513 void kvm_arch_exit(void);
78514
78515 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
78516diff --git a/include/linux/libata.h b/include/linux/libata.h
78517index 9b50337..712d748 100644
78518--- a/include/linux/libata.h
78519+++ b/include/linux/libata.h
78520@@ -973,7 +973,7 @@ struct ata_port_operations {
78521 * fields must be pointers.
78522 */
78523 const struct ata_port_operations *inherits;
78524-};
78525+} __do_const;
78526
78527 struct ata_port_info {
78528 unsigned long flags;
78529diff --git a/include/linux/linkage.h b/include/linux/linkage.h
78530index d3e8ad2..a949f68 100644
78531--- a/include/linux/linkage.h
78532+++ b/include/linux/linkage.h
78533@@ -31,6 +31,7 @@
78534 #endif
78535
78536 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
78537+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
78538 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
78539
78540 /*
78541diff --git a/include/linux/list.h b/include/linux/list.h
78542index ef95941..82db65a 100644
78543--- a/include/linux/list.h
78544+++ b/include/linux/list.h
78545@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
78546 extern void list_del(struct list_head *entry);
78547 #endif
78548
78549+extern void __pax_list_add(struct list_head *new,
78550+ struct list_head *prev,
78551+ struct list_head *next);
78552+static inline void pax_list_add(struct list_head *new, struct list_head *head)
78553+{
78554+ __pax_list_add(new, head, head->next);
78555+}
78556+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
78557+{
78558+ __pax_list_add(new, head->prev, head);
78559+}
78560+extern void pax_list_del(struct list_head *entry);
78561+
78562 /**
78563 * list_replace - replace old entry by new one
78564 * @old : the element to be replaced
78565@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
78566 INIT_LIST_HEAD(entry);
78567 }
78568
78569+extern void pax_list_del_init(struct list_head *entry);
78570+
78571 /**
78572 * list_move - delete from one list and add as another's head
78573 * @list: the entry to move
78574diff --git a/include/linux/math64.h b/include/linux/math64.h
78575index c45c089..298841c 100644
78576--- a/include/linux/math64.h
78577+++ b/include/linux/math64.h
78578@@ -15,7 +15,7 @@
78579 * This is commonly provided by 32bit archs to provide an optimized 64bit
78580 * divide.
78581 */
78582-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78583+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78584 {
78585 *remainder = dividend % divisor;
78586 return dividend / divisor;
78587@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
78588 /**
78589 * div64_u64 - unsigned 64bit divide with 64bit divisor
78590 */
78591-static inline u64 div64_u64(u64 dividend, u64 divisor)
78592+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
78593 {
78594 return dividend / divisor;
78595 }
78596@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
78597 #define div64_ul(x, y) div_u64((x), (y))
78598
78599 #ifndef div_u64_rem
78600-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78601+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78602 {
78603 *remainder = do_div(dividend, divisor);
78604 return dividend;
78605@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
78606 #endif
78607
78608 #ifndef div64_u64
78609-extern u64 div64_u64(u64 dividend, u64 divisor);
78610+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
78611 #endif
78612
78613 #ifndef div64_s64
78614@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
78615 * divide.
78616 */
78617 #ifndef div_u64
78618-static inline u64 div_u64(u64 dividend, u32 divisor)
78619+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
78620 {
78621 u32 remainder;
78622 return div_u64_rem(dividend, divisor, &remainder);
78623diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
78624index 9fe426b..8148be6 100644
78625--- a/include/linux/mempolicy.h
78626+++ b/include/linux/mempolicy.h
78627@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
78628 }
78629
78630 #define vma_policy(vma) ((vma)->vm_policy)
78631+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78632+{
78633+ vma->vm_policy = pol;
78634+}
78635
78636 static inline void mpol_get(struct mempolicy *pol)
78637 {
78638@@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
78639 }
78640
78641 #define vma_policy(vma) NULL
78642+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78643+{
78644+}
78645
78646 static inline int
78647 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
78648diff --git a/include/linux/mm.h b/include/linux/mm.h
78649index 3552717..658aae0 100644
78650--- a/include/linux/mm.h
78651+++ b/include/linux/mm.h
78652@@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
78653 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
78654 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
78655 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
78656+
78657+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
78658+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
78659+#endif
78660+
78661 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
78662
78663 #ifdef CONFIG_MEM_SOFT_DIRTY
78664@@ -219,8 +224,8 @@ struct vm_operations_struct {
78665 /* called by access_process_vm when get_user_pages() fails, typically
78666 * for use by special VMAs that can switch between memory and hardware
78667 */
78668- int (*access)(struct vm_area_struct *vma, unsigned long addr,
78669- void *buf, int len, int write);
78670+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
78671+ void *buf, size_t len, int write);
78672 #ifdef CONFIG_NUMA
78673 /*
78674 * set_policy() op must add a reference to any non-NULL @new mempolicy
78675@@ -250,6 +255,7 @@ struct vm_operations_struct {
78676 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
78677 unsigned long size, pgoff_t pgoff);
78678 };
78679+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
78680
78681 struct mmu_gather;
78682 struct inode;
78683@@ -1061,8 +1067,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
78684 unsigned long *pfn);
78685 int follow_phys(struct vm_area_struct *vma, unsigned long address,
78686 unsigned int flags, unsigned long *prot, resource_size_t *phys);
78687-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78688- void *buf, int len, int write);
78689+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78690+ void *buf, size_t len, int write);
78691
78692 static inline void unmap_shared_mapping_range(struct address_space *mapping,
78693 loff_t const holebegin, loff_t const holelen)
78694@@ -1101,9 +1107,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
78695 }
78696 #endif
78697
78698-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
78699-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
78700- void *buf, int len, int write);
78701+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
78702+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
78703+ void *buf, size_t len, int write);
78704
78705 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
78706 unsigned long start, unsigned long nr_pages,
78707@@ -1135,34 +1141,6 @@ int set_page_dirty(struct page *page);
78708 int set_page_dirty_lock(struct page *page);
78709 int clear_page_dirty_for_io(struct page *page);
78710
78711-/* Is the vma a continuation of the stack vma above it? */
78712-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
78713-{
78714- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
78715-}
78716-
78717-static inline int stack_guard_page_start(struct vm_area_struct *vma,
78718- unsigned long addr)
78719-{
78720- return (vma->vm_flags & VM_GROWSDOWN) &&
78721- (vma->vm_start == addr) &&
78722- !vma_growsdown(vma->vm_prev, addr);
78723-}
78724-
78725-/* Is the vma a continuation of the stack vma below it? */
78726-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
78727-{
78728- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
78729-}
78730-
78731-static inline int stack_guard_page_end(struct vm_area_struct *vma,
78732- unsigned long addr)
78733-{
78734- return (vma->vm_flags & VM_GROWSUP) &&
78735- (vma->vm_end == addr) &&
78736- !vma_growsup(vma->vm_next, addr);
78737-}
78738-
78739 extern pid_t
78740 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
78741
78742@@ -1262,6 +1240,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
78743 }
78744 #endif
78745
78746+#ifdef CONFIG_MMU
78747+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
78748+#else
78749+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
78750+{
78751+ return __pgprot(0);
78752+}
78753+#endif
78754+
78755 int vma_wants_writenotify(struct vm_area_struct *vma);
78756
78757 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
78758@@ -1280,8 +1267,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
78759 {
78760 return 0;
78761 }
78762+
78763+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
78764+ unsigned long address)
78765+{
78766+ return 0;
78767+}
78768 #else
78769 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78770+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78771 #endif
78772
78773 #ifdef __PAGETABLE_PMD_FOLDED
78774@@ -1290,8 +1284,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
78775 {
78776 return 0;
78777 }
78778+
78779+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
78780+ unsigned long address)
78781+{
78782+ return 0;
78783+}
78784 #else
78785 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
78786+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
78787 #endif
78788
78789 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
78790@@ -1309,11 +1310,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
78791 NULL: pud_offset(pgd, address);
78792 }
78793
78794+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
78795+{
78796+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
78797+ NULL: pud_offset(pgd, address);
78798+}
78799+
78800 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
78801 {
78802 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
78803 NULL: pmd_offset(pud, address);
78804 }
78805+
78806+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
78807+{
78808+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
78809+ NULL: pmd_offset(pud, address);
78810+}
78811 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
78812
78813 #if USE_SPLIT_PTE_PTLOCKS
78814@@ -1691,7 +1704,7 @@ extern int install_special_mapping(struct mm_struct *mm,
78815 unsigned long addr, unsigned long len,
78816 unsigned long flags, struct page **pages);
78817
78818-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
78819+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
78820
78821 extern unsigned long mmap_region(struct file *file, unsigned long addr,
78822 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
78823@@ -1699,6 +1712,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
78824 unsigned long len, unsigned long prot, unsigned long flags,
78825 unsigned long pgoff, unsigned long *populate);
78826 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
78827+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
78828
78829 #ifdef CONFIG_MMU
78830 extern int __mm_populate(unsigned long addr, unsigned long len,
78831@@ -1727,10 +1741,11 @@ struct vm_unmapped_area_info {
78832 unsigned long high_limit;
78833 unsigned long align_mask;
78834 unsigned long align_offset;
78835+ unsigned long threadstack_offset;
78836 };
78837
78838-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
78839-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
78840+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
78841+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
78842
78843 /*
78844 * Search for an unmapped address range.
78845@@ -1742,7 +1757,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
78846 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
78847 */
78848 static inline unsigned long
78849-vm_unmapped_area(struct vm_unmapped_area_info *info)
78850+vm_unmapped_area(const struct vm_unmapped_area_info *info)
78851 {
78852 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
78853 return unmapped_area(info);
78854@@ -1805,6 +1820,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
78855 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
78856 struct vm_area_struct **pprev);
78857
78858+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
78859+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
78860+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
78861+
78862 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
78863 NULL if none. Assume start_addr < end_addr. */
78864 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
78865@@ -1833,15 +1852,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
78866 return vma;
78867 }
78868
78869-#ifdef CONFIG_MMU
78870-pgprot_t vm_get_page_prot(unsigned long vm_flags);
78871-#else
78872-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
78873-{
78874- return __pgprot(0);
78875-}
78876-#endif
78877-
78878 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
78879 unsigned long change_prot_numa(struct vm_area_struct *vma,
78880 unsigned long start, unsigned long end);
78881@@ -1893,6 +1903,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
78882 static inline void vm_stat_account(struct mm_struct *mm,
78883 unsigned long flags, struct file *file, long pages)
78884 {
78885+
78886+#ifdef CONFIG_PAX_RANDMMAP
78887+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
78888+#endif
78889+
78890 mm->total_vm += pages;
78891 }
78892 #endif /* CONFIG_PROC_FS */
78893@@ -1974,7 +1989,7 @@ extern int unpoison_memory(unsigned long pfn);
78894 extern int sysctl_memory_failure_early_kill;
78895 extern int sysctl_memory_failure_recovery;
78896 extern void shake_page(struct page *p, int access);
78897-extern atomic_long_t num_poisoned_pages;
78898+extern atomic_long_unchecked_t num_poisoned_pages;
78899 extern int soft_offline_page(struct page *page, int flags);
78900
78901 extern void dump_page(struct page *page);
78902@@ -2011,5 +2026,11 @@ void __init setup_nr_node_ids(void);
78903 static inline void setup_nr_node_ids(void) {}
78904 #endif
78905
78906+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78907+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
78908+#else
78909+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
78910+#endif
78911+
78912 #endif /* __KERNEL__ */
78913 #endif /* _LINUX_MM_H */
78914diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
78915index 290901a..e99b01c 100644
78916--- a/include/linux/mm_types.h
78917+++ b/include/linux/mm_types.h
78918@@ -307,7 +307,9 @@ struct vm_area_struct {
78919 #ifdef CONFIG_NUMA
78920 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
78921 #endif
78922-};
78923+
78924+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
78925+} __randomize_layout;
78926
78927 struct core_thread {
78928 struct task_struct *task;
78929@@ -453,7 +455,25 @@ struct mm_struct {
78930 bool tlb_flush_pending;
78931 #endif
78932 struct uprobes_state uprobes_state;
78933-};
78934+
78935+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
78936+ unsigned long pax_flags;
78937+#endif
78938+
78939+#ifdef CONFIG_PAX_DLRESOLVE
78940+ unsigned long call_dl_resolve;
78941+#endif
78942+
78943+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
78944+ unsigned long call_syscall;
78945+#endif
78946+
78947+#ifdef CONFIG_PAX_ASLR
78948+ unsigned long delta_mmap; /* randomized offset */
78949+ unsigned long delta_stack; /* randomized offset */
78950+#endif
78951+
78952+} __randomize_layout;
78953
78954 static inline void mm_init_cpumask(struct mm_struct *mm)
78955 {
78956diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
78957index c5d5278..f0b68c8 100644
78958--- a/include/linux/mmiotrace.h
78959+++ b/include/linux/mmiotrace.h
78960@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
78961 /* Called from ioremap.c */
78962 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
78963 void __iomem *addr);
78964-extern void mmiotrace_iounmap(volatile void __iomem *addr);
78965+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
78966
78967 /* For anyone to insert markers. Remember trailing newline. */
78968 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
78969@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
78970 {
78971 }
78972
78973-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
78974+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
78975 {
78976 }
78977
78978diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
78979index bd791e4..8617c34f 100644
78980--- a/include/linux/mmzone.h
78981+++ b/include/linux/mmzone.h
78982@@ -396,7 +396,7 @@ struct zone {
78983 unsigned long flags; /* zone flags, see below */
78984
78985 /* Zone statistics */
78986- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78987+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78988
78989 /*
78990 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
78991diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
78992index 45e9214..a7227d6 100644
78993--- a/include/linux/mod_devicetable.h
78994+++ b/include/linux/mod_devicetable.h
78995@@ -13,7 +13,7 @@
78996 typedef unsigned long kernel_ulong_t;
78997 #endif
78998
78999-#define PCI_ANY_ID (~0)
79000+#define PCI_ANY_ID ((__u16)~0)
79001
79002 struct pci_device_id {
79003 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
79004@@ -139,7 +139,7 @@ struct usb_device_id {
79005 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
79006 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
79007
79008-#define HID_ANY_ID (~0)
79009+#define HID_ANY_ID (~0U)
79010 #define HID_BUS_ANY 0xffff
79011 #define HID_GROUP_ANY 0x0000
79012
79013@@ -467,7 +467,7 @@ struct dmi_system_id {
79014 const char *ident;
79015 struct dmi_strmatch matches[4];
79016 void *driver_data;
79017-};
79018+} __do_const;
79019 /*
79020 * struct dmi_device_id appears during expansion of
79021 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
79022diff --git a/include/linux/module.h b/include/linux/module.h
79023index 15cd6b1..f6e2e6a 100644
79024--- a/include/linux/module.h
79025+++ b/include/linux/module.h
79026@@ -17,9 +17,11 @@
79027 #include <linux/moduleparam.h>
79028 #include <linux/tracepoint.h>
79029 #include <linux/export.h>
79030+#include <linux/fs.h>
79031
79032 #include <linux/percpu.h>
79033 #include <asm/module.h>
79034+#include <asm/pgtable.h>
79035
79036 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
79037 #define MODULE_SIG_STRING "~Module signature appended~\n"
79038@@ -43,7 +45,7 @@ struct module_kobject {
79039 struct kobject *drivers_dir;
79040 struct module_param_attrs *mp;
79041 struct completion *kobj_completion;
79042-};
79043+} __randomize_layout;
79044
79045 struct module_attribute {
79046 struct attribute attr;
79047@@ -55,12 +57,13 @@ struct module_attribute {
79048 int (*test)(struct module *);
79049 void (*free)(struct module *);
79050 };
79051+typedef struct module_attribute __no_const module_attribute_no_const;
79052
79053 struct module_version_attribute {
79054 struct module_attribute mattr;
79055 const char *module_name;
79056 const char *version;
79057-} __attribute__ ((__aligned__(sizeof(void *))));
79058+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
79059
79060 extern ssize_t __modver_version_show(struct module_attribute *,
79061 struct module_kobject *, char *);
79062@@ -238,7 +241,7 @@ struct module
79063
79064 /* Sysfs stuff. */
79065 struct module_kobject mkobj;
79066- struct module_attribute *modinfo_attrs;
79067+ module_attribute_no_const *modinfo_attrs;
79068 const char *version;
79069 const char *srcversion;
79070 struct kobject *holders_dir;
79071@@ -287,19 +290,16 @@ struct module
79072 int (*init)(void);
79073
79074 /* If this is non-NULL, vfree after init() returns */
79075- void *module_init;
79076+ void *module_init_rx, *module_init_rw;
79077
79078 /* Here is the actual code + data, vfree'd on unload. */
79079- void *module_core;
79080+ void *module_core_rx, *module_core_rw;
79081
79082 /* Here are the sizes of the init and core sections */
79083- unsigned int init_size, core_size;
79084+ unsigned int init_size_rw, core_size_rw;
79085
79086 /* The size of the executable code in each section. */
79087- unsigned int init_text_size, core_text_size;
79088-
79089- /* Size of RO sections of the module (text+rodata) */
79090- unsigned int init_ro_size, core_ro_size;
79091+ unsigned int init_size_rx, core_size_rx;
79092
79093 /* Arch-specific module values */
79094 struct mod_arch_specific arch;
79095@@ -355,6 +355,10 @@ struct module
79096 #ifdef CONFIG_EVENT_TRACING
79097 struct ftrace_event_call **trace_events;
79098 unsigned int num_trace_events;
79099+ struct file_operations trace_id;
79100+ struct file_operations trace_enable;
79101+ struct file_operations trace_format;
79102+ struct file_operations trace_filter;
79103 #endif
79104 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
79105 unsigned int num_ftrace_callsites;
79106@@ -378,7 +382,7 @@ struct module
79107 ctor_fn_t *ctors;
79108 unsigned int num_ctors;
79109 #endif
79110-};
79111+} __randomize_layout;
79112 #ifndef MODULE_ARCH_INIT
79113 #define MODULE_ARCH_INIT {}
79114 #endif
79115@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
79116 bool is_module_percpu_address(unsigned long addr);
79117 bool is_module_text_address(unsigned long addr);
79118
79119+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
79120+{
79121+
79122+#ifdef CONFIG_PAX_KERNEXEC
79123+ if (ktla_ktva(addr) >= (unsigned long)start &&
79124+ ktla_ktva(addr) < (unsigned long)start + size)
79125+ return 1;
79126+#endif
79127+
79128+ return ((void *)addr >= start && (void *)addr < start + size);
79129+}
79130+
79131+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
79132+{
79133+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
79134+}
79135+
79136+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
79137+{
79138+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
79139+}
79140+
79141+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
79142+{
79143+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
79144+}
79145+
79146+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
79147+{
79148+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
79149+}
79150+
79151 static inline int within_module_core(unsigned long addr, const struct module *mod)
79152 {
79153- return (unsigned long)mod->module_core <= addr &&
79154- addr < (unsigned long)mod->module_core + mod->core_size;
79155+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
79156 }
79157
79158 static inline int within_module_init(unsigned long addr, const struct module *mod)
79159 {
79160- return (unsigned long)mod->module_init <= addr &&
79161- addr < (unsigned long)mod->module_init + mod->init_size;
79162+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
79163 }
79164
79165 /* Search for module by name: must hold module_mutex. */
79166diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
79167index 560ca53..ef621ef 100644
79168--- a/include/linux/moduleloader.h
79169+++ b/include/linux/moduleloader.h
79170@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
79171 sections. Returns NULL on failure. */
79172 void *module_alloc(unsigned long size);
79173
79174+#ifdef CONFIG_PAX_KERNEXEC
79175+void *module_alloc_exec(unsigned long size);
79176+#else
79177+#define module_alloc_exec(x) module_alloc(x)
79178+#endif
79179+
79180 /* Free memory returned from module_alloc. */
79181 void module_free(struct module *mod, void *module_region);
79182
79183+#ifdef CONFIG_PAX_KERNEXEC
79184+void module_free_exec(struct module *mod, void *module_region);
79185+#else
79186+#define module_free_exec(x, y) module_free((x), (y))
79187+#endif
79188+
79189 /*
79190 * Apply the given relocation to the (simplified) ELF. Return -error
79191 * or 0.
79192@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
79193 unsigned int relsec,
79194 struct module *me)
79195 {
79196+#ifdef CONFIG_MODULES
79197 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79198+#endif
79199 return -ENOEXEC;
79200 }
79201 #endif
79202@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
79203 unsigned int relsec,
79204 struct module *me)
79205 {
79206+#ifdef CONFIG_MODULES
79207 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79208+#endif
79209 return -ENOEXEC;
79210 }
79211 #endif
79212diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
79213index c3eb102..073c4a6 100644
79214--- a/include/linux/moduleparam.h
79215+++ b/include/linux/moduleparam.h
79216@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
79217 * @len is usually just sizeof(string).
79218 */
79219 #define module_param_string(name, string, len, perm) \
79220- static const struct kparam_string __param_string_##name \
79221+ static const struct kparam_string __param_string_##name __used \
79222 = { len, string }; \
79223 __module_param_call(MODULE_PARAM_PREFIX, name, \
79224 &param_ops_string, \
79225@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
79226 */
79227 #define module_param_array_named(name, array, type, nump, perm) \
79228 param_check_##type(name, &(array)[0]); \
79229- static const struct kparam_array __param_arr_##name \
79230+ static const struct kparam_array __param_arr_##name __used \
79231 = { .max = ARRAY_SIZE(array), .num = nump, \
79232 .ops = &param_ops_##type, \
79233 .elemsize = sizeof(array[0]), .elem = array }; \
79234diff --git a/include/linux/mount.h b/include/linux/mount.h
79235index 371d346..fba2819 100644
79236--- a/include/linux/mount.h
79237+++ b/include/linux/mount.h
79238@@ -56,7 +56,7 @@ struct vfsmount {
79239 struct dentry *mnt_root; /* root of the mounted tree */
79240 struct super_block *mnt_sb; /* pointer to superblock */
79241 int mnt_flags;
79242-};
79243+} __randomize_layout;
79244
79245 struct file; /* forward dec */
79246
79247diff --git a/include/linux/namei.h b/include/linux/namei.h
79248index 492de72..1bddcd4 100644
79249--- a/include/linux/namei.h
79250+++ b/include/linux/namei.h
79251@@ -19,7 +19,7 @@ struct nameidata {
79252 unsigned seq, m_seq;
79253 int last_type;
79254 unsigned depth;
79255- char *saved_names[MAX_NESTED_LINKS + 1];
79256+ const char *saved_names[MAX_NESTED_LINKS + 1];
79257 };
79258
79259 /*
79260@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
79261
79262 extern void nd_jump_link(struct nameidata *nd, struct path *path);
79263
79264-static inline void nd_set_link(struct nameidata *nd, char *path)
79265+static inline void nd_set_link(struct nameidata *nd, const char *path)
79266 {
79267 nd->saved_names[nd->depth] = path;
79268 }
79269
79270-static inline char *nd_get_link(struct nameidata *nd)
79271+static inline const char *nd_get_link(const struct nameidata *nd)
79272 {
79273 return nd->saved_names[nd->depth];
79274 }
79275diff --git a/include/linux/net.h b/include/linux/net.h
79276index 69be3e6..0fb422d 100644
79277--- a/include/linux/net.h
79278+++ b/include/linux/net.h
79279@@ -192,7 +192,7 @@ struct net_proto_family {
79280 int (*create)(struct net *net, struct socket *sock,
79281 int protocol, int kern);
79282 struct module *owner;
79283-};
79284+} __do_const;
79285
79286 struct iovec;
79287 struct kvec;
79288diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
79289index ce2a1f5..cb9bc8c 100644
79290--- a/include/linux/netdevice.h
79291+++ b/include/linux/netdevice.h
79292@@ -1129,6 +1129,7 @@ struct net_device_ops {
79293 struct net_device *dev,
79294 void *priv);
79295 };
79296+typedef struct net_device_ops __no_const net_device_ops_no_const;
79297
79298 /*
79299 * The DEVICE structure.
79300@@ -1211,7 +1212,7 @@ struct net_device {
79301 int iflink;
79302
79303 struct net_device_stats stats;
79304- atomic_long_t rx_dropped; /* dropped packets by core network
79305+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
79306 * Do not use this in drivers.
79307 */
79308
79309diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
79310index 2077489..a15e561 100644
79311--- a/include/linux/netfilter.h
79312+++ b/include/linux/netfilter.h
79313@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
79314 #endif
79315 /* Use the module struct to lock set/get code in place */
79316 struct module *owner;
79317-};
79318+} __do_const;
79319
79320 /* Function to register/unregister hook points. */
79321 int nf_register_hook(struct nf_hook_ops *reg);
79322diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
79323index 28c7436..2d6156a 100644
79324--- a/include/linux/netfilter/nfnetlink.h
79325+++ b/include/linux/netfilter/nfnetlink.h
79326@@ -19,7 +19,7 @@ struct nfnl_callback {
79327 const struct nlattr * const cda[]);
79328 const struct nla_policy *policy; /* netlink attribute policy */
79329 const u_int16_t attr_count; /* number of nlattr's */
79330-};
79331+} __do_const;
79332
79333 struct nfnetlink_subsystem {
79334 const char *name;
79335diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
79336new file mode 100644
79337index 0000000..33f4af8
79338--- /dev/null
79339+++ b/include/linux/netfilter/xt_gradm.h
79340@@ -0,0 +1,9 @@
79341+#ifndef _LINUX_NETFILTER_XT_GRADM_H
79342+#define _LINUX_NETFILTER_XT_GRADM_H 1
79343+
79344+struct xt_gradm_mtinfo {
79345+ __u16 flags;
79346+ __u16 invflags;
79347+};
79348+
79349+#endif
79350diff --git a/include/linux/nls.h b/include/linux/nls.h
79351index 5dc635f..35f5e11 100644
79352--- a/include/linux/nls.h
79353+++ b/include/linux/nls.h
79354@@ -31,7 +31,7 @@ struct nls_table {
79355 const unsigned char *charset2upper;
79356 struct module *owner;
79357 struct nls_table *next;
79358-};
79359+} __do_const;
79360
79361 /* this value hold the maximum octet of charset */
79362 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
79363diff --git a/include/linux/notifier.h b/include/linux/notifier.h
79364index d14a4c3..a078786 100644
79365--- a/include/linux/notifier.h
79366+++ b/include/linux/notifier.h
79367@@ -54,7 +54,8 @@ struct notifier_block {
79368 notifier_fn_t notifier_call;
79369 struct notifier_block __rcu *next;
79370 int priority;
79371-};
79372+} __do_const;
79373+typedef struct notifier_block __no_const notifier_block_no_const;
79374
79375 struct atomic_notifier_head {
79376 spinlock_t lock;
79377diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
79378index b2a0f15..4d7da32 100644
79379--- a/include/linux/oprofile.h
79380+++ b/include/linux/oprofile.h
79381@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
79382 int oprofilefs_create_ro_ulong(struct dentry * root,
79383 char const * name, ulong * val);
79384
79385-/** Create a file for read-only access to an atomic_t. */
79386+/** Create a file for read-only access to an atomic_unchecked_t. */
79387 int oprofilefs_create_ro_atomic(struct dentry * root,
79388- char const * name, atomic_t * val);
79389+ char const * name, atomic_unchecked_t * val);
79390
79391 /** create a directory */
79392 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
79393diff --git a/include/linux/padata.h b/include/linux/padata.h
79394index 4386946..f50c615 100644
79395--- a/include/linux/padata.h
79396+++ b/include/linux/padata.h
79397@@ -129,7 +129,7 @@ struct parallel_data {
79398 struct padata_serial_queue __percpu *squeue;
79399 atomic_t reorder_objects;
79400 atomic_t refcnt;
79401- atomic_t seq_nr;
79402+ atomic_unchecked_t seq_nr;
79403 struct padata_cpumask cpumask;
79404 spinlock_t lock ____cacheline_aligned;
79405 unsigned int processed;
79406diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
79407index a2e2f1d..8a391d2 100644
79408--- a/include/linux/pci_hotplug.h
79409+++ b/include/linux/pci_hotplug.h
79410@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
79411 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
79412 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
79413 int (*reset_slot) (struct hotplug_slot *slot, int probe);
79414-};
79415+} __do_const;
79416+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
79417
79418 /**
79419 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
79420diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
79421index 2e069d1..27054b8 100644
79422--- a/include/linux/perf_event.h
79423+++ b/include/linux/perf_event.h
79424@@ -327,8 +327,8 @@ struct perf_event {
79425
79426 enum perf_event_active_state state;
79427 unsigned int attach_state;
79428- local64_t count;
79429- atomic64_t child_count;
79430+ local64_t count; /* PaX: fix it one day */
79431+ atomic64_unchecked_t child_count;
79432
79433 /*
79434 * These are the total time in nanoseconds that the event
79435@@ -379,8 +379,8 @@ struct perf_event {
79436 * These accumulate total time (in nanoseconds) that children
79437 * events have been enabled and running, respectively.
79438 */
79439- atomic64_t child_total_time_enabled;
79440- atomic64_t child_total_time_running;
79441+ atomic64_unchecked_t child_total_time_enabled;
79442+ atomic64_unchecked_t child_total_time_running;
79443
79444 /*
79445 * Protect attach/detach and child_list:
79446@@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
79447 entry->ip[entry->nr++] = ip;
79448 }
79449
79450-extern int sysctl_perf_event_paranoid;
79451+extern int sysctl_perf_event_legitimately_concerned;
79452 extern int sysctl_perf_event_mlock;
79453 extern int sysctl_perf_event_sample_rate;
79454 extern int sysctl_perf_cpu_time_max_percent;
79455@@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
79456 loff_t *ppos);
79457
79458
79459+static inline bool perf_paranoid_any(void)
79460+{
79461+ return sysctl_perf_event_legitimately_concerned > 2;
79462+}
79463+
79464 static inline bool perf_paranoid_tracepoint_raw(void)
79465 {
79466- return sysctl_perf_event_paranoid > -1;
79467+ return sysctl_perf_event_legitimately_concerned > -1;
79468 }
79469
79470 static inline bool perf_paranoid_cpu(void)
79471 {
79472- return sysctl_perf_event_paranoid > 0;
79473+ return sysctl_perf_event_legitimately_concerned > 0;
79474 }
79475
79476 static inline bool perf_paranoid_kernel(void)
79477 {
79478- return sysctl_perf_event_paranoid > 1;
79479+ return sysctl_perf_event_legitimately_concerned > 1;
79480 }
79481
79482 extern void perf_event_init(void);
79483@@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
79484 struct device_attribute attr;
79485 u64 id;
79486 const char *event_str;
79487-};
79488+} __do_const;
79489
79490 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
79491 static struct perf_pmu_events_attr _var = { \
79492diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
79493index 7246ef3..1539ea4 100644
79494--- a/include/linux/pid_namespace.h
79495+++ b/include/linux/pid_namespace.h
79496@@ -43,7 +43,7 @@ struct pid_namespace {
79497 int hide_pid;
79498 int reboot; /* group exit code if this pidns was rebooted */
79499 unsigned int proc_inum;
79500-};
79501+} __randomize_layout;
79502
79503 extern struct pid_namespace init_pid_ns;
79504
79505diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
79506index b8809fe..ae4ccd0 100644
79507--- a/include/linux/pipe_fs_i.h
79508+++ b/include/linux/pipe_fs_i.h
79509@@ -47,10 +47,10 @@ struct pipe_inode_info {
79510 struct mutex mutex;
79511 wait_queue_head_t wait;
79512 unsigned int nrbufs, curbuf, buffers;
79513- unsigned int readers;
79514- unsigned int writers;
79515- unsigned int files;
79516- unsigned int waiting_writers;
79517+ atomic_t readers;
79518+ atomic_t writers;
79519+ atomic_t files;
79520+ atomic_t waiting_writers;
79521 unsigned int r_counter;
79522 unsigned int w_counter;
79523 struct page *tmp_page;
79524diff --git a/include/linux/pm.h b/include/linux/pm.h
79525index a224c7f..92d8a97 100644
79526--- a/include/linux/pm.h
79527+++ b/include/linux/pm.h
79528@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
79529 struct dev_pm_domain {
79530 struct dev_pm_ops ops;
79531 };
79532+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
79533
79534 /*
79535 * The PM_EVENT_ messages are also used by drivers implementing the legacy
79536diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
79537index 7c1d252..c5c773e 100644
79538--- a/include/linux/pm_domain.h
79539+++ b/include/linux/pm_domain.h
79540@@ -48,7 +48,7 @@ struct gpd_dev_ops {
79541
79542 struct gpd_cpu_data {
79543 unsigned int saved_exit_latency;
79544- struct cpuidle_state *idle_state;
79545+ cpuidle_state_no_const *idle_state;
79546 };
79547
79548 struct generic_pm_domain {
79549diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
79550index 6fa7cea..7bf6415 100644
79551--- a/include/linux/pm_runtime.h
79552+++ b/include/linux/pm_runtime.h
79553@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
79554
79555 static inline void pm_runtime_mark_last_busy(struct device *dev)
79556 {
79557- ACCESS_ONCE(dev->power.last_busy) = jiffies;
79558+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
79559 }
79560
79561 #else /* !CONFIG_PM_RUNTIME */
79562diff --git a/include/linux/pnp.h b/include/linux/pnp.h
79563index 195aafc..49a7bc2 100644
79564--- a/include/linux/pnp.h
79565+++ b/include/linux/pnp.h
79566@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
79567 struct pnp_fixup {
79568 char id[7];
79569 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
79570-};
79571+} __do_const;
79572
79573 /* config parameters */
79574 #define PNP_CONFIG_NORMAL 0x0001
79575diff --git a/include/linux/poison.h b/include/linux/poison.h
79576index 2110a81..13a11bb 100644
79577--- a/include/linux/poison.h
79578+++ b/include/linux/poison.h
79579@@ -19,8 +19,8 @@
79580 * under normal circumstances, used to verify that nobody uses
79581 * non-initialized list entries.
79582 */
79583-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
79584-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
79585+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
79586+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
79587
79588 /********** include/linux/timer.h **********/
79589 /*
79590diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
79591index d8b187c3..9a9257a 100644
79592--- a/include/linux/power/smartreflex.h
79593+++ b/include/linux/power/smartreflex.h
79594@@ -238,7 +238,7 @@ struct omap_sr_class_data {
79595 int (*notify)(struct omap_sr *sr, u32 status);
79596 u8 notify_flags;
79597 u8 class_type;
79598-};
79599+} __do_const;
79600
79601 /**
79602 * struct omap_sr_nvalue_table - Smartreflex n-target value info
79603diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
79604index 4ea1d37..80f4b33 100644
79605--- a/include/linux/ppp-comp.h
79606+++ b/include/linux/ppp-comp.h
79607@@ -84,7 +84,7 @@ struct compressor {
79608 struct module *owner;
79609 /* Extra skb space needed by the compressor algorithm */
79610 unsigned int comp_extra;
79611-};
79612+} __do_const;
79613
79614 /*
79615 * The return value from decompress routine is the length of the
79616diff --git a/include/linux/preempt.h b/include/linux/preempt.h
79617index a3d9dc8..8af9922 100644
79618--- a/include/linux/preempt.h
79619+++ b/include/linux/preempt.h
79620@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
79621 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
79622 #endif
79623
79624+#define raw_preempt_count_add(val) __preempt_count_add(val)
79625+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
79626+
79627 #define __preempt_count_inc() __preempt_count_add(1)
79628 #define __preempt_count_dec() __preempt_count_sub(1)
79629
79630 #define preempt_count_inc() preempt_count_add(1)
79631+#define raw_preempt_count_inc() raw_preempt_count_add(1)
79632 #define preempt_count_dec() preempt_count_sub(1)
79633+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
79634
79635 #ifdef CONFIG_PREEMPT_COUNT
79636
79637@@ -41,6 +46,12 @@ do { \
79638 barrier(); \
79639 } while (0)
79640
79641+#define raw_preempt_disable() \
79642+do { \
79643+ raw_preempt_count_inc(); \
79644+ barrier(); \
79645+} while (0)
79646+
79647 #define sched_preempt_enable_no_resched() \
79648 do { \
79649 barrier(); \
79650@@ -49,6 +60,12 @@ do { \
79651
79652 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
79653
79654+#define raw_preempt_enable_no_resched() \
79655+do { \
79656+ barrier(); \
79657+ raw_preempt_count_dec(); \
79658+} while (0)
79659+
79660 #ifdef CONFIG_PREEMPT
79661 #define preempt_enable() \
79662 do { \
79663@@ -105,8 +122,10 @@ do { \
79664 * region.
79665 */
79666 #define preempt_disable() barrier()
79667+#define raw_preempt_disable() barrier()
79668 #define sched_preempt_enable_no_resched() barrier()
79669 #define preempt_enable_no_resched() barrier()
79670+#define raw_preempt_enable_no_resched() barrier()
79671 #define preempt_enable() barrier()
79672 #define preempt_check_resched() do { } while (0)
79673
79674diff --git a/include/linux/printk.h b/include/linux/printk.h
79675index 6949258..7c4730e 100644
79676--- a/include/linux/printk.h
79677+++ b/include/linux/printk.h
79678@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
79679 void early_printk(const char *s, ...) { }
79680 #endif
79681
79682+extern int kptr_restrict;
79683+
79684 #ifdef CONFIG_PRINTK
79685 asmlinkage __printf(5, 0)
79686 int vprintk_emit(int facility, int level,
79687@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
79688
79689 extern int printk_delay_msec;
79690 extern int dmesg_restrict;
79691-extern int kptr_restrict;
79692
79693 extern void wake_up_klogd(void);
79694
79695diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
79696index 608e60a..c26f864 100644
79697--- a/include/linux/proc_fs.h
79698+++ b/include/linux/proc_fs.h
79699@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
79700 return proc_create_data(name, mode, parent, proc_fops, NULL);
79701 }
79702
79703+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
79704+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
79705+{
79706+#ifdef CONFIG_GRKERNSEC_PROC_USER
79707+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
79708+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79709+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
79710+#else
79711+ return proc_create_data(name, mode, parent, proc_fops, NULL);
79712+#endif
79713+}
79714+
79715+
79716 extern void proc_set_size(struct proc_dir_entry *, loff_t);
79717 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
79718 extern void *PDE_DATA(const struct inode *);
79719diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
79720index 34a1e10..70f6bde 100644
79721--- a/include/linux/proc_ns.h
79722+++ b/include/linux/proc_ns.h
79723@@ -14,7 +14,7 @@ struct proc_ns_operations {
79724 void (*put)(void *ns);
79725 int (*install)(struct nsproxy *nsproxy, void *ns);
79726 unsigned int (*inum)(void *ns);
79727-};
79728+} __do_const __randomize_layout;
79729
79730 struct proc_ns {
79731 void *ns;
79732diff --git a/include/linux/quota.h b/include/linux/quota.h
79733index cc7494a..1e27036 100644
79734--- a/include/linux/quota.h
79735+++ b/include/linux/quota.h
79736@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
79737
79738 extern bool qid_eq(struct kqid left, struct kqid right);
79739 extern bool qid_lt(struct kqid left, struct kqid right);
79740-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
79741+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
79742 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
79743 extern bool qid_valid(struct kqid qid);
79744
79745diff --git a/include/linux/random.h b/include/linux/random.h
79746index 4002b3d..d5ad855 100644
79747--- a/include/linux/random.h
79748+++ b/include/linux/random.h
79749@@ -10,9 +10,19 @@
79750
79751
79752 extern void add_device_randomness(const void *, unsigned int);
79753+
79754+static inline void add_latent_entropy(void)
79755+{
79756+
79757+#ifdef LATENT_ENTROPY_PLUGIN
79758+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
79759+#endif
79760+
79761+}
79762+
79763 extern void add_input_randomness(unsigned int type, unsigned int code,
79764- unsigned int value);
79765-extern void add_interrupt_randomness(int irq, int irq_flags);
79766+ unsigned int value) __latent_entropy;
79767+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
79768
79769 extern void get_random_bytes(void *buf, int nbytes);
79770 extern void get_random_bytes_arch(void *buf, int nbytes);
79771@@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
79772 extern const struct file_operations random_fops, urandom_fops;
79773 #endif
79774
79775-unsigned int get_random_int(void);
79776+unsigned int __intentional_overflow(-1) get_random_int(void);
79777 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
79778
79779-u32 prandom_u32(void);
79780+u32 prandom_u32(void) __intentional_overflow(-1);
79781 void prandom_bytes(void *buf, int nbytes);
79782 void prandom_seed(u32 seed);
79783 void prandom_reseed_late(void);
79784@@ -38,6 +48,11 @@ struct rnd_state {
79785 u32 prandom_u32_state(struct rnd_state *state);
79786 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
79787
79788+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
79789+{
79790+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
79791+}
79792+
79793 /*
79794 * Handle minimum values for seeds
79795 */
79796diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
79797index fea49b5..2ac22bb 100644
79798--- a/include/linux/rbtree_augmented.h
79799+++ b/include/linux/rbtree_augmented.h
79800@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
79801 old->rbaugmented = rbcompute(old); \
79802 } \
79803 rbstatic const struct rb_augment_callbacks rbname = { \
79804- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
79805+ .propagate = rbname ## _propagate, \
79806+ .copy = rbname ## _copy, \
79807+ .rotate = rbname ## _rotate \
79808 };
79809
79810
79811diff --git a/include/linux/rculist.h b/include/linux/rculist.h
79812index 45a0a9e..e83788e 100644
79813--- a/include/linux/rculist.h
79814+++ b/include/linux/rculist.h
79815@@ -29,8 +29,8 @@
79816 */
79817 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
79818 {
79819- ACCESS_ONCE(list->next) = list;
79820- ACCESS_ONCE(list->prev) = list;
79821+ ACCESS_ONCE_RW(list->next) = list;
79822+ ACCESS_ONCE_RW(list->prev) = list;
79823 }
79824
79825 /*
79826@@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
79827 struct list_head *prev, struct list_head *next);
79828 #endif
79829
79830+extern void __pax_list_add_rcu(struct list_head *new,
79831+ struct list_head *prev, struct list_head *next);
79832+
79833 /**
79834 * list_add_rcu - add a new entry to rcu-protected list
79835 * @new: new entry to be added
79836@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
79837 __list_add_rcu(new, head, head->next);
79838 }
79839
79840+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
79841+{
79842+ __pax_list_add_rcu(new, head, head->next);
79843+}
79844+
79845 /**
79846 * list_add_tail_rcu - add a new entry to rcu-protected list
79847 * @new: new entry to be added
79848@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
79849 __list_add_rcu(new, head->prev, head);
79850 }
79851
79852+static inline void pax_list_add_tail_rcu(struct list_head *new,
79853+ struct list_head *head)
79854+{
79855+ __pax_list_add_rcu(new, head->prev, head);
79856+}
79857+
79858 /**
79859 * list_del_rcu - deletes entry from list without re-initialization
79860 * @entry: the element to delete from the list.
79861@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
79862 entry->prev = LIST_POISON2;
79863 }
79864
79865+extern void pax_list_del_rcu(struct list_head *entry);
79866+
79867 /**
79868 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
79869 * @n: the element to delete from the hash list.
79870diff --git a/include/linux/reboot.h b/include/linux/reboot.h
79871index 9e7db9e..7d4fd72 100644
79872--- a/include/linux/reboot.h
79873+++ b/include/linux/reboot.h
79874@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
79875 */
79876
79877 extern void migrate_to_reboot_cpu(void);
79878-extern void machine_restart(char *cmd);
79879-extern void machine_halt(void);
79880-extern void machine_power_off(void);
79881+extern void machine_restart(char *cmd) __noreturn;
79882+extern void machine_halt(void) __noreturn;
79883+extern void machine_power_off(void) __noreturn;
79884
79885 extern void machine_shutdown(void);
79886 struct pt_regs;
79887@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
79888 */
79889
79890 extern void kernel_restart_prepare(char *cmd);
79891-extern void kernel_restart(char *cmd);
79892-extern void kernel_halt(void);
79893-extern void kernel_power_off(void);
79894+extern void kernel_restart(char *cmd) __noreturn;
79895+extern void kernel_halt(void) __noreturn;
79896+extern void kernel_power_off(void) __noreturn;
79897
79898 extern int C_A_D; /* for sysctl */
79899 void ctrl_alt_del(void);
79900@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
79901 * Emergency restart, callable from an interrupt handler.
79902 */
79903
79904-extern void emergency_restart(void);
79905+extern void emergency_restart(void) __noreturn;
79906 #include <asm/emergency-restart.h>
79907
79908 #endif /* _LINUX_REBOOT_H */
79909diff --git a/include/linux/regset.h b/include/linux/regset.h
79910index 8e0c9fe..ac4d221 100644
79911--- a/include/linux/regset.h
79912+++ b/include/linux/regset.h
79913@@ -161,7 +161,8 @@ struct user_regset {
79914 unsigned int align;
79915 unsigned int bias;
79916 unsigned int core_note_type;
79917-};
79918+} __do_const;
79919+typedef struct user_regset __no_const user_regset_no_const;
79920
79921 /**
79922 * struct user_regset_view - available regsets
79923diff --git a/include/linux/relay.h b/include/linux/relay.h
79924index d7c8359..818daf5 100644
79925--- a/include/linux/relay.h
79926+++ b/include/linux/relay.h
79927@@ -157,7 +157,7 @@ struct rchan_callbacks
79928 * The callback should return 0 if successful, negative if not.
79929 */
79930 int (*remove_buf_file)(struct dentry *dentry);
79931-};
79932+} __no_const;
79933
79934 /*
79935 * CONFIG_RELAY kernel API, kernel/relay.c
79936diff --git a/include/linux/rio.h b/include/linux/rio.h
79937index b71d573..2f940bd 100644
79938--- a/include/linux/rio.h
79939+++ b/include/linux/rio.h
79940@@ -355,7 +355,7 @@ struct rio_ops {
79941 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
79942 u64 rstart, u32 size, u32 flags);
79943 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
79944-};
79945+} __no_const;
79946
79947 #define RIO_RESOURCE_MEM 0x00000100
79948 #define RIO_RESOURCE_DOORBELL 0x00000200
79949diff --git a/include/linux/rmap.h b/include/linux/rmap.h
79950index 6dacb93..6174423 100644
79951--- a/include/linux/rmap.h
79952+++ b/include/linux/rmap.h
79953@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
79954 void anon_vma_init(void); /* create anon_vma_cachep */
79955 int anon_vma_prepare(struct vm_area_struct *);
79956 void unlink_anon_vmas(struct vm_area_struct *);
79957-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
79958-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
79959+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
79960+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
79961
79962 static inline void anon_vma_merge(struct vm_area_struct *vma,
79963 struct vm_area_struct *next)
79964diff --git a/include/linux/sched.h b/include/linux/sched.h
79965index 53f97eb..1d90705 100644
79966--- a/include/linux/sched.h
79967+++ b/include/linux/sched.h
79968@@ -63,6 +63,7 @@ struct bio_list;
79969 struct fs_struct;
79970 struct perf_event_context;
79971 struct blk_plug;
79972+struct linux_binprm;
79973
79974 /*
79975 * List of flags we want to share for kernel threads,
79976@@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
79977 extern int in_sched_functions(unsigned long addr);
79978
79979 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
79980-extern signed long schedule_timeout(signed long timeout);
79981+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
79982 extern signed long schedule_timeout_interruptible(signed long timeout);
79983 extern signed long schedule_timeout_killable(signed long timeout);
79984 extern signed long schedule_timeout_uninterruptible(signed long timeout);
79985@@ -315,6 +316,19 @@ struct nsproxy;
79986 struct user_namespace;
79987
79988 #ifdef CONFIG_MMU
79989+
79990+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
79991+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
79992+#else
79993+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
79994+{
79995+ return 0;
79996+}
79997+#endif
79998+
79999+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
80000+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
80001+
80002 extern void arch_pick_mmap_layout(struct mm_struct *mm);
80003 extern unsigned long
80004 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
80005@@ -600,6 +614,17 @@ struct signal_struct {
80006 #ifdef CONFIG_TASKSTATS
80007 struct taskstats *stats;
80008 #endif
80009+
80010+#ifdef CONFIG_GRKERNSEC
80011+ u32 curr_ip;
80012+ u32 saved_ip;
80013+ u32 gr_saddr;
80014+ u32 gr_daddr;
80015+ u16 gr_sport;
80016+ u16 gr_dport;
80017+ u8 used_accept:1;
80018+#endif
80019+
80020 #ifdef CONFIG_AUDIT
80021 unsigned audit_tty;
80022 unsigned audit_tty_log_passwd;
80023@@ -626,7 +651,7 @@ struct signal_struct {
80024 struct mutex cred_guard_mutex; /* guard against foreign influences on
80025 * credential calculations
80026 * (notably. ptrace) */
80027-};
80028+} __randomize_layout;
80029
80030 /*
80031 * Bits in flags field of signal_struct.
80032@@ -680,6 +705,14 @@ struct user_struct {
80033 struct key *session_keyring; /* UID's default session keyring */
80034 #endif
80035
80036+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
80037+ unsigned char kernel_banned;
80038+#endif
80039+#ifdef CONFIG_GRKERNSEC_BRUTE
80040+ unsigned char suid_banned;
80041+ unsigned long suid_ban_expires;
80042+#endif
80043+
80044 /* Hash table maintenance information */
80045 struct hlist_node uidhash_node;
80046 kuid_t uid;
80047@@ -687,7 +720,7 @@ struct user_struct {
80048 #ifdef CONFIG_PERF_EVENTS
80049 atomic_long_t locked_vm;
80050 #endif
80051-};
80052+} __randomize_layout;
80053
80054 extern int uids_sysfs_init(void);
80055
80056@@ -1162,8 +1195,8 @@ struct task_struct {
80057 struct list_head thread_group;
80058
80059 struct completion *vfork_done; /* for vfork() */
80060- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
80061- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80062+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
80063+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80064
80065 cputime_t utime, stime, utimescaled, stimescaled;
80066 cputime_t gtime;
80067@@ -1188,11 +1221,6 @@ struct task_struct {
80068 struct task_cputime cputime_expires;
80069 struct list_head cpu_timers[3];
80070
80071-/* process credentials */
80072- const struct cred __rcu *real_cred; /* objective and real subjective task
80073- * credentials (COW) */
80074- const struct cred __rcu *cred; /* effective (overridable) subjective task
80075- * credentials (COW) */
80076 char comm[TASK_COMM_LEN]; /* executable name excluding path
80077 - access with [gs]et_task_comm (which lock
80078 it with task_lock())
80079@@ -1209,6 +1237,10 @@ struct task_struct {
80080 #endif
80081 /* CPU-specific state of this task */
80082 struct thread_struct thread;
80083+/* thread_info moved to task_struct */
80084+#ifdef CONFIG_X86
80085+ struct thread_info tinfo;
80086+#endif
80087 /* filesystem information */
80088 struct fs_struct *fs;
80089 /* open file information */
80090@@ -1282,6 +1314,10 @@ struct task_struct {
80091 gfp_t lockdep_reclaim_gfp;
80092 #endif
80093
80094+/* process credentials */
80095+ const struct cred __rcu *real_cred; /* objective and real subjective task
80096+ * credentials (COW) */
80097+
80098 /* journalling filesystem info */
80099 void *journal_info;
80100
80101@@ -1320,6 +1356,10 @@ struct task_struct {
80102 /* cg_list protected by css_set_lock and tsk->alloc_lock */
80103 struct list_head cg_list;
80104 #endif
80105+
80106+ const struct cred __rcu *cred; /* effective (overridable) subjective task
80107+ * credentials (COW) */
80108+
80109 #ifdef CONFIG_FUTEX
80110 struct robust_list_head __user *robust_list;
80111 #ifdef CONFIG_COMPAT
80112@@ -1454,7 +1494,78 @@ struct task_struct {
80113 unsigned int sequential_io;
80114 unsigned int sequential_io_avg;
80115 #endif
80116-};
80117+
80118+#ifdef CONFIG_GRKERNSEC
80119+ /* grsecurity */
80120+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80121+ u64 exec_id;
80122+#endif
80123+#ifdef CONFIG_GRKERNSEC_SETXID
80124+ const struct cred *delayed_cred;
80125+#endif
80126+ struct dentry *gr_chroot_dentry;
80127+ struct acl_subject_label *acl;
80128+ struct acl_subject_label *tmpacl;
80129+ struct acl_role_label *role;
80130+ struct file *exec_file;
80131+ unsigned long brute_expires;
80132+ u16 acl_role_id;
80133+ u8 inherited;
80134+ /* is this the task that authenticated to the special role */
80135+ u8 acl_sp_role;
80136+ u8 is_writable;
80137+ u8 brute;
80138+ u8 gr_is_chrooted;
80139+#endif
80140+
80141+} __randomize_layout;
80142+
80143+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
80144+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
80145+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
80146+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
80147+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
80148+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
80149+
80150+#ifdef CONFIG_PAX_SOFTMODE
80151+extern int pax_softmode;
80152+#endif
80153+
80154+extern int pax_check_flags(unsigned long *);
80155+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
80156+
80157+/* if tsk != current then task_lock must be held on it */
80158+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80159+static inline unsigned long pax_get_flags(struct task_struct *tsk)
80160+{
80161+ if (likely(tsk->mm))
80162+ return tsk->mm->pax_flags;
80163+ else
80164+ return 0UL;
80165+}
80166+
80167+/* if tsk != current then task_lock must be held on it */
80168+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
80169+{
80170+ if (likely(tsk->mm)) {
80171+ tsk->mm->pax_flags = flags;
80172+ return 0;
80173+ }
80174+ return -EINVAL;
80175+}
80176+#endif
80177+
80178+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
80179+extern void pax_set_initial_flags(struct linux_binprm *bprm);
80180+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
80181+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
80182+#endif
80183+
80184+struct path;
80185+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
80186+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
80187+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
80188+extern void pax_report_refcount_overflow(struct pt_regs *regs);
80189
80190 /* Future-safe accessor for struct task_struct's cpus_allowed. */
80191 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
80192@@ -1531,7 +1642,7 @@ struct pid_namespace;
80193 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
80194 struct pid_namespace *ns);
80195
80196-static inline pid_t task_pid_nr(struct task_struct *tsk)
80197+static inline pid_t task_pid_nr(const struct task_struct *tsk)
80198 {
80199 return tsk->pid;
80200 }
80201@@ -1981,7 +2092,9 @@ void yield(void);
80202 extern struct exec_domain default_exec_domain;
80203
80204 union thread_union {
80205+#ifndef CONFIG_X86
80206 struct thread_info thread_info;
80207+#endif
80208 unsigned long stack[THREAD_SIZE/sizeof(long)];
80209 };
80210
80211@@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
80212 */
80213
80214 extern struct task_struct *find_task_by_vpid(pid_t nr);
80215+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
80216 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
80217 struct pid_namespace *ns);
80218
80219@@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
80220 extern void exit_itimers(struct signal_struct *);
80221 extern void flush_itimer_signals(void);
80222
80223-extern void do_group_exit(int);
80224+extern __noreturn void do_group_exit(int);
80225
80226 extern int allow_signal(int);
80227 extern int disallow_signal(int);
80228@@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
80229
80230 #endif
80231
80232-static inline int object_is_on_stack(void *obj)
80233+static inline int object_starts_on_stack(void *obj)
80234 {
80235- void *stack = task_stack_page(current);
80236+ const void *stack = task_stack_page(current);
80237
80238 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
80239 }
80240diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
80241index 41467f8..1e4253d 100644
80242--- a/include/linux/sched/sysctl.h
80243+++ b/include/linux/sched/sysctl.h
80244@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
80245 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
80246
80247 extern int sysctl_max_map_count;
80248+extern unsigned long sysctl_heap_stack_gap;
80249
80250 extern unsigned int sysctl_sched_latency;
80251 extern unsigned int sysctl_sched_min_granularity;
80252diff --git a/include/linux/security.h b/include/linux/security.h
80253index 5623a7f..b352409 100644
80254--- a/include/linux/security.h
80255+++ b/include/linux/security.h
80256@@ -27,6 +27,7 @@
80257 #include <linux/slab.h>
80258 #include <linux/err.h>
80259 #include <linux/string.h>
80260+#include <linux/grsecurity.h>
80261
80262 struct linux_binprm;
80263 struct cred;
80264@@ -116,8 +117,6 @@ struct seq_file;
80265
80266 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
80267
80268-void reset_security_ops(void);
80269-
80270 #ifdef CONFIG_MMU
80271 extern unsigned long mmap_min_addr;
80272 extern unsigned long dac_mmap_min_addr;
80273diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
80274index dc368b8..e895209 100644
80275--- a/include/linux/semaphore.h
80276+++ b/include/linux/semaphore.h
80277@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
80278 }
80279
80280 extern void down(struct semaphore *sem);
80281-extern int __must_check down_interruptible(struct semaphore *sem);
80282+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
80283 extern int __must_check down_killable(struct semaphore *sem);
80284 extern int __must_check down_trylock(struct semaphore *sem);
80285 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
80286diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
80287index 52e0097..09625ef 100644
80288--- a/include/linux/seq_file.h
80289+++ b/include/linux/seq_file.h
80290@@ -27,6 +27,9 @@ struct seq_file {
80291 struct mutex lock;
80292 const struct seq_operations *op;
80293 int poll_event;
80294+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80295+ u64 exec_id;
80296+#endif
80297 #ifdef CONFIG_USER_NS
80298 struct user_namespace *user_ns;
80299 #endif
80300@@ -39,6 +42,7 @@ struct seq_operations {
80301 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
80302 int (*show) (struct seq_file *m, void *v);
80303 };
80304+typedef struct seq_operations __no_const seq_operations_no_const;
80305
80306 #define SEQ_SKIP 1
80307
80308diff --git a/include/linux/shm.h b/include/linux/shm.h
80309index 429c199..4d42e38 100644
80310--- a/include/linux/shm.h
80311+++ b/include/linux/shm.h
80312@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
80313
80314 /* The task created the shm object. NULL if the task is dead. */
80315 struct task_struct *shm_creator;
80316+#ifdef CONFIG_GRKERNSEC
80317+ time_t shm_createtime;
80318+ pid_t shm_lapid;
80319+#endif
80320 };
80321
80322 /* shm_mode upper byte flags */
80323diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
80324index 6f69b3f..335b9b1 100644
80325--- a/include/linux/skbuff.h
80326+++ b/include/linux/skbuff.h
80327@@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
80328 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
80329 int node);
80330 struct sk_buff *build_skb(void *data, unsigned int frag_size);
80331-static inline struct sk_buff *alloc_skb(unsigned int size,
80332+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
80333 gfp_t priority)
80334 {
80335 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
80336@@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
80337 */
80338 static inline int skb_queue_empty(const struct sk_buff_head *list)
80339 {
80340- return list->next == (struct sk_buff *)list;
80341+ return list->next == (const struct sk_buff *)list;
80342 }
80343
80344 /**
80345@@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
80346 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80347 const struct sk_buff *skb)
80348 {
80349- return skb->next == (struct sk_buff *)list;
80350+ return skb->next == (const struct sk_buff *)list;
80351 }
80352
80353 /**
80354@@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80355 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
80356 const struct sk_buff *skb)
80357 {
80358- return skb->prev == (struct sk_buff *)list;
80359+ return skb->prev == (const struct sk_buff *)list;
80360 }
80361
80362 /**
80363@@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
80364 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
80365 */
80366 #ifndef NET_SKB_PAD
80367-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
80368+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
80369 #endif
80370
80371 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
80372@@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
80373 int *err);
80374 unsigned int datagram_poll(struct file *file, struct socket *sock,
80375 struct poll_table_struct *wait);
80376-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80377+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80378 struct iovec *to, int size);
80379 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
80380 struct iovec *iov);
80381@@ -2617,6 +2617,9 @@ static inline void nf_reset(struct sk_buff *skb)
80382 nf_bridge_put(skb->nf_bridge);
80383 skb->nf_bridge = NULL;
80384 #endif
80385+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
80386+ skb->nf_trace = 0;
80387+#endif
80388 }
80389
80390 static inline void nf_reset_trace(struct sk_buff *skb)
80391diff --git a/include/linux/slab.h b/include/linux/slab.h
80392index 1e2f4fe..df49ca6 100644
80393--- a/include/linux/slab.h
80394+++ b/include/linux/slab.h
80395@@ -14,15 +14,29 @@
80396 #include <linux/gfp.h>
80397 #include <linux/types.h>
80398 #include <linux/workqueue.h>
80399-
80400+#include <linux/err.h>
80401
80402 /*
80403 * Flags to pass to kmem_cache_create().
80404 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
80405 */
80406 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
80407+
80408+#ifdef CONFIG_PAX_USERCOPY_SLABS
80409+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
80410+#else
80411+#define SLAB_USERCOPY 0x00000000UL
80412+#endif
80413+
80414 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
80415 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
80416+
80417+#ifdef CONFIG_PAX_MEMORY_SANITIZE
80418+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
80419+#else
80420+#define SLAB_NO_SANITIZE 0x00000000UL
80421+#endif
80422+
80423 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
80424 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
80425 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
80426@@ -98,10 +112,13 @@
80427 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
80428 * Both make kfree a no-op.
80429 */
80430-#define ZERO_SIZE_PTR ((void *)16)
80431+#define ZERO_SIZE_PTR \
80432+({ \
80433+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
80434+ (void *)(-MAX_ERRNO-1L); \
80435+})
80436
80437-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
80438- (unsigned long)ZERO_SIZE_PTR)
80439+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
80440
80441 #include <linux/kmemleak.h>
80442
80443@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
80444 void kfree(const void *);
80445 void kzfree(const void *);
80446 size_t ksize(const void *);
80447+const char *check_heap_object(const void *ptr, unsigned long n);
80448+bool is_usercopy_object(const void *ptr);
80449
80450 /*
80451 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
80452@@ -174,7 +193,7 @@ struct kmem_cache {
80453 unsigned int align; /* Alignment as calculated */
80454 unsigned long flags; /* Active flags on the slab */
80455 const char *name; /* Slab name for sysfs */
80456- int refcount; /* Use counter */
80457+ atomic_t refcount; /* Use counter */
80458 void (*ctor)(void *); /* Called on object slot creation */
80459 struct list_head list; /* List of all slab caches on the system */
80460 };
80461@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
80462 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80463 #endif
80464
80465+#ifdef CONFIG_PAX_USERCOPY_SLABS
80466+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
80467+#endif
80468+
80469 /*
80470 * Figure out which kmalloc slab an allocation of a certain size
80471 * belongs to.
80472@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80473 * 2 = 120 .. 192 bytes
80474 * n = 2^(n-1) .. 2^n -1
80475 */
80476-static __always_inline int kmalloc_index(size_t size)
80477+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
80478 {
80479 if (!size)
80480 return 0;
80481@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
80482 }
80483 #endif /* !CONFIG_SLOB */
80484
80485-void *__kmalloc(size_t size, gfp_t flags);
80486+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
80487 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
80488
80489 #ifdef CONFIG_NUMA
80490-void *__kmalloc_node(size_t size, gfp_t flags, int node);
80491+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
80492 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
80493 #else
80494 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
80495diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
80496index 09bfffb..4fc80fb 100644
80497--- a/include/linux/slab_def.h
80498+++ b/include/linux/slab_def.h
80499@@ -36,7 +36,7 @@ struct kmem_cache {
80500 /* 4) cache creation/removal */
80501 const char *name;
80502 struct list_head list;
80503- int refcount;
80504+ atomic_t refcount;
80505 int object_size;
80506 int align;
80507
80508@@ -52,10 +52,14 @@ struct kmem_cache {
80509 unsigned long node_allocs;
80510 unsigned long node_frees;
80511 unsigned long node_overflow;
80512- atomic_t allochit;
80513- atomic_t allocmiss;
80514- atomic_t freehit;
80515- atomic_t freemiss;
80516+ atomic_unchecked_t allochit;
80517+ atomic_unchecked_t allocmiss;
80518+ atomic_unchecked_t freehit;
80519+ atomic_unchecked_t freemiss;
80520+#ifdef CONFIG_PAX_MEMORY_SANITIZE
80521+ atomic_unchecked_t sanitized;
80522+ atomic_unchecked_t not_sanitized;
80523+#endif
80524
80525 /*
80526 * If debugging is enabled, then the allocator can add additional
80527diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
80528index f56bfa9..8378a26 100644
80529--- a/include/linux/slub_def.h
80530+++ b/include/linux/slub_def.h
80531@@ -74,7 +74,7 @@ struct kmem_cache {
80532 struct kmem_cache_order_objects max;
80533 struct kmem_cache_order_objects min;
80534 gfp_t allocflags; /* gfp flags to use on each alloc */
80535- int refcount; /* Refcount for slab cache destroy */
80536+ atomic_t refcount; /* Refcount for slab cache destroy */
80537 void (*ctor)(void *);
80538 int inuse; /* Offset to metadata */
80539 int align; /* Alignment */
80540diff --git a/include/linux/smp.h b/include/linux/smp.h
80541index 5da22ee..71d8a28 100644
80542--- a/include/linux/smp.h
80543+++ b/include/linux/smp.h
80544@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
80545 #endif
80546
80547 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
80548+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
80549 #define put_cpu() preempt_enable()
80550+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
80551
80552 /*
80553 * Callback to arch code if there's nosmp or maxcpus=0 on the
80554diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
80555index 54f91d3..be2c379 100644
80556--- a/include/linux/sock_diag.h
80557+++ b/include/linux/sock_diag.h
80558@@ -11,7 +11,7 @@ struct sock;
80559 struct sock_diag_handler {
80560 __u8 family;
80561 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
80562-};
80563+} __do_const;
80564
80565 int sock_diag_register(const struct sock_diag_handler *h);
80566 void sock_diag_unregister(const struct sock_diag_handler *h);
80567diff --git a/include/linux/sonet.h b/include/linux/sonet.h
80568index 680f9a3..f13aeb0 100644
80569--- a/include/linux/sonet.h
80570+++ b/include/linux/sonet.h
80571@@ -7,7 +7,7 @@
80572 #include <uapi/linux/sonet.h>
80573
80574 struct k_sonet_stats {
80575-#define __HANDLE_ITEM(i) atomic_t i
80576+#define __HANDLE_ITEM(i) atomic_unchecked_t i
80577 __SONET_ITEMS
80578 #undef __HANDLE_ITEM
80579 };
80580diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
80581index 07d8e53..dc934c9 100644
80582--- a/include/linux/sunrpc/addr.h
80583+++ b/include/linux/sunrpc/addr.h
80584@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
80585 {
80586 switch (sap->sa_family) {
80587 case AF_INET:
80588- return ntohs(((struct sockaddr_in *)sap)->sin_port);
80589+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
80590 case AF_INET6:
80591- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
80592+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
80593 }
80594 return 0;
80595 }
80596@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
80597 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
80598 const struct sockaddr *src)
80599 {
80600- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
80601+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
80602 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
80603
80604 dsin->sin_family = ssin->sin_family;
80605@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
80606 if (sa->sa_family != AF_INET6)
80607 return 0;
80608
80609- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
80610+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
80611 }
80612
80613 #endif /* _LINUX_SUNRPC_ADDR_H */
80614diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
80615index 8af2804..c7414ef 100644
80616--- a/include/linux/sunrpc/clnt.h
80617+++ b/include/linux/sunrpc/clnt.h
80618@@ -97,7 +97,7 @@ struct rpc_procinfo {
80619 unsigned int p_timer; /* Which RTT timer to use */
80620 u32 p_statidx; /* Which procedure to account */
80621 const char * p_name; /* name of procedure */
80622-};
80623+} __do_const;
80624
80625 #ifdef __KERNEL__
80626
80627diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
80628index 6eecfc2..7ada79d 100644
80629--- a/include/linux/sunrpc/svc.h
80630+++ b/include/linux/sunrpc/svc.h
80631@@ -410,7 +410,7 @@ struct svc_procedure {
80632 unsigned int pc_count; /* call count */
80633 unsigned int pc_cachetype; /* cache info (NFS) */
80634 unsigned int pc_xdrressize; /* maximum size of XDR reply */
80635-};
80636+} __do_const;
80637
80638 /*
80639 * Function prototypes.
80640diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
80641index 0b8e3e6..33e0a01 100644
80642--- a/include/linux/sunrpc/svc_rdma.h
80643+++ b/include/linux/sunrpc/svc_rdma.h
80644@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
80645 extern unsigned int svcrdma_max_requests;
80646 extern unsigned int svcrdma_max_req_size;
80647
80648-extern atomic_t rdma_stat_recv;
80649-extern atomic_t rdma_stat_read;
80650-extern atomic_t rdma_stat_write;
80651-extern atomic_t rdma_stat_sq_starve;
80652-extern atomic_t rdma_stat_rq_starve;
80653-extern atomic_t rdma_stat_rq_poll;
80654-extern atomic_t rdma_stat_rq_prod;
80655-extern atomic_t rdma_stat_sq_poll;
80656-extern atomic_t rdma_stat_sq_prod;
80657+extern atomic_unchecked_t rdma_stat_recv;
80658+extern atomic_unchecked_t rdma_stat_read;
80659+extern atomic_unchecked_t rdma_stat_write;
80660+extern atomic_unchecked_t rdma_stat_sq_starve;
80661+extern atomic_unchecked_t rdma_stat_rq_starve;
80662+extern atomic_unchecked_t rdma_stat_rq_poll;
80663+extern atomic_unchecked_t rdma_stat_rq_prod;
80664+extern atomic_unchecked_t rdma_stat_sq_poll;
80665+extern atomic_unchecked_t rdma_stat_sq_prod;
80666
80667 #define RPCRDMA_VERSION 1
80668
80669diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
80670index 8d71d65..f79586e 100644
80671--- a/include/linux/sunrpc/svcauth.h
80672+++ b/include/linux/sunrpc/svcauth.h
80673@@ -120,7 +120,7 @@ struct auth_ops {
80674 int (*release)(struct svc_rqst *rq);
80675 void (*domain_release)(struct auth_domain *);
80676 int (*set_client)(struct svc_rqst *rq);
80677-};
80678+} __do_const;
80679
80680 #define SVC_GARBAGE 1
80681 #define SVC_SYSERR 2
80682diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
80683index a5ffd32..0935dea 100644
80684--- a/include/linux/swiotlb.h
80685+++ b/include/linux/swiotlb.h
80686@@ -60,7 +60,8 @@ extern void
80687
80688 extern void
80689 swiotlb_free_coherent(struct device *hwdev, size_t size,
80690- void *vaddr, dma_addr_t dma_handle);
80691+ void *vaddr, dma_addr_t dma_handle,
80692+ struct dma_attrs *attrs);
80693
80694 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
80695 unsigned long offset, size_t size,
80696diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
80697index 94273bb..c2e05fc 100644
80698--- a/include/linux/syscalls.h
80699+++ b/include/linux/syscalls.h
80700@@ -97,8 +97,14 @@ struct sigaltstack;
80701 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
80702
80703 #define __SC_DECL(t, a) t a
80704+#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))
80705 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
80706-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
80707+#define __SC_LONG(t, a) __typeof( \
80708+ __builtin_choose_expr( \
80709+ sizeof(t) > sizeof(int), \
80710+ (t) 0, \
80711+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
80712+ )) a
80713 #define __SC_CAST(t, a) (t) a
80714 #define __SC_ARGS(t, a) a
80715 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
80716@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
80717 asmlinkage long sys_fsync(unsigned int fd);
80718 asmlinkage long sys_fdatasync(unsigned int fd);
80719 asmlinkage long sys_bdflush(int func, long data);
80720-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
80721- char __user *type, unsigned long flags,
80722+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
80723+ const char __user *type, unsigned long flags,
80724 void __user *data);
80725-asmlinkage long sys_umount(char __user *name, int flags);
80726-asmlinkage long sys_oldumount(char __user *name);
80727+asmlinkage long sys_umount(const char __user *name, int flags);
80728+asmlinkage long sys_oldumount(const char __user *name);
80729 asmlinkage long sys_truncate(const char __user *path, long length);
80730 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
80731 asmlinkage long sys_stat(const char __user *filename,
80732@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
80733 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
80734 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
80735 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
80736- struct sockaddr __user *, int);
80737+ struct sockaddr __user *, int) __intentional_overflow(0);
80738 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
80739 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
80740 unsigned int vlen, unsigned flags);
80741diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
80742index 27b3b0b..e093dd9 100644
80743--- a/include/linux/syscore_ops.h
80744+++ b/include/linux/syscore_ops.h
80745@@ -16,7 +16,7 @@ struct syscore_ops {
80746 int (*suspend)(void);
80747 void (*resume)(void);
80748 void (*shutdown)(void);
80749-};
80750+} __do_const;
80751
80752 extern void register_syscore_ops(struct syscore_ops *ops);
80753 extern void unregister_syscore_ops(struct syscore_ops *ops);
80754diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
80755index 14a8ff2..fa95f3a 100644
80756--- a/include/linux/sysctl.h
80757+++ b/include/linux/sysctl.h
80758@@ -34,13 +34,13 @@ struct ctl_table_root;
80759 struct ctl_table_header;
80760 struct ctl_dir;
80761
80762-typedef struct ctl_table ctl_table;
80763-
80764 typedef int proc_handler (struct ctl_table *ctl, int write,
80765 void __user *buffer, size_t *lenp, loff_t *ppos);
80766
80767 extern int proc_dostring(struct ctl_table *, int,
80768 void __user *, size_t *, loff_t *);
80769+extern int proc_dostring_modpriv(struct ctl_table *, int,
80770+ void __user *, size_t *, loff_t *);
80771 extern int proc_dointvec(struct ctl_table *, int,
80772 void __user *, size_t *, loff_t *);
80773 extern int proc_dointvec_minmax(struct ctl_table *, int,
80774@@ -115,7 +115,9 @@ struct ctl_table
80775 struct ctl_table_poll *poll;
80776 void *extra1;
80777 void *extra2;
80778-};
80779+} __do_const __randomize_layout;
80780+typedef struct ctl_table __no_const ctl_table_no_const;
80781+typedef struct ctl_table ctl_table;
80782
80783 struct ctl_node {
80784 struct rb_node node;
80785diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
80786index 6695040..3d4192d 100644
80787--- a/include/linux/sysfs.h
80788+++ b/include/linux/sysfs.h
80789@@ -33,7 +33,8 @@ struct attribute {
80790 struct lock_class_key *key;
80791 struct lock_class_key skey;
80792 #endif
80793-};
80794+} __do_const;
80795+typedef struct attribute __no_const attribute_no_const;
80796
80797 /**
80798 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
80799@@ -62,7 +63,8 @@ struct attribute_group {
80800 struct attribute *, int);
80801 struct attribute **attrs;
80802 struct bin_attribute **bin_attrs;
80803-};
80804+} __do_const;
80805+typedef struct attribute_group __no_const attribute_group_no_const;
80806
80807 /**
80808 * Use these macros to make defining attributes easier. See include/linux/device.h
80809@@ -126,7 +128,8 @@ struct bin_attribute {
80810 char *, loff_t, size_t);
80811 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
80812 struct vm_area_struct *vma);
80813-};
80814+} __do_const;
80815+typedef struct bin_attribute __no_const bin_attribute_no_const;
80816
80817 /**
80818 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
80819diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
80820index 387fa7d..3fcde6b 100644
80821--- a/include/linux/sysrq.h
80822+++ b/include/linux/sysrq.h
80823@@ -16,6 +16,7 @@
80824
80825 #include <linux/errno.h>
80826 #include <linux/types.h>
80827+#include <linux/compiler.h>
80828
80829 /* Possible values of bitmask for enabling sysrq functions */
80830 /* 0x0001 is reserved for enable everything */
80831@@ -33,7 +34,7 @@ struct sysrq_key_op {
80832 char *help_msg;
80833 char *action_msg;
80834 int enable_mask;
80835-};
80836+} __do_const;
80837
80838 #ifdef CONFIG_MAGIC_SYSRQ
80839
80840diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
80841index fddbe20..0312de8 100644
80842--- a/include/linux/thread_info.h
80843+++ b/include/linux/thread_info.h
80844@@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
80845 #error "no set_restore_sigmask() provided and default one won't work"
80846 #endif
80847
80848+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
80849+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
80850+{
80851+#ifndef CONFIG_PAX_USERCOPY_DEBUG
80852+ if (!__builtin_constant_p(n))
80853+#endif
80854+ __check_object_size(ptr, n, to_user);
80855+}
80856+
80857 #endif /* __KERNEL__ */
80858
80859 #endif /* _LINUX_THREAD_INFO_H */
80860diff --git a/include/linux/tty.h b/include/linux/tty.h
80861index 97d660e..6356755 100644
80862--- a/include/linux/tty.h
80863+++ b/include/linux/tty.h
80864@@ -196,7 +196,7 @@ struct tty_port {
80865 const struct tty_port_operations *ops; /* Port operations */
80866 spinlock_t lock; /* Lock protecting tty field */
80867 int blocked_open; /* Waiting to open */
80868- int count; /* Usage count */
80869+ atomic_t count; /* Usage count */
80870 wait_queue_head_t open_wait; /* Open waiters */
80871 wait_queue_head_t close_wait; /* Close waiters */
80872 wait_queue_head_t delta_msr_wait; /* Modem status change */
80873@@ -278,7 +278,7 @@ struct tty_struct {
80874 /* If the tty has a pending do_SAK, queue it here - akpm */
80875 struct work_struct SAK_work;
80876 struct tty_port *port;
80877-};
80878+} __randomize_layout;
80879
80880 /* Each of a tty's open files has private_data pointing to tty_file_private */
80881 struct tty_file_private {
80882@@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
80883 struct tty_struct *tty, struct file *filp);
80884 static inline int tty_port_users(struct tty_port *port)
80885 {
80886- return port->count + port->blocked_open;
80887+ return atomic_read(&port->count) + port->blocked_open;
80888 }
80889
80890 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
80891diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
80892index 756a609..f61242d 100644
80893--- a/include/linux/tty_driver.h
80894+++ b/include/linux/tty_driver.h
80895@@ -285,7 +285,7 @@ struct tty_operations {
80896 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
80897 #endif
80898 const struct file_operations *proc_fops;
80899-};
80900+} __do_const;
80901
80902 struct tty_driver {
80903 int magic; /* magic number for this structure */
80904@@ -319,7 +319,7 @@ struct tty_driver {
80905
80906 const struct tty_operations *ops;
80907 struct list_head tty_drivers;
80908-};
80909+} __randomize_layout;
80910
80911 extern struct list_head tty_drivers;
80912
80913diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
80914index f15c898..207b7d1 100644
80915--- a/include/linux/tty_ldisc.h
80916+++ b/include/linux/tty_ldisc.h
80917@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
80918
80919 struct module *owner;
80920
80921- int refcount;
80922+ atomic_t refcount;
80923 };
80924
80925 struct tty_ldisc {
80926diff --git a/include/linux/types.h b/include/linux/types.h
80927index 4d118ba..c3ee9bf 100644
80928--- a/include/linux/types.h
80929+++ b/include/linux/types.h
80930@@ -176,10 +176,26 @@ typedef struct {
80931 int counter;
80932 } atomic_t;
80933
80934+#ifdef CONFIG_PAX_REFCOUNT
80935+typedef struct {
80936+ int counter;
80937+} atomic_unchecked_t;
80938+#else
80939+typedef atomic_t atomic_unchecked_t;
80940+#endif
80941+
80942 #ifdef CONFIG_64BIT
80943 typedef struct {
80944 long counter;
80945 } atomic64_t;
80946+
80947+#ifdef CONFIG_PAX_REFCOUNT
80948+typedef struct {
80949+ long counter;
80950+} atomic64_unchecked_t;
80951+#else
80952+typedef atomic64_t atomic64_unchecked_t;
80953+#endif
80954 #endif
80955
80956 struct list_head {
80957diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
80958index 9d8cf05..0ed74dd 100644
80959--- a/include/linux/uaccess.h
80960+++ b/include/linux/uaccess.h
80961@@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
80962 long ret; \
80963 mm_segment_t old_fs = get_fs(); \
80964 \
80965- set_fs(KERNEL_DS); \
80966 pagefault_disable(); \
80967- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
80968- pagefault_enable(); \
80969+ set_fs(KERNEL_DS); \
80970+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
80971 set_fs(old_fs); \
80972+ pagefault_enable(); \
80973 ret; \
80974 })
80975
80976diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
80977index 8e522cbc..aa8572d 100644
80978--- a/include/linux/uidgid.h
80979+++ b/include/linux/uidgid.h
80980@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
80981
80982 #endif /* CONFIG_USER_NS */
80983
80984+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
80985+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
80986+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
80987+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
80988+
80989 #endif /* _LINUX_UIDGID_H */
80990diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
80991index 99c1b4d..562e6f3 100644
80992--- a/include/linux/unaligned/access_ok.h
80993+++ b/include/linux/unaligned/access_ok.h
80994@@ -4,34 +4,34 @@
80995 #include <linux/kernel.h>
80996 #include <asm/byteorder.h>
80997
80998-static inline u16 get_unaligned_le16(const void *p)
80999+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
81000 {
81001- return le16_to_cpup((__le16 *)p);
81002+ return le16_to_cpup((const __le16 *)p);
81003 }
81004
81005-static inline u32 get_unaligned_le32(const void *p)
81006+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
81007 {
81008- return le32_to_cpup((__le32 *)p);
81009+ return le32_to_cpup((const __le32 *)p);
81010 }
81011
81012-static inline u64 get_unaligned_le64(const void *p)
81013+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
81014 {
81015- return le64_to_cpup((__le64 *)p);
81016+ return le64_to_cpup((const __le64 *)p);
81017 }
81018
81019-static inline u16 get_unaligned_be16(const void *p)
81020+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
81021 {
81022- return be16_to_cpup((__be16 *)p);
81023+ return be16_to_cpup((const __be16 *)p);
81024 }
81025
81026-static inline u32 get_unaligned_be32(const void *p)
81027+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
81028 {
81029- return be32_to_cpup((__be32 *)p);
81030+ return be32_to_cpup((const __be32 *)p);
81031 }
81032
81033-static inline u64 get_unaligned_be64(const void *p)
81034+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
81035 {
81036- return be64_to_cpup((__be64 *)p);
81037+ return be64_to_cpup((const __be64 *)p);
81038 }
81039
81040 static inline void put_unaligned_le16(u16 val, void *p)
81041diff --git a/include/linux/usb.h b/include/linux/usb.h
81042index 512ab16..f53e1bf 100644
81043--- a/include/linux/usb.h
81044+++ b/include/linux/usb.h
81045@@ -563,7 +563,7 @@ struct usb_device {
81046 int maxchild;
81047
81048 u32 quirks;
81049- atomic_t urbnum;
81050+ atomic_unchecked_t urbnum;
81051
81052 unsigned long active_duration;
81053
81054@@ -1643,7 +1643,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
81055
81056 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
81057 __u8 request, __u8 requesttype, __u16 value, __u16 index,
81058- void *data, __u16 size, int timeout);
81059+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
81060 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
81061 void *data, int len, int *actual_length, int timeout);
81062 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
81063diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
81064index e452ba6..78f8e80 100644
81065--- a/include/linux/usb/renesas_usbhs.h
81066+++ b/include/linux/usb/renesas_usbhs.h
81067@@ -39,7 +39,7 @@ enum {
81068 */
81069 struct renesas_usbhs_driver_callback {
81070 int (*notify_hotplug)(struct platform_device *pdev);
81071-};
81072+} __no_const;
81073
81074 /*
81075 * callback functions for platform
81076diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
81077index 4836ba3..603f6ee 100644
81078--- a/include/linux/user_namespace.h
81079+++ b/include/linux/user_namespace.h
81080@@ -33,7 +33,7 @@ struct user_namespace {
81081 struct key *persistent_keyring_register;
81082 struct rw_semaphore persistent_keyring_register_sem;
81083 #endif
81084-};
81085+} __randomize_layout;
81086
81087 extern struct user_namespace init_user_ns;
81088
81089diff --git a/include/linux/utsname.h b/include/linux/utsname.h
81090index 239e277..22a5cf5 100644
81091--- a/include/linux/utsname.h
81092+++ b/include/linux/utsname.h
81093@@ -24,7 +24,7 @@ struct uts_namespace {
81094 struct new_utsname name;
81095 struct user_namespace *user_ns;
81096 unsigned int proc_inum;
81097-};
81098+} __randomize_layout;
81099 extern struct uts_namespace init_uts_ns;
81100
81101 #ifdef CONFIG_UTS_NS
81102diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
81103index 6f8fbcf..e2a0e61 100644
81104--- a/include/linux/vermagic.h
81105+++ b/include/linux/vermagic.h
81106@@ -25,9 +25,41 @@
81107 #define MODULE_ARCH_VERMAGIC ""
81108 #endif
81109
81110+#ifdef CONFIG_PAX_REFCOUNT
81111+#define MODULE_PAX_REFCOUNT "REFCOUNT "
81112+#else
81113+#define MODULE_PAX_REFCOUNT ""
81114+#endif
81115+
81116+#ifdef CONSTIFY_PLUGIN
81117+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
81118+#else
81119+#define MODULE_CONSTIFY_PLUGIN ""
81120+#endif
81121+
81122+#ifdef STACKLEAK_PLUGIN
81123+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
81124+#else
81125+#define MODULE_STACKLEAK_PLUGIN ""
81126+#endif
81127+
81128+#ifdef RANDSTRUCT_PLUGIN
81129+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
81130+#else
81131+#define MODULE_RANDSTRUCT_PLUGIN
81132+#endif
81133+
81134+#ifdef CONFIG_GRKERNSEC
81135+#define MODULE_GRSEC "GRSEC "
81136+#else
81137+#define MODULE_GRSEC ""
81138+#endif
81139+
81140 #define VERMAGIC_STRING \
81141 UTS_RELEASE " " \
81142 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
81143 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
81144- MODULE_ARCH_VERMAGIC
81145+ MODULE_ARCH_VERMAGIC \
81146+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
81147+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
81148
81149diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
81150index 502073a..a7de024 100644
81151--- a/include/linux/vga_switcheroo.h
81152+++ b/include/linux/vga_switcheroo.h
81153@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
81154
81155 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
81156
81157-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
81158-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
81159+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
81160+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
81161 #else
81162
81163 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
81164@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
81165
81166 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
81167
81168-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81169-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81170+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81171+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81172
81173 #endif
81174 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
81175diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
81176index 4b8a891..cb8df6e 100644
81177--- a/include/linux/vmalloc.h
81178+++ b/include/linux/vmalloc.h
81179@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
81180 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
81181 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
81182 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
81183+
81184+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
81185+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
81186+#endif
81187+
81188 /* bits [20..32] reserved for arch specific ioremap internals */
81189
81190 /*
81191@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
81192
81193 /* for /dev/kmem */
81194 extern long vread(char *buf, char *addr, unsigned long count);
81195-extern long vwrite(char *buf, char *addr, unsigned long count);
81196+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
81197
81198 /*
81199 * Internals. Dont't use..
81200diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
81201index e4b9480..5a5f65a 100644
81202--- a/include/linux/vmstat.h
81203+++ b/include/linux/vmstat.h
81204@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
81205 /*
81206 * Zone based page accounting with per cpu differentials.
81207 */
81208-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81209+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81210
81211 static inline void zone_page_state_add(long x, struct zone *zone,
81212 enum zone_stat_item item)
81213 {
81214- atomic_long_add(x, &zone->vm_stat[item]);
81215- atomic_long_add(x, &vm_stat[item]);
81216+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
81217+ atomic_long_add_unchecked(x, &vm_stat[item]);
81218 }
81219
81220-static inline unsigned long global_page_state(enum zone_stat_item item)
81221+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
81222 {
81223- long x = atomic_long_read(&vm_stat[item]);
81224+ long x = atomic_long_read_unchecked(&vm_stat[item]);
81225 #ifdef CONFIG_SMP
81226 if (x < 0)
81227 x = 0;
81228@@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
81229 return x;
81230 }
81231
81232-static inline unsigned long zone_page_state(struct zone *zone,
81233+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
81234 enum zone_stat_item item)
81235 {
81236- long x = atomic_long_read(&zone->vm_stat[item]);
81237+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81238 #ifdef CONFIG_SMP
81239 if (x < 0)
81240 x = 0;
81241@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
81242 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
81243 enum zone_stat_item item)
81244 {
81245- long x = atomic_long_read(&zone->vm_stat[item]);
81246+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81247
81248 #ifdef CONFIG_SMP
81249 int cpu;
81250@@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
81251
81252 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
81253 {
81254- atomic_long_inc(&zone->vm_stat[item]);
81255- atomic_long_inc(&vm_stat[item]);
81256+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
81257+ atomic_long_inc_unchecked(&vm_stat[item]);
81258 }
81259
81260 static inline void __inc_zone_page_state(struct page *page,
81261@@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
81262
81263 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
81264 {
81265- atomic_long_dec(&zone->vm_stat[item]);
81266- atomic_long_dec(&vm_stat[item]);
81267+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
81268+ atomic_long_dec_unchecked(&vm_stat[item]);
81269 }
81270
81271 static inline void __dec_zone_page_state(struct page *page,
81272diff --git a/include/linux/xattr.h b/include/linux/xattr.h
81273index 91b0a68..0e9adf6 100644
81274--- a/include/linux/xattr.h
81275+++ b/include/linux/xattr.h
81276@@ -28,7 +28,7 @@ struct xattr_handler {
81277 size_t size, int handler_flags);
81278 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
81279 size_t size, int flags, int handler_flags);
81280-};
81281+} __do_const;
81282
81283 struct xattr {
81284 const char *name;
81285@@ -37,6 +37,9 @@ struct xattr {
81286 };
81287
81288 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
81289+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81290+ssize_t pax_getxattr(struct dentry *, void *, size_t);
81291+#endif
81292 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
81293 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
81294 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
81295diff --git a/include/linux/zlib.h b/include/linux/zlib.h
81296index 9c5a6b4..09c9438 100644
81297--- a/include/linux/zlib.h
81298+++ b/include/linux/zlib.h
81299@@ -31,6 +31,7 @@
81300 #define _ZLIB_H
81301
81302 #include <linux/zconf.h>
81303+#include <linux/compiler.h>
81304
81305 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
81306 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
81307@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
81308
81309 /* basic functions */
81310
81311-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
81312+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
81313 /*
81314 Returns the number of bytes that needs to be allocated for a per-
81315 stream workspace with the specified parameters. A pointer to this
81316diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
81317index c768c9f..bdcaa5a 100644
81318--- a/include/media/v4l2-dev.h
81319+++ b/include/media/v4l2-dev.h
81320@@ -76,7 +76,7 @@ struct v4l2_file_operations {
81321 int (*mmap) (struct file *, struct vm_area_struct *);
81322 int (*open) (struct file *);
81323 int (*release) (struct file *);
81324-};
81325+} __do_const;
81326
81327 /*
81328 * Newer version of video_device, handled by videodev2.c
81329diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
81330index c9b1593..a572459 100644
81331--- a/include/media/v4l2-device.h
81332+++ b/include/media/v4l2-device.h
81333@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
81334 this function returns 0. If the name ends with a digit (e.g. cx18),
81335 then the name will be set to cx18-0 since cx180 looks really odd. */
81336 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
81337- atomic_t *instance);
81338+ atomic_unchecked_t *instance);
81339
81340 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
81341 Since the parent disappears this ensures that v4l2_dev doesn't have an
81342diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
81343index 9a36d92..0aafe2a 100644
81344--- a/include/net/9p/transport.h
81345+++ b/include/net/9p/transport.h
81346@@ -60,7 +60,7 @@ struct p9_trans_module {
81347 int (*cancel) (struct p9_client *, struct p9_req_t *req);
81348 int (*zc_request)(struct p9_client *, struct p9_req_t *,
81349 char *, char *, int , int, int, int);
81350-};
81351+} __do_const;
81352
81353 void v9fs_register_trans(struct p9_trans_module *m);
81354 void v9fs_unregister_trans(struct p9_trans_module *m);
81355diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
81356index c853b16d..37fccb7 100644
81357--- a/include/net/bluetooth/l2cap.h
81358+++ b/include/net/bluetooth/l2cap.h
81359@@ -557,7 +557,7 @@ struct l2cap_ops {
81360 long (*get_sndtimeo) (struct l2cap_chan *chan);
81361 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
81362 unsigned long len, int nb);
81363-};
81364+} __do_const;
81365
81366 struct l2cap_conn {
81367 struct hci_conn *hcon;
81368diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
81369index f2ae33d..c457cf0 100644
81370--- a/include/net/caif/cfctrl.h
81371+++ b/include/net/caif/cfctrl.h
81372@@ -52,7 +52,7 @@ struct cfctrl_rsp {
81373 void (*radioset_rsp)(void);
81374 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
81375 struct cflayer *client_layer);
81376-};
81377+} __no_const;
81378
81379 /* Link Setup Parameters for CAIF-Links. */
81380 struct cfctrl_link_param {
81381@@ -101,8 +101,8 @@ struct cfctrl_request_info {
81382 struct cfctrl {
81383 struct cfsrvl serv;
81384 struct cfctrl_rsp res;
81385- atomic_t req_seq_no;
81386- atomic_t rsp_seq_no;
81387+ atomic_unchecked_t req_seq_no;
81388+ atomic_unchecked_t rsp_seq_no;
81389 struct list_head list;
81390 /* Protects from simultaneous access to first_req list */
81391 spinlock_t info_list_lock;
81392diff --git a/include/net/flow.h b/include/net/flow.h
81393index 65ce471..b7bbe9b 100644
81394--- a/include/net/flow.h
81395+++ b/include/net/flow.h
81396@@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
81397
81398 void flow_cache_flush(void);
81399 void flow_cache_flush_deferred(void);
81400-extern atomic_t flow_cache_genid;
81401+extern atomic_unchecked_t flow_cache_genid;
81402
81403 #endif
81404diff --git a/include/net/genetlink.h b/include/net/genetlink.h
81405index 1b177ed..a24a138 100644
81406--- a/include/net/genetlink.h
81407+++ b/include/net/genetlink.h
81408@@ -118,7 +118,7 @@ struct genl_ops {
81409 u8 cmd;
81410 u8 internal_flags;
81411 u8 flags;
81412-};
81413+} __do_const;
81414
81415 int __genl_register_family(struct genl_family *family);
81416
81417diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
81418index 734d9b5..48a9a4b 100644
81419--- a/include/net/gro_cells.h
81420+++ b/include/net/gro_cells.h
81421@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
81422 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
81423
81424 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
81425- atomic_long_inc(&dev->rx_dropped);
81426+ atomic_long_inc_unchecked(&dev->rx_dropped);
81427 kfree_skb(skb);
81428 return;
81429 }
81430diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
81431index c55aeed..b3393f4 100644
81432--- a/include/net/inet_connection_sock.h
81433+++ b/include/net/inet_connection_sock.h
81434@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
81435 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
81436 int (*bind_conflict)(const struct sock *sk,
81437 const struct inet_bind_bucket *tb, bool relax);
81438-};
81439+} __do_const;
81440
81441 /** inet_connection_sock - INET connection oriented sock
81442 *
81443diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
81444index f4e127a..c3d5e9c 100644
81445--- a/include/net/inetpeer.h
81446+++ b/include/net/inetpeer.h
81447@@ -47,8 +47,8 @@ struct inet_peer {
81448 */
81449 union {
81450 struct {
81451- atomic_t rid; /* Frag reception counter */
81452- atomic_t ip_id_count; /* IP ID for the next packet */
81453+ atomic_unchecked_t rid; /* Frag reception counter */
81454+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
81455 };
81456 struct rcu_head rcu;
81457 struct inet_peer *gc_next;
81458@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
81459 /* can be called with or without local BH being disabled */
81460 static inline int inet_getid(struct inet_peer *p, int more)
81461 {
81462- int old, new;
81463+ int id;
81464 more++;
81465 inet_peer_refcheck(p);
81466- do {
81467- old = atomic_read(&p->ip_id_count);
81468- new = old + more;
81469- if (!new)
81470- new = 1;
81471- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
81472- return new;
81473+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
81474+ if (!id)
81475+ id = atomic_inc_return_unchecked(&p->ip_id_count);
81476+ return id;
81477 }
81478
81479 #endif /* _NET_INETPEER_H */
81480diff --git a/include/net/ip.h b/include/net/ip.h
81481index 5a25f36..2e73203 100644
81482--- a/include/net/ip.h
81483+++ b/include/net/ip.h
81484@@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
81485
81486 void inet_get_local_port_range(struct net *net, int *low, int *high);
81487
81488-extern unsigned long *sysctl_local_reserved_ports;
81489+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
81490 static inline int inet_is_reserved_local_port(int port)
81491 {
81492 return test_bit(port, sysctl_local_reserved_ports);
81493diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
81494index 9922093..a1755d6 100644
81495--- a/include/net/ip_fib.h
81496+++ b/include/net/ip_fib.h
81497@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
81498
81499 #define FIB_RES_SADDR(net, res) \
81500 ((FIB_RES_NH(res).nh_saddr_genid == \
81501- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
81502+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
81503 FIB_RES_NH(res).nh_saddr : \
81504 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
81505 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
81506diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
81507index 5679d92..2e7a690 100644
81508--- a/include/net/ip_vs.h
81509+++ b/include/net/ip_vs.h
81510@@ -558,7 +558,7 @@ struct ip_vs_conn {
81511 struct ip_vs_conn *control; /* Master control connection */
81512 atomic_t n_control; /* Number of controlled ones */
81513 struct ip_vs_dest *dest; /* real server */
81514- atomic_t in_pkts; /* incoming packet counter */
81515+ atomic_unchecked_t in_pkts; /* incoming packet counter */
81516
81517 /* packet transmitter for different forwarding methods. If it
81518 mangles the packet, it must return NF_DROP or better NF_STOLEN,
81519@@ -705,7 +705,7 @@ struct ip_vs_dest {
81520 __be16 port; /* port number of the server */
81521 union nf_inet_addr addr; /* IP address of the server */
81522 volatile unsigned int flags; /* dest status flags */
81523- atomic_t conn_flags; /* flags to copy to conn */
81524+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
81525 atomic_t weight; /* server weight */
81526
81527 atomic_t refcnt; /* reference counter */
81528@@ -960,11 +960,11 @@ struct netns_ipvs {
81529 /* ip_vs_lblc */
81530 int sysctl_lblc_expiration;
81531 struct ctl_table_header *lblc_ctl_header;
81532- struct ctl_table *lblc_ctl_table;
81533+ ctl_table_no_const *lblc_ctl_table;
81534 /* ip_vs_lblcr */
81535 int sysctl_lblcr_expiration;
81536 struct ctl_table_header *lblcr_ctl_header;
81537- struct ctl_table *lblcr_ctl_table;
81538+ ctl_table_no_const *lblcr_ctl_table;
81539 /* ip_vs_est */
81540 struct list_head est_list; /* estimator list */
81541 spinlock_t est_lock;
81542diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
81543index 0224402..dafaf94a 100644
81544--- a/include/net/irda/ircomm_tty.h
81545+++ b/include/net/irda/ircomm_tty.h
81546@@ -35,6 +35,7 @@
81547 #include <linux/termios.h>
81548 #include <linux/timer.h>
81549 #include <linux/tty.h> /* struct tty_struct */
81550+#include <asm/local.h>
81551
81552 #include <net/irda/irias_object.h>
81553 #include <net/irda/ircomm_core.h>
81554diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
81555index 714cc9a..ea05f3e 100644
81556--- a/include/net/iucv/af_iucv.h
81557+++ b/include/net/iucv/af_iucv.h
81558@@ -149,7 +149,7 @@ struct iucv_skb_cb {
81559 struct iucv_sock_list {
81560 struct hlist_head head;
81561 rwlock_t lock;
81562- atomic_t autobind_name;
81563+ atomic_unchecked_t autobind_name;
81564 };
81565
81566 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
81567diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
81568index f3be818..bf46196 100644
81569--- a/include/net/llc_c_ac.h
81570+++ b/include/net/llc_c_ac.h
81571@@ -87,7 +87,7 @@
81572 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
81573 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
81574
81575-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81576+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81577
81578 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
81579 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
81580diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
81581index 3948cf1..83b28c4 100644
81582--- a/include/net/llc_c_ev.h
81583+++ b/include/net/llc_c_ev.h
81584@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
81585 return (struct llc_conn_state_ev *)skb->cb;
81586 }
81587
81588-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81589-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81590+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81591+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81592
81593 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
81594 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
81595diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
81596index 0e79cfb..f46db31 100644
81597--- a/include/net/llc_c_st.h
81598+++ b/include/net/llc_c_st.h
81599@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
81600 u8 next_state;
81601 llc_conn_ev_qfyr_t *ev_qualifiers;
81602 llc_conn_action_t *ev_actions;
81603-};
81604+} __do_const;
81605
81606 struct llc_conn_state {
81607 u8 current_state;
81608diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
81609index a61b98c..aade1eb 100644
81610--- a/include/net/llc_s_ac.h
81611+++ b/include/net/llc_s_ac.h
81612@@ -23,7 +23,7 @@
81613 #define SAP_ACT_TEST_IND 9
81614
81615 /* All action functions must look like this */
81616-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81617+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81618
81619 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
81620 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
81621diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
81622index 567c681..cd73ac0 100644
81623--- a/include/net/llc_s_st.h
81624+++ b/include/net/llc_s_st.h
81625@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
81626 llc_sap_ev_t ev;
81627 u8 next_state;
81628 llc_sap_action_t *ev_actions;
81629-};
81630+} __do_const;
81631
81632 struct llc_sap_state {
81633 u8 curr_state;
81634diff --git a/include/net/mac80211.h b/include/net/mac80211.h
81635index 7ceed99..d3ffaa2 100644
81636--- a/include/net/mac80211.h
81637+++ b/include/net/mac80211.h
81638@@ -4407,7 +4407,7 @@ struct rate_control_ops {
81639 void (*add_sta_debugfs)(void *priv, void *priv_sta,
81640 struct dentry *dir);
81641 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
81642-};
81643+} __do_const;
81644
81645 static inline int rate_supported(struct ieee80211_sta *sta,
81646 enum ieee80211_band band,
81647diff --git a/include/net/neighbour.h b/include/net/neighbour.h
81648index 536501a..74ad02bc 100644
81649--- a/include/net/neighbour.h
81650+++ b/include/net/neighbour.h
81651@@ -123,7 +123,7 @@ struct neigh_ops {
81652 void (*error_report)(struct neighbour *, struct sk_buff *);
81653 int (*output)(struct neighbour *, struct sk_buff *);
81654 int (*connected_output)(struct neighbour *, struct sk_buff *);
81655-};
81656+} __do_const;
81657
81658 struct pneigh_entry {
81659 struct pneigh_entry *next;
81660@@ -178,7 +178,7 @@ struct neigh_table {
81661 struct neigh_statistics __percpu *stats;
81662 struct neigh_hash_table __rcu *nht;
81663 struct pneigh_entry **phash_buckets;
81664-};
81665+} __randomize_layout;
81666
81667 #define NEIGH_PRIV_ALIGN sizeof(long long)
81668 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
81669diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
81670index da68c9a..c4a0720 100644
81671--- a/include/net/net_namespace.h
81672+++ b/include/net/net_namespace.h
81673@@ -124,8 +124,8 @@ struct net {
81674 struct netns_ipvs *ipvs;
81675 #endif
81676 struct sock *diag_nlsk;
81677- atomic_t fnhe_genid;
81678-};
81679+ atomic_unchecked_t fnhe_genid;
81680+} __randomize_layout;
81681
81682 /*
81683 * ifindex generation is per-net namespace, and loopback is
81684@@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
81685 #define __net_init __init
81686 #define __net_exit __exit_refok
81687 #define __net_initdata __initdata
81688+#ifdef CONSTIFY_PLUGIN
81689 #define __net_initconst __initconst
81690+#else
81691+#define __net_initconst __initdata
81692+#endif
81693 #endif
81694
81695 struct pernet_operations {
81696@@ -291,7 +295,7 @@ struct pernet_operations {
81697 void (*exit_batch)(struct list_head *net_exit_list);
81698 int *id;
81699 size_t size;
81700-};
81701+} __do_const;
81702
81703 /*
81704 * Use these carefully. If you implement a network device and it
81705@@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
81706
81707 static inline int rt_genid_ipv4(struct net *net)
81708 {
81709- return atomic_read(&net->ipv4.rt_genid);
81710+ return atomic_read_unchecked(&net->ipv4.rt_genid);
81711 }
81712
81713 static inline void rt_genid_bump_ipv4(struct net *net)
81714 {
81715- atomic_inc(&net->ipv4.rt_genid);
81716+ atomic_inc_unchecked(&net->ipv4.rt_genid);
81717 }
81718
81719 #if IS_ENABLED(CONFIG_IPV6)
81720 static inline int rt_genid_ipv6(struct net *net)
81721 {
81722- return atomic_read(&net->ipv6.rt_genid);
81723+ return atomic_read_unchecked(&net->ipv6.rt_genid);
81724 }
81725
81726 static inline void rt_genid_bump_ipv6(struct net *net)
81727 {
81728- atomic_inc(&net->ipv6.rt_genid);
81729+ atomic_inc_unchecked(&net->ipv6.rt_genid);
81730 }
81731 #else
81732 static inline int rt_genid_ipv6(struct net *net)
81733@@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
81734
81735 static inline int fnhe_genid(struct net *net)
81736 {
81737- return atomic_read(&net->fnhe_genid);
81738+ return atomic_read_unchecked(&net->fnhe_genid);
81739 }
81740
81741 static inline void fnhe_genid_bump(struct net *net)
81742 {
81743- atomic_inc(&net->fnhe_genid);
81744+ atomic_inc_unchecked(&net->fnhe_genid);
81745 }
81746
81747 #endif /* __NET_NET_NAMESPACE_H */
81748diff --git a/include/net/netdma.h b/include/net/netdma.h
81749index 8ba8ce2..99b7fff 100644
81750--- a/include/net/netdma.h
81751+++ b/include/net/netdma.h
81752@@ -24,7 +24,7 @@
81753 #include <linux/dmaengine.h>
81754 #include <linux/skbuff.h>
81755
81756-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81757+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81758 struct sk_buff *skb, int offset, struct iovec *to,
81759 size_t len, struct dma_pinned_list *pinned_list);
81760
81761diff --git a/include/net/netlink.h b/include/net/netlink.h
81762index 2b47eaa..6d5bcc2 100644
81763--- a/include/net/netlink.h
81764+++ b/include/net/netlink.h
81765@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
81766 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
81767 {
81768 if (mark)
81769- skb_trim(skb, (unsigned char *) mark - skb->data);
81770+ skb_trim(skb, (const unsigned char *) mark - skb->data);
81771 }
81772
81773 /**
81774diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
81775index c9c0c53..53f24c3 100644
81776--- a/include/net/netns/conntrack.h
81777+++ b/include/net/netns/conntrack.h
81778@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
81779 struct nf_proto_net {
81780 #ifdef CONFIG_SYSCTL
81781 struct ctl_table_header *ctl_table_header;
81782- struct ctl_table *ctl_table;
81783+ ctl_table_no_const *ctl_table;
81784 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
81785 struct ctl_table_header *ctl_compat_header;
81786- struct ctl_table *ctl_compat_table;
81787+ ctl_table_no_const *ctl_compat_table;
81788 #endif
81789 #endif
81790 unsigned int users;
81791@@ -58,7 +58,7 @@ struct nf_ip_net {
81792 struct nf_icmp_net icmpv6;
81793 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
81794 struct ctl_table_header *ctl_table_header;
81795- struct ctl_table *ctl_table;
81796+ ctl_table_no_const *ctl_table;
81797 #endif
81798 };
81799
81800diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
81801index ee520cb..9a0fd88 100644
81802--- a/include/net/netns/ipv4.h
81803+++ b/include/net/netns/ipv4.h
81804@@ -72,7 +72,7 @@ struct netns_ipv4 {
81805
81806 kgid_t sysctl_ping_group_range[2];
81807
81808- atomic_t dev_addr_genid;
81809+ atomic_unchecked_t dev_addr_genid;
81810
81811 #ifdef CONFIG_IP_MROUTE
81812 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
81813@@ -82,6 +82,6 @@ struct netns_ipv4 {
81814 struct fib_rules_ops *mr_rules_ops;
81815 #endif
81816 #endif
81817- atomic_t rt_genid;
81818+ atomic_unchecked_t rt_genid;
81819 };
81820 #endif
81821diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
81822index 0fb2401..477d81c 100644
81823--- a/include/net/netns/ipv6.h
81824+++ b/include/net/netns/ipv6.h
81825@@ -71,8 +71,8 @@ struct netns_ipv6 {
81826 struct fib_rules_ops *mr6_rules_ops;
81827 #endif
81828 #endif
81829- atomic_t dev_addr_genid;
81830- atomic_t rt_genid;
81831+ atomic_unchecked_t dev_addr_genid;
81832+ atomic_unchecked_t rt_genid;
81833 };
81834
81835 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
81836diff --git a/include/net/ping.h b/include/net/ping.h
81837index 90f4841..74446a8 100644
81838--- a/include/net/ping.h
81839+++ b/include/net/ping.h
81840@@ -56,7 +56,7 @@ struct ping_iter_state {
81841 extern struct proto ping_prot;
81842 extern struct ping_table ping_table;
81843 #if IS_ENABLED(CONFIG_IPV6)
81844-extern struct pingv6_ops pingv6_ops;
81845+extern struct pingv6_ops *pingv6_ops;
81846 #endif
81847
81848 struct pingfakehdr {
81849diff --git a/include/net/protocol.h b/include/net/protocol.h
81850index fbf7676..a5e21c3 100644
81851--- a/include/net/protocol.h
81852+++ b/include/net/protocol.h
81853@@ -44,7 +44,7 @@ struct net_protocol {
81854 void (*err_handler)(struct sk_buff *skb, u32 info);
81855 unsigned int no_policy:1,
81856 netns_ok:1;
81857-};
81858+} __do_const;
81859
81860 #if IS_ENABLED(CONFIG_IPV6)
81861 struct inet6_protocol {
81862@@ -57,7 +57,7 @@ struct inet6_protocol {
81863 u8 type, u8 code, int offset,
81864 __be32 info);
81865 unsigned int flags; /* INET6_PROTO_xxx */
81866-};
81867+} __do_const;
81868
81869 #define INET6_PROTO_NOPOLICY 0x1
81870 #define INET6_PROTO_FINAL 0x2
81871diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
81872index bb13a18..e734116 100644
81873--- a/include/net/rtnetlink.h
81874+++ b/include/net/rtnetlink.h
81875@@ -79,7 +79,7 @@ struct rtnl_link_ops {
81876 const struct net_device *dev);
81877 unsigned int (*get_num_tx_queues)(void);
81878 unsigned int (*get_num_rx_queues)(void);
81879-};
81880+} __do_const;
81881
81882 int __rtnl_link_register(struct rtnl_link_ops *ops);
81883 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
81884diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
81885index 6bd44fe..96f364e 100644
81886--- a/include/net/sctp/checksum.h
81887+++ b/include/net/sctp/checksum.h
81888@@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
81889 unsigned int offset)
81890 {
81891 struct sctphdr *sh = sctp_hdr(skb);
81892- __le32 ret, old = sh->checksum;
81893- const struct skb_checksum_ops ops = {
81894+ __le32 ret, old = sh->checksum;
81895+ static const struct skb_checksum_ops ops = {
81896 .update = sctp_csum_update,
81897 .combine = sctp_csum_combine,
81898 };
81899diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
81900index 4ef75af..5aa073a 100644
81901--- a/include/net/sctp/sm.h
81902+++ b/include/net/sctp/sm.h
81903@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
81904 typedef struct {
81905 sctp_state_fn_t *fn;
81906 const char *name;
81907-} sctp_sm_table_entry_t;
81908+} __do_const sctp_sm_table_entry_t;
81909
81910 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
81911 * currently in use.
81912@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
81913 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
81914
81915 /* Extern declarations for major data structures. */
81916-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
81917+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
81918
81919
81920 /* Get the size of a DATA chunk payload. */
81921diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
81922index 0a248b3..4dcbe5c 100644
81923--- a/include/net/sctp/structs.h
81924+++ b/include/net/sctp/structs.h
81925@@ -508,7 +508,7 @@ struct sctp_pf {
81926 struct sctp_association *asoc);
81927 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
81928 struct sctp_af *af;
81929-};
81930+} __do_const;
81931
81932
81933 /* Structure to track chunk fragments that have been acked, but peer
81934diff --git a/include/net/sock.h b/include/net/sock.h
81935index 2ef3c3e..e02013e 100644
81936--- a/include/net/sock.h
81937+++ b/include/net/sock.h
81938@@ -348,7 +348,7 @@ struct sock {
81939 unsigned int sk_napi_id;
81940 unsigned int sk_ll_usec;
81941 #endif
81942- atomic_t sk_drops;
81943+ atomic_unchecked_t sk_drops;
81944 int sk_rcvbuf;
81945
81946 struct sk_filter __rcu *sk_filter;
81947@@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
81948 return ret >> PAGE_SHIFT;
81949 }
81950
81951-static inline long
81952+static inline long __intentional_overflow(-1)
81953 sk_memory_allocated(const struct sock *sk)
81954 {
81955 struct proto *prot = sk->sk_prot;
81956@@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
81957 }
81958
81959 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
81960- char __user *from, char *to,
81961+ char __user *from, unsigned char *to,
81962 int copy, int offset)
81963 {
81964 if (skb->ip_summed == CHECKSUM_NONE) {
81965@@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
81966 }
81967 }
81968
81969-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
81970+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
81971
81972 /**
81973 * sk_page_frag - return an appropriate page_frag
81974diff --git a/include/net/tcp.h b/include/net/tcp.h
81975index 70e55d2..c5d8d53 100644
81976--- a/include/net/tcp.h
81977+++ b/include/net/tcp.h
81978@@ -540,7 +540,7 @@ void tcp_retransmit_timer(struct sock *sk);
81979 void tcp_xmit_retransmit_queue(struct sock *);
81980 void tcp_simple_retransmit(struct sock *);
81981 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
81982-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
81983+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
81984
81985 void tcp_send_probe0(struct sock *);
81986 void tcp_send_partial(struct sock *);
81987@@ -711,8 +711,8 @@ struct tcp_skb_cb {
81988 struct inet6_skb_parm h6;
81989 #endif
81990 } header; /* For incoming frames */
81991- __u32 seq; /* Starting sequence number */
81992- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
81993+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
81994+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
81995 __u32 when; /* used to compute rtt's */
81996 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
81997
81998@@ -726,7 +726,7 @@ struct tcp_skb_cb {
81999
82000 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
82001 /* 1 byte hole */
82002- __u32 ack_seq; /* Sequence number ACK'd */
82003+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
82004 };
82005
82006 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
82007diff --git a/include/net/xfrm.h b/include/net/xfrm.h
82008index 6b82fdf..14d74d2 100644
82009--- a/include/net/xfrm.h
82010+++ b/include/net/xfrm.h
82011@@ -287,7 +287,6 @@ struct xfrm_dst;
82012 struct xfrm_policy_afinfo {
82013 unsigned short family;
82014 struct dst_ops *dst_ops;
82015- void (*garbage_collect)(struct net *net);
82016 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
82017 const xfrm_address_t *saddr,
82018 const xfrm_address_t *daddr);
82019@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
82020 struct net_device *dev,
82021 const struct flowi *fl);
82022 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
82023-};
82024+} __do_const;
82025
82026 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
82027 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
82028@@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
82029 int (*transport_finish)(struct sk_buff *skb,
82030 int async);
82031 void (*local_error)(struct sk_buff *skb, u32 mtu);
82032-};
82033+} __do_const;
82034
82035 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
82036 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
82037@@ -429,7 +428,7 @@ struct xfrm_mode {
82038 struct module *owner;
82039 unsigned int encap;
82040 int flags;
82041-};
82042+} __do_const;
82043
82044 /* Flags for xfrm_mode. */
82045 enum {
82046@@ -526,7 +525,7 @@ struct xfrm_policy {
82047 struct timer_list timer;
82048
82049 struct flow_cache_object flo;
82050- atomic_t genid;
82051+ atomic_unchecked_t genid;
82052 u32 priority;
82053 u32 index;
82054 struct xfrm_mark mark;
82055@@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
82056 }
82057
82058 void xfrm_garbage_collect(struct net *net);
82059+void xfrm_garbage_collect_deferred(struct net *net);
82060
82061 #else
82062
82063@@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
82064 static inline void xfrm_garbage_collect(struct net *net)
82065 {
82066 }
82067+static inline void xfrm_garbage_collect_deferred(struct net *net)
82068+{
82069+}
82070 #endif
82071
82072 static __inline__
82073diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
82074index 1017e0b..227aa4d 100644
82075--- a/include/rdma/iw_cm.h
82076+++ b/include/rdma/iw_cm.h
82077@@ -122,7 +122,7 @@ struct iw_cm_verbs {
82078 int backlog);
82079
82080 int (*destroy_listen)(struct iw_cm_id *cm_id);
82081-};
82082+} __no_const;
82083
82084 /**
82085 * iw_create_cm_id - Create an IW CM identifier.
82086diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
82087index 52beadf..598734c 100644
82088--- a/include/scsi/libfc.h
82089+++ b/include/scsi/libfc.h
82090@@ -771,6 +771,7 @@ struct libfc_function_template {
82091 */
82092 void (*disc_stop_final) (struct fc_lport *);
82093 };
82094+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
82095
82096 /**
82097 * struct fc_disc - Discovery context
82098@@ -875,7 +876,7 @@ struct fc_lport {
82099 struct fc_vport *vport;
82100
82101 /* Operational Information */
82102- struct libfc_function_template tt;
82103+ libfc_function_template_no_const tt;
82104 u8 link_up;
82105 u8 qfull;
82106 enum fc_lport_state state;
82107diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
82108index d65fbec..f80fef2 100644
82109--- a/include/scsi/scsi_device.h
82110+++ b/include/scsi/scsi_device.h
82111@@ -180,9 +180,9 @@ struct scsi_device {
82112 unsigned int max_device_blocked; /* what device_blocked counts down from */
82113 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
82114
82115- atomic_t iorequest_cnt;
82116- atomic_t iodone_cnt;
82117- atomic_t ioerr_cnt;
82118+ atomic_unchecked_t iorequest_cnt;
82119+ atomic_unchecked_t iodone_cnt;
82120+ atomic_unchecked_t ioerr_cnt;
82121
82122 struct device sdev_gendev,
82123 sdev_dev;
82124diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
82125index b797e8f..8e2c3aa 100644
82126--- a/include/scsi/scsi_transport_fc.h
82127+++ b/include/scsi/scsi_transport_fc.h
82128@@ -751,7 +751,8 @@ struct fc_function_template {
82129 unsigned long show_host_system_hostname:1;
82130
82131 unsigned long disable_target_scan:1;
82132-};
82133+} __do_const;
82134+typedef struct fc_function_template __no_const fc_function_template_no_const;
82135
82136
82137 /**
82138diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
82139index ae6c3b8..fd748ac 100644
82140--- a/include/sound/compress_driver.h
82141+++ b/include/sound/compress_driver.h
82142@@ -128,7 +128,7 @@ struct snd_compr_ops {
82143 struct snd_compr_caps *caps);
82144 int (*get_codec_caps) (struct snd_compr_stream *stream,
82145 struct snd_compr_codec_caps *codec);
82146-};
82147+} __no_const;
82148
82149 /**
82150 * struct snd_compr: Compressed device
82151diff --git a/include/sound/soc.h b/include/sound/soc.h
82152index 1f741cb..8cefc08 100644
82153--- a/include/sound/soc.h
82154+++ b/include/sound/soc.h
82155@@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
82156 /* probe ordering - for components with runtime dependencies */
82157 int probe_order;
82158 int remove_order;
82159-};
82160+} __do_const;
82161
82162 /* SoC platform interface */
82163 struct snd_soc_platform_driver {
82164@@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
82165 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
82166 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
82167 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
82168-};
82169+} __do_const;
82170
82171 struct snd_soc_platform {
82172 const char *name;
82173diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
82174index 321301c..2ae5cb0 100644
82175--- a/include/target/target_core_base.h
82176+++ b/include/target/target_core_base.h
82177@@ -687,7 +687,7 @@ struct se_device {
82178 atomic_long_t write_bytes;
82179 /* Active commands on this virtual SE device */
82180 atomic_t simple_cmds;
82181- atomic_t dev_ordered_id;
82182+ atomic_unchecked_t dev_ordered_id;
82183 atomic_t dev_ordered_sync;
82184 atomic_t dev_qf_count;
82185 int export_count;
82186diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
82187new file mode 100644
82188index 0000000..fb634b7
82189--- /dev/null
82190+++ b/include/trace/events/fs.h
82191@@ -0,0 +1,53 @@
82192+#undef TRACE_SYSTEM
82193+#define TRACE_SYSTEM fs
82194+
82195+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
82196+#define _TRACE_FS_H
82197+
82198+#include <linux/fs.h>
82199+#include <linux/tracepoint.h>
82200+
82201+TRACE_EVENT(do_sys_open,
82202+
82203+ TP_PROTO(const char *filename, int flags, int mode),
82204+
82205+ TP_ARGS(filename, flags, mode),
82206+
82207+ TP_STRUCT__entry(
82208+ __string( filename, filename )
82209+ __field( int, flags )
82210+ __field( int, mode )
82211+ ),
82212+
82213+ TP_fast_assign(
82214+ __assign_str(filename, filename);
82215+ __entry->flags = flags;
82216+ __entry->mode = mode;
82217+ ),
82218+
82219+ TP_printk("\"%s\" %x %o",
82220+ __get_str(filename), __entry->flags, __entry->mode)
82221+);
82222+
82223+TRACE_EVENT(open_exec,
82224+
82225+ TP_PROTO(const char *filename),
82226+
82227+ TP_ARGS(filename),
82228+
82229+ TP_STRUCT__entry(
82230+ __string( filename, filename )
82231+ ),
82232+
82233+ TP_fast_assign(
82234+ __assign_str(filename, filename);
82235+ ),
82236+
82237+ TP_printk("\"%s\"",
82238+ __get_str(filename))
82239+);
82240+
82241+#endif /* _TRACE_FS_H */
82242+
82243+/* This part must be outside protection */
82244+#include <trace/define_trace.h>
82245diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
82246index 1c09820..7f5ec79 100644
82247--- a/include/trace/events/irq.h
82248+++ b/include/trace/events/irq.h
82249@@ -36,7 +36,7 @@ struct softirq_action;
82250 */
82251 TRACE_EVENT(irq_handler_entry,
82252
82253- TP_PROTO(int irq, struct irqaction *action),
82254+ TP_PROTO(int irq, const struct irqaction *action),
82255
82256 TP_ARGS(irq, action),
82257
82258@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
82259 */
82260 TRACE_EVENT(irq_handler_exit,
82261
82262- TP_PROTO(int irq, struct irqaction *action, int ret),
82263+ TP_PROTO(int irq, const struct irqaction *action, int ret),
82264
82265 TP_ARGS(irq, action, ret),
82266
82267diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
82268index 7caf44c..23c6f27 100644
82269--- a/include/uapi/linux/a.out.h
82270+++ b/include/uapi/linux/a.out.h
82271@@ -39,6 +39,14 @@ enum machine_type {
82272 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
82273 };
82274
82275+/* Constants for the N_FLAGS field */
82276+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82277+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
82278+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
82279+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
82280+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82281+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82282+
82283 #if !defined (N_MAGIC)
82284 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
82285 #endif
82286diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
82287index d876736..ccce5c0 100644
82288--- a/include/uapi/linux/byteorder/little_endian.h
82289+++ b/include/uapi/linux/byteorder/little_endian.h
82290@@ -42,51 +42,51 @@
82291
82292 static inline __le64 __cpu_to_le64p(const __u64 *p)
82293 {
82294- return (__force __le64)*p;
82295+ return (__force const __le64)*p;
82296 }
82297-static inline __u64 __le64_to_cpup(const __le64 *p)
82298+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
82299 {
82300- return (__force __u64)*p;
82301+ return (__force const __u64)*p;
82302 }
82303 static inline __le32 __cpu_to_le32p(const __u32 *p)
82304 {
82305- return (__force __le32)*p;
82306+ return (__force const __le32)*p;
82307 }
82308 static inline __u32 __le32_to_cpup(const __le32 *p)
82309 {
82310- return (__force __u32)*p;
82311+ return (__force const __u32)*p;
82312 }
82313 static inline __le16 __cpu_to_le16p(const __u16 *p)
82314 {
82315- return (__force __le16)*p;
82316+ return (__force const __le16)*p;
82317 }
82318 static inline __u16 __le16_to_cpup(const __le16 *p)
82319 {
82320- return (__force __u16)*p;
82321+ return (__force const __u16)*p;
82322 }
82323 static inline __be64 __cpu_to_be64p(const __u64 *p)
82324 {
82325- return (__force __be64)__swab64p(p);
82326+ return (__force const __be64)__swab64p(p);
82327 }
82328 static inline __u64 __be64_to_cpup(const __be64 *p)
82329 {
82330- return __swab64p((__u64 *)p);
82331+ return __swab64p((const __u64 *)p);
82332 }
82333 static inline __be32 __cpu_to_be32p(const __u32 *p)
82334 {
82335- return (__force __be32)__swab32p(p);
82336+ return (__force const __be32)__swab32p(p);
82337 }
82338-static inline __u32 __be32_to_cpup(const __be32 *p)
82339+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
82340 {
82341- return __swab32p((__u32 *)p);
82342+ return __swab32p((const __u32 *)p);
82343 }
82344 static inline __be16 __cpu_to_be16p(const __u16 *p)
82345 {
82346- return (__force __be16)__swab16p(p);
82347+ return (__force const __be16)__swab16p(p);
82348 }
82349 static inline __u16 __be16_to_cpup(const __be16 *p)
82350 {
82351- return __swab16p((__u16 *)p);
82352+ return __swab16p((const __u16 *)p);
82353 }
82354 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
82355 #define __le64_to_cpus(x) do { (void)(x); } while (0)
82356diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
82357index ef6103b..d4e65dd 100644
82358--- a/include/uapi/linux/elf.h
82359+++ b/include/uapi/linux/elf.h
82360@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
82361 #define PT_GNU_EH_FRAME 0x6474e550
82362
82363 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
82364+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
82365+
82366+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
82367+
82368+/* Constants for the e_flags field */
82369+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82370+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
82371+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
82372+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
82373+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82374+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82375
82376 /*
82377 * Extended Numbering
82378@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
82379 #define DT_DEBUG 21
82380 #define DT_TEXTREL 22
82381 #define DT_JMPREL 23
82382+#define DT_FLAGS 30
82383+ #define DF_TEXTREL 0x00000004
82384 #define DT_ENCODING 32
82385 #define OLD_DT_LOOS 0x60000000
82386 #define DT_LOOS 0x6000000d
82387@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
82388 #define PF_W 0x2
82389 #define PF_X 0x1
82390
82391+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
82392+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
82393+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
82394+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
82395+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
82396+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
82397+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
82398+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
82399+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
82400+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
82401+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
82402+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
82403+
82404 typedef struct elf32_phdr{
82405 Elf32_Word p_type;
82406 Elf32_Off p_offset;
82407@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
82408 #define EI_OSABI 7
82409 #define EI_PAD 8
82410
82411+#define EI_PAX 14
82412+
82413 #define ELFMAG0 0x7f /* EI_MAG */
82414 #define ELFMAG1 'E'
82415 #define ELFMAG2 'L'
82416diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
82417index aa169c4..6a2771d 100644
82418--- a/include/uapi/linux/personality.h
82419+++ b/include/uapi/linux/personality.h
82420@@ -30,6 +30,7 @@ enum {
82421 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
82422 ADDR_NO_RANDOMIZE | \
82423 ADDR_COMPAT_LAYOUT | \
82424+ ADDR_LIMIT_3GB | \
82425 MMAP_PAGE_ZERO)
82426
82427 /*
82428diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
82429index 7530e74..e714828 100644
82430--- a/include/uapi/linux/screen_info.h
82431+++ b/include/uapi/linux/screen_info.h
82432@@ -43,7 +43,8 @@ struct screen_info {
82433 __u16 pages; /* 0x32 */
82434 __u16 vesa_attributes; /* 0x34 */
82435 __u32 capabilities; /* 0x36 */
82436- __u8 _reserved[6]; /* 0x3a */
82437+ __u16 vesapm_size; /* 0x3a */
82438+ __u8 _reserved[4]; /* 0x3c */
82439 } __attribute__((packed));
82440
82441 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
82442diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
82443index 0e011eb..82681b1 100644
82444--- a/include/uapi/linux/swab.h
82445+++ b/include/uapi/linux/swab.h
82446@@ -43,7 +43,7 @@
82447 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
82448 */
82449
82450-static inline __attribute_const__ __u16 __fswab16(__u16 val)
82451+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
82452 {
82453 #ifdef __HAVE_BUILTIN_BSWAP16__
82454 return __builtin_bswap16(val);
82455@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
82456 #endif
82457 }
82458
82459-static inline __attribute_const__ __u32 __fswab32(__u32 val)
82460+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
82461 {
82462 #ifdef __HAVE_BUILTIN_BSWAP32__
82463 return __builtin_bswap32(val);
82464@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
82465 #endif
82466 }
82467
82468-static inline __attribute_const__ __u64 __fswab64(__u64 val)
82469+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
82470 {
82471 #ifdef __HAVE_BUILTIN_BSWAP64__
82472 return __builtin_bswap64(val);
82473diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
82474index 6d67213..552fdd9 100644
82475--- a/include/uapi/linux/sysctl.h
82476+++ b/include/uapi/linux/sysctl.h
82477@@ -155,8 +155,6 @@ enum
82478 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
82479 };
82480
82481-
82482-
82483 /* CTL_VM names: */
82484 enum
82485 {
82486diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
82487index 437f1b0..0eeb38d 100644
82488--- a/include/uapi/linux/videodev2.h
82489+++ b/include/uapi/linux/videodev2.h
82490@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
82491 union {
82492 __s32 value;
82493 __s64 value64;
82494- char *string;
82495+ char __user *string;
82496 };
82497 } __attribute__ ((packed));
82498
82499diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
82500index e4629b9..6958086 100644
82501--- a/include/uapi/linux/xattr.h
82502+++ b/include/uapi/linux/xattr.h
82503@@ -63,5 +63,9 @@
82504 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
82505 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
82506
82507+/* User namespace */
82508+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
82509+#define XATTR_PAX_FLAGS_SUFFIX "flags"
82510+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
82511
82512 #endif /* _UAPI_LINUX_XATTR_H */
82513diff --git a/include/video/udlfb.h b/include/video/udlfb.h
82514index f9466fa..f4e2b81 100644
82515--- a/include/video/udlfb.h
82516+++ b/include/video/udlfb.h
82517@@ -53,10 +53,10 @@ struct dlfb_data {
82518 u32 pseudo_palette[256];
82519 int blank_mode; /*one of FB_BLANK_ */
82520 /* blit-only rendering path metrics, exposed through sysfs */
82521- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82522- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
82523- atomic_t bytes_sent; /* to usb, after compression including overhead */
82524- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
82525+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82526+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
82527+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
82528+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
82529 };
82530
82531 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
82532diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
82533index 30f5362..8ed8ac9 100644
82534--- a/include/video/uvesafb.h
82535+++ b/include/video/uvesafb.h
82536@@ -122,6 +122,7 @@ struct uvesafb_par {
82537 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
82538 u8 pmi_setpal; /* PMI for palette changes */
82539 u16 *pmi_base; /* protected mode interface location */
82540+ u8 *pmi_code; /* protected mode code location */
82541 void *pmi_start;
82542 void *pmi_pal;
82543 u8 *vbe_state_orig; /*
82544diff --git a/init/Kconfig b/init/Kconfig
82545index 4e5d96a..93cd8a1 100644
82546--- a/init/Kconfig
82547+++ b/init/Kconfig
82548@@ -1079,6 +1079,7 @@ endif # CGROUPS
82549
82550 config CHECKPOINT_RESTORE
82551 bool "Checkpoint/restore support" if EXPERT
82552+ depends on !GRKERNSEC
82553 default n
82554 help
82555 Enables additional kernel features in a sake of checkpoint/restore.
82556@@ -1550,7 +1551,7 @@ config SLUB_DEBUG
82557
82558 config COMPAT_BRK
82559 bool "Disable heap randomization"
82560- default y
82561+ default n
82562 help
82563 Randomizing heap placement makes heap exploits harder, but it
82564 also breaks ancient binaries (including anything libc5 based).
82565@@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
82566 config STOP_MACHINE
82567 bool
82568 default y
82569- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
82570+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
82571 help
82572 Need stop_machine() primitive.
82573
82574diff --git a/init/Makefile b/init/Makefile
82575index 7bc47ee..6da2dc7 100644
82576--- a/init/Makefile
82577+++ b/init/Makefile
82578@@ -2,6 +2,9 @@
82579 # Makefile for the linux kernel.
82580 #
82581
82582+ccflags-y := $(GCC_PLUGINS_CFLAGS)
82583+asflags-y := $(GCC_PLUGINS_AFLAGS)
82584+
82585 obj-y := main.o version.o mounts.o
82586 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
82587 obj-y += noinitramfs.o
82588diff --git a/init/do_mounts.c b/init/do_mounts.c
82589index 8e5addc..c96ea61 100644
82590--- a/init/do_mounts.c
82591+++ b/init/do_mounts.c
82592@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
82593 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
82594 {
82595 struct super_block *s;
82596- int err = sys_mount(name, "/root", fs, flags, data);
82597+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
82598 if (err)
82599 return err;
82600
82601- sys_chdir("/root");
82602+ sys_chdir((const char __force_user *)"/root");
82603 s = current->fs->pwd.dentry->d_sb;
82604 ROOT_DEV = s->s_dev;
82605 printk(KERN_INFO
82606@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
82607 va_start(args, fmt);
82608 vsprintf(buf, fmt, args);
82609 va_end(args);
82610- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
82611+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
82612 if (fd >= 0) {
82613 sys_ioctl(fd, FDEJECT, 0);
82614 sys_close(fd);
82615 }
82616 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
82617- fd = sys_open("/dev/console", O_RDWR, 0);
82618+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
82619 if (fd >= 0) {
82620 sys_ioctl(fd, TCGETS, (long)&termios);
82621 termios.c_lflag &= ~ICANON;
82622 sys_ioctl(fd, TCSETSF, (long)&termios);
82623- sys_read(fd, &c, 1);
82624+ sys_read(fd, (char __user *)&c, 1);
82625 termios.c_lflag |= ICANON;
82626 sys_ioctl(fd, TCSETSF, (long)&termios);
82627 sys_close(fd);
82628@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
82629 mount_root();
82630 out:
82631 devtmpfs_mount("dev");
82632- sys_mount(".", "/", NULL, MS_MOVE, NULL);
82633- sys_chroot(".");
82634+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82635+ sys_chroot((const char __force_user *)".");
82636 }
82637
82638 static bool is_tmpfs;
82639diff --git a/init/do_mounts.h b/init/do_mounts.h
82640index f5b978a..69dbfe8 100644
82641--- a/init/do_mounts.h
82642+++ b/init/do_mounts.h
82643@@ -15,15 +15,15 @@ extern int root_mountflags;
82644
82645 static inline int create_dev(char *name, dev_t dev)
82646 {
82647- sys_unlink(name);
82648- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
82649+ sys_unlink((char __force_user *)name);
82650+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
82651 }
82652
82653 #if BITS_PER_LONG == 32
82654 static inline u32 bstat(char *name)
82655 {
82656 struct stat64 stat;
82657- if (sys_stat64(name, &stat) != 0)
82658+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
82659 return 0;
82660 if (!S_ISBLK(stat.st_mode))
82661 return 0;
82662@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
82663 static inline u32 bstat(char *name)
82664 {
82665 struct stat stat;
82666- if (sys_newstat(name, &stat) != 0)
82667+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
82668 return 0;
82669 if (!S_ISBLK(stat.st_mode))
82670 return 0;
82671diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
82672index 3e0878e..8a9d7a0 100644
82673--- a/init/do_mounts_initrd.c
82674+++ b/init/do_mounts_initrd.c
82675@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
82676 {
82677 sys_unshare(CLONE_FS | CLONE_FILES);
82678 /* stdin/stdout/stderr for /linuxrc */
82679- sys_open("/dev/console", O_RDWR, 0);
82680+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
82681 sys_dup(0);
82682 sys_dup(0);
82683 /* move initrd over / and chdir/chroot in initrd root */
82684- sys_chdir("/root");
82685- sys_mount(".", "/", NULL, MS_MOVE, NULL);
82686- sys_chroot(".");
82687+ sys_chdir((const char __force_user *)"/root");
82688+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82689+ sys_chroot((const char __force_user *)".");
82690 sys_setsid();
82691 return 0;
82692 }
82693@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
82694 create_dev("/dev/root.old", Root_RAM0);
82695 /* mount initrd on rootfs' /root */
82696 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
82697- sys_mkdir("/old", 0700);
82698- sys_chdir("/old");
82699+ sys_mkdir((const char __force_user *)"/old", 0700);
82700+ sys_chdir((const char __force_user *)"/old");
82701
82702 /* try loading default modules from initrd */
82703 load_default_modules();
82704@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
82705 current->flags &= ~PF_FREEZER_SKIP;
82706
82707 /* move initrd to rootfs' /old */
82708- sys_mount("..", ".", NULL, MS_MOVE, NULL);
82709+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
82710 /* switch root and cwd back to / of rootfs */
82711- sys_chroot("..");
82712+ sys_chroot((const char __force_user *)"..");
82713
82714 if (new_decode_dev(real_root_dev) == Root_RAM0) {
82715- sys_chdir("/old");
82716+ sys_chdir((const char __force_user *)"/old");
82717 return;
82718 }
82719
82720- sys_chdir("/");
82721+ sys_chdir((const char __force_user *)"/");
82722 ROOT_DEV = new_decode_dev(real_root_dev);
82723 mount_root();
82724
82725 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
82726- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
82727+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
82728 if (!error)
82729 printk("okay\n");
82730 else {
82731- int fd = sys_open("/dev/root.old", O_RDWR, 0);
82732+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
82733 if (error == -ENOENT)
82734 printk("/initrd does not exist. Ignored.\n");
82735 else
82736 printk("failed\n");
82737 printk(KERN_NOTICE "Unmounting old root\n");
82738- sys_umount("/old", MNT_DETACH);
82739+ sys_umount((char __force_user *)"/old", MNT_DETACH);
82740 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
82741 if (fd < 0) {
82742 error = fd;
82743@@ -127,11 +127,11 @@ int __init initrd_load(void)
82744 * mounted in the normal path.
82745 */
82746 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
82747- sys_unlink("/initrd.image");
82748+ sys_unlink((const char __force_user *)"/initrd.image");
82749 handle_initrd();
82750 return 1;
82751 }
82752 }
82753- sys_unlink("/initrd.image");
82754+ sys_unlink((const char __force_user *)"/initrd.image");
82755 return 0;
82756 }
82757diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
82758index 8cb6db5..d729f50 100644
82759--- a/init/do_mounts_md.c
82760+++ b/init/do_mounts_md.c
82761@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
82762 partitioned ? "_d" : "", minor,
82763 md_setup_args[ent].device_names);
82764
82765- fd = sys_open(name, 0, 0);
82766+ fd = sys_open((char __force_user *)name, 0, 0);
82767 if (fd < 0) {
82768 printk(KERN_ERR "md: open failed - cannot start "
82769 "array %s\n", name);
82770@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
82771 * array without it
82772 */
82773 sys_close(fd);
82774- fd = sys_open(name, 0, 0);
82775+ fd = sys_open((char __force_user *)name, 0, 0);
82776 sys_ioctl(fd, BLKRRPART, 0);
82777 }
82778 sys_close(fd);
82779@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
82780
82781 wait_for_device_probe();
82782
82783- fd = sys_open("/dev/md0", 0, 0);
82784+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
82785 if (fd >= 0) {
82786 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
82787 sys_close(fd);
82788diff --git a/init/init_task.c b/init/init_task.c
82789index ba0a7f36..2bcf1d5 100644
82790--- a/init/init_task.c
82791+++ b/init/init_task.c
82792@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
82793 * Initial thread structure. Alignment of this is handled by a special
82794 * linker map entry.
82795 */
82796+#ifdef CONFIG_X86
82797+union thread_union init_thread_union __init_task_data;
82798+#else
82799 union thread_union init_thread_union __init_task_data =
82800 { INIT_THREAD_INFO(init_task) };
82801+#endif
82802diff --git a/init/initramfs.c b/init/initramfs.c
82803index a67ef9d..2d17ed9 100644
82804--- a/init/initramfs.c
82805+++ b/init/initramfs.c
82806@@ -84,7 +84,7 @@ static void __init free_hash(void)
82807 }
82808 }
82809
82810-static long __init do_utime(char *filename, time_t mtime)
82811+static long __init do_utime(char __force_user *filename, time_t mtime)
82812 {
82813 struct timespec t[2];
82814
82815@@ -119,7 +119,7 @@ static void __init dir_utime(void)
82816 struct dir_entry *de, *tmp;
82817 list_for_each_entry_safe(de, tmp, &dir_list, list) {
82818 list_del(&de->list);
82819- do_utime(de->name, de->mtime);
82820+ do_utime((char __force_user *)de->name, de->mtime);
82821 kfree(de->name);
82822 kfree(de);
82823 }
82824@@ -281,7 +281,7 @@ static int __init maybe_link(void)
82825 if (nlink >= 2) {
82826 char *old = find_link(major, minor, ino, mode, collected);
82827 if (old)
82828- return (sys_link(old, collected) < 0) ? -1 : 1;
82829+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
82830 }
82831 return 0;
82832 }
82833@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
82834 {
82835 struct stat st;
82836
82837- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
82838+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
82839 if (S_ISDIR(st.st_mode))
82840- sys_rmdir(path);
82841+ sys_rmdir((char __force_user *)path);
82842 else
82843- sys_unlink(path);
82844+ sys_unlink((char __force_user *)path);
82845 }
82846 }
82847
82848@@ -315,7 +315,7 @@ static int __init do_name(void)
82849 int openflags = O_WRONLY|O_CREAT;
82850 if (ml != 1)
82851 openflags |= O_TRUNC;
82852- wfd = sys_open(collected, openflags, mode);
82853+ wfd = sys_open((char __force_user *)collected, openflags, mode);
82854
82855 if (wfd >= 0) {
82856 sys_fchown(wfd, uid, gid);
82857@@ -327,17 +327,17 @@ static int __init do_name(void)
82858 }
82859 }
82860 } else if (S_ISDIR(mode)) {
82861- sys_mkdir(collected, mode);
82862- sys_chown(collected, uid, gid);
82863- sys_chmod(collected, mode);
82864+ sys_mkdir((char __force_user *)collected, mode);
82865+ sys_chown((char __force_user *)collected, uid, gid);
82866+ sys_chmod((char __force_user *)collected, mode);
82867 dir_add(collected, mtime);
82868 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
82869 S_ISFIFO(mode) || S_ISSOCK(mode)) {
82870 if (maybe_link() == 0) {
82871- sys_mknod(collected, mode, rdev);
82872- sys_chown(collected, uid, gid);
82873- sys_chmod(collected, mode);
82874- do_utime(collected, mtime);
82875+ sys_mknod((char __force_user *)collected, mode, rdev);
82876+ sys_chown((char __force_user *)collected, uid, gid);
82877+ sys_chmod((char __force_user *)collected, mode);
82878+ do_utime((char __force_user *)collected, mtime);
82879 }
82880 }
82881 return 0;
82882@@ -346,15 +346,15 @@ static int __init do_name(void)
82883 static int __init do_copy(void)
82884 {
82885 if (count >= body_len) {
82886- sys_write(wfd, victim, body_len);
82887+ sys_write(wfd, (char __force_user *)victim, body_len);
82888 sys_close(wfd);
82889- do_utime(vcollected, mtime);
82890+ do_utime((char __force_user *)vcollected, mtime);
82891 kfree(vcollected);
82892 eat(body_len);
82893 state = SkipIt;
82894 return 0;
82895 } else {
82896- sys_write(wfd, victim, count);
82897+ sys_write(wfd, (char __force_user *)victim, count);
82898 body_len -= count;
82899 eat(count);
82900 return 1;
82901@@ -365,9 +365,9 @@ static int __init do_symlink(void)
82902 {
82903 collected[N_ALIGN(name_len) + body_len] = '\0';
82904 clean_path(collected, 0);
82905- sys_symlink(collected + N_ALIGN(name_len), collected);
82906- sys_lchown(collected, uid, gid);
82907- do_utime(collected, mtime);
82908+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
82909+ sys_lchown((char __force_user *)collected, uid, gid);
82910+ do_utime((char __force_user *)collected, mtime);
82911 state = SkipIt;
82912 next_state = Reset;
82913 return 0;
82914@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
82915 {
82916 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
82917 if (err)
82918- panic(err); /* Failed to decompress INTERNAL initramfs */
82919+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
82920 if (initrd_start) {
82921 #ifdef CONFIG_BLK_DEV_RAM
82922 int fd;
82923diff --git a/init/main.c b/init/main.c
82924index febc511..f0851763 100644
82925--- a/init/main.c
82926+++ b/init/main.c
82927@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
82928 extern void tc_init(void);
82929 #endif
82930
82931+extern void grsecurity_init(void);
82932+
82933 /*
82934 * Debug helper: via this flag we know that we are in 'early bootup code'
82935 * where only the boot processor is running with IRQ disabled. This means
82936@@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
82937
82938 __setup("reset_devices", set_reset_devices);
82939
82940+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82941+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
82942+static int __init setup_grsec_proc_gid(char *str)
82943+{
82944+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
82945+ return 1;
82946+}
82947+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
82948+#endif
82949+
82950+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
82951+unsigned long pax_user_shadow_base __read_only;
82952+EXPORT_SYMBOL(pax_user_shadow_base);
82953+extern char pax_enter_kernel_user[];
82954+extern char pax_exit_kernel_user[];
82955+#endif
82956+
82957+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
82958+static int __init setup_pax_nouderef(char *str)
82959+{
82960+#ifdef CONFIG_X86_32
82961+ unsigned int cpu;
82962+ struct desc_struct *gdt;
82963+
82964+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
82965+ gdt = get_cpu_gdt_table(cpu);
82966+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
82967+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
82968+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
82969+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
82970+ }
82971+ loadsegment(ds, __KERNEL_DS);
82972+ loadsegment(es, __KERNEL_DS);
82973+ loadsegment(ss, __KERNEL_DS);
82974+#else
82975+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
82976+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
82977+ clone_pgd_mask = ~(pgdval_t)0UL;
82978+ pax_user_shadow_base = 0UL;
82979+ setup_clear_cpu_cap(X86_FEATURE_PCID);
82980+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
82981+#endif
82982+
82983+ return 0;
82984+}
82985+early_param("pax_nouderef", setup_pax_nouderef);
82986+
82987+#ifdef CONFIG_X86_64
82988+static int __init setup_pax_weakuderef(char *str)
82989+{
82990+ if (clone_pgd_mask != ~(pgdval_t)0UL)
82991+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
82992+ return 1;
82993+}
82994+__setup("pax_weakuderef", setup_pax_weakuderef);
82995+#endif
82996+#endif
82997+
82998+#ifdef CONFIG_PAX_SOFTMODE
82999+int pax_softmode;
83000+
83001+static int __init setup_pax_softmode(char *str)
83002+{
83003+ get_option(&str, &pax_softmode);
83004+ return 1;
83005+}
83006+__setup("pax_softmode=", setup_pax_softmode);
83007+#endif
83008+
83009 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
83010 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
83011 static const char *panic_later, *panic_param;
83012@@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
83013 {
83014 int count = preempt_count();
83015 int ret;
83016- char msgbuf[64];
83017+ const char *msg1 = "", *msg2 = "";
83018
83019 if (initcall_debug)
83020 ret = do_one_initcall_debug(fn);
83021 else
83022 ret = fn();
83023
83024- msgbuf[0] = 0;
83025-
83026 if (preempt_count() != count) {
83027- sprintf(msgbuf, "preemption imbalance ");
83028+ msg1 = " preemption imbalance";
83029 preempt_count_set(count);
83030 }
83031 if (irqs_disabled()) {
83032- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
83033+ msg2 = " disabled interrupts";
83034 local_irq_enable();
83035 }
83036- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
83037+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
83038
83039+ add_latent_entropy();
83040 return ret;
83041 }
83042
83043@@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
83044 {
83045 argv_init[0] = init_filename;
83046 return do_execve(init_filename,
83047- (const char __user *const __user *)argv_init,
83048- (const char __user *const __user *)envp_init);
83049+ (const char __user *const __force_user *)argv_init,
83050+ (const char __user *const __force_user *)envp_init);
83051 }
83052
83053 static int try_to_run_init_process(const char *init_filename)
83054@@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
83055 return ret;
83056 }
83057
83058+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83059+extern int gr_init_ran;
83060+#endif
83061+
83062 static noinline void __init kernel_init_freeable(void);
83063
83064 static int __ref kernel_init(void *unused)
83065@@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
83066 ramdisk_execute_command, ret);
83067 }
83068
83069+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83070+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
83071+ gr_init_ran = 1;
83072+#endif
83073+
83074 /*
83075 * We try each of these until one succeeds.
83076 *
83077@@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
83078 do_basic_setup();
83079
83080 /* Open the /dev/console on the rootfs, this should never fail */
83081- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
83082+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
83083 pr_err("Warning: unable to open an initial console.\n");
83084
83085 (void) sys_dup(0);
83086@@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
83087 if (!ramdisk_execute_command)
83088 ramdisk_execute_command = "/init";
83089
83090- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
83091+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
83092 ramdisk_execute_command = NULL;
83093 prepare_namespace();
83094 }
83095
83096+ grsecurity_init();
83097+
83098 /*
83099 * Ok, we have completed the initial bootup, and
83100 * we're essentially up and running. Get rid of the
83101diff --git a/ipc/compat.c b/ipc/compat.c
83102index 892f658..e7c6320 100644
83103--- a/ipc/compat.c
83104+++ b/ipc/compat.c
83105@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
83106 COMPAT_SHMLBA);
83107 if (err < 0)
83108 return err;
83109- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
83110+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
83111 }
83112 case SHMDT:
83113 return sys_shmdt(compat_ptr(ptr));
83114diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
83115index b0e99de..09f385c 100644
83116--- a/ipc/ipc_sysctl.c
83117+++ b/ipc/ipc_sysctl.c
83118@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
83119 static int proc_ipc_dointvec(ctl_table *table, int write,
83120 void __user *buffer, size_t *lenp, loff_t *ppos)
83121 {
83122- struct ctl_table ipc_table;
83123+ ctl_table_no_const ipc_table;
83124
83125 memcpy(&ipc_table, table, sizeof(ipc_table));
83126 ipc_table.data = get_ipc(table);
83127@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
83128 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
83129 void __user *buffer, size_t *lenp, loff_t *ppos)
83130 {
83131- struct ctl_table ipc_table;
83132+ ctl_table_no_const ipc_table;
83133
83134 memcpy(&ipc_table, table, sizeof(ipc_table));
83135 ipc_table.data = get_ipc(table);
83136@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
83137 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83138 void __user *buffer, size_t *lenp, loff_t *ppos)
83139 {
83140- struct ctl_table ipc_table;
83141+ ctl_table_no_const ipc_table;
83142 size_t lenp_bef = *lenp;
83143 int rc;
83144
83145@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83146 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
83147 void __user *buffer, size_t *lenp, loff_t *ppos)
83148 {
83149- struct ctl_table ipc_table;
83150+ ctl_table_no_const ipc_table;
83151 memcpy(&ipc_table, table, sizeof(ipc_table));
83152 ipc_table.data = get_ipc(table);
83153
83154@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
83155 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
83156 void __user *buffer, size_t *lenp, loff_t *ppos)
83157 {
83158- struct ctl_table ipc_table;
83159+ ctl_table_no_const ipc_table;
83160 size_t lenp_bef = *lenp;
83161 int oldval;
83162 int rc;
83163diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
83164index 383d638..943fdbb 100644
83165--- a/ipc/mq_sysctl.c
83166+++ b/ipc/mq_sysctl.c
83167@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
83168 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
83169 void __user *buffer, size_t *lenp, loff_t *ppos)
83170 {
83171- struct ctl_table mq_table;
83172+ ctl_table_no_const mq_table;
83173 memcpy(&mq_table, table, sizeof(mq_table));
83174 mq_table.data = get_mq(table);
83175
83176diff --git a/ipc/mqueue.c b/ipc/mqueue.c
83177index 95827ce..09e6d38 100644
83178--- a/ipc/mqueue.c
83179+++ b/ipc/mqueue.c
83180@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
83181 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
83182 info->attr.mq_msgsize);
83183
83184+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
83185 spin_lock(&mq_lock);
83186 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
83187 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
83188diff --git a/ipc/msg.c b/ipc/msg.c
83189index 558aa91..359e718 100644
83190--- a/ipc/msg.c
83191+++ b/ipc/msg.c
83192@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
83193 return security_msg_queue_associate(msq, msgflg);
83194 }
83195
83196+static struct ipc_ops msg_ops = {
83197+ .getnew = newque,
83198+ .associate = msg_security,
83199+ .more_checks = NULL
83200+};
83201+
83202 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
83203 {
83204 struct ipc_namespace *ns;
83205- struct ipc_ops msg_ops;
83206 struct ipc_params msg_params;
83207
83208 ns = current->nsproxy->ipc_ns;
83209
83210- msg_ops.getnew = newque;
83211- msg_ops.associate = msg_security;
83212- msg_ops.more_checks = NULL;
83213-
83214 msg_params.key = key;
83215 msg_params.flg = msgflg;
83216
83217diff --git a/ipc/sem.c b/ipc/sem.c
83218index db9d241..bc8427c 100644
83219--- a/ipc/sem.c
83220+++ b/ipc/sem.c
83221@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
83222 return 0;
83223 }
83224
83225+static struct ipc_ops sem_ops = {
83226+ .getnew = newary,
83227+ .associate = sem_security,
83228+ .more_checks = sem_more_checks
83229+};
83230+
83231 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83232 {
83233 struct ipc_namespace *ns;
83234- struct ipc_ops sem_ops;
83235 struct ipc_params sem_params;
83236
83237 ns = current->nsproxy->ipc_ns;
83238@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83239 if (nsems < 0 || nsems > ns->sc_semmsl)
83240 return -EINVAL;
83241
83242- sem_ops.getnew = newary;
83243- sem_ops.associate = sem_security;
83244- sem_ops.more_checks = sem_more_checks;
83245-
83246 sem_params.key = key;
83247 sem_params.flg = semflg;
83248 sem_params.u.nsems = nsems;
83249diff --git a/ipc/shm.c b/ipc/shm.c
83250index 7a51443..3a257d8 100644
83251--- a/ipc/shm.c
83252+++ b/ipc/shm.c
83253@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
83254 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
83255 #endif
83256
83257+#ifdef CONFIG_GRKERNSEC
83258+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83259+ const time_t shm_createtime, const kuid_t cuid,
83260+ const int shmid);
83261+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83262+ const time_t shm_createtime);
83263+#endif
83264+
83265 void shm_init_ns(struct ipc_namespace *ns)
83266 {
83267 ns->shm_ctlmax = SHMMAX;
83268@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
83269 shp->shm_lprid = 0;
83270 shp->shm_atim = shp->shm_dtim = 0;
83271 shp->shm_ctim = get_seconds();
83272+#ifdef CONFIG_GRKERNSEC
83273+ {
83274+ struct timespec timeval;
83275+ do_posix_clock_monotonic_gettime(&timeval);
83276+
83277+ shp->shm_createtime = timeval.tv_sec;
83278+ }
83279+#endif
83280 shp->shm_segsz = size;
83281 shp->shm_nattch = 0;
83282 shp->shm_file = file;
83283@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
83284 return 0;
83285 }
83286
83287+static struct ipc_ops shm_ops = {
83288+ .getnew = newseg,
83289+ .associate = shm_security,
83290+ .more_checks = shm_more_checks
83291+};
83292+
83293 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
83294 {
83295 struct ipc_namespace *ns;
83296- struct ipc_ops shm_ops;
83297 struct ipc_params shm_params;
83298
83299 ns = current->nsproxy->ipc_ns;
83300
83301- shm_ops.getnew = newseg;
83302- shm_ops.associate = shm_security;
83303- shm_ops.more_checks = shm_more_checks;
83304-
83305 shm_params.key = key;
83306 shm_params.flg = shmflg;
83307 shm_params.u.size = size;
83308@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83309 f_mode = FMODE_READ | FMODE_WRITE;
83310 }
83311 if (shmflg & SHM_EXEC) {
83312+
83313+#ifdef CONFIG_PAX_MPROTECT
83314+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
83315+ goto out;
83316+#endif
83317+
83318 prot |= PROT_EXEC;
83319 acc_mode |= S_IXUGO;
83320 }
83321@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83322 if (err)
83323 goto out_unlock;
83324
83325+#ifdef CONFIG_GRKERNSEC
83326+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
83327+ shp->shm_perm.cuid, shmid) ||
83328+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
83329+ err = -EACCES;
83330+ goto out_unlock;
83331+ }
83332+#endif
83333+
83334 ipc_lock_object(&shp->shm_perm);
83335
83336 /* check if shm_destroy() is tearing down shp */
83337@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83338 path = shp->shm_file->f_path;
83339 path_get(&path);
83340 shp->shm_nattch++;
83341+#ifdef CONFIG_GRKERNSEC
83342+ shp->shm_lapid = current->pid;
83343+#endif
83344 size = i_size_read(path.dentry->d_inode);
83345 ipc_unlock_object(&shp->shm_perm);
83346 rcu_read_unlock();
83347diff --git a/ipc/util.c b/ipc/util.c
83348index 3ae17a4..d67c32f 100644
83349--- a/ipc/util.c
83350+++ b/ipc/util.c
83351@@ -71,6 +71,8 @@ struct ipc_proc_iface {
83352 int (*show)(struct seq_file *, void *);
83353 };
83354
83355+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
83356+
83357 static void ipc_memory_notifier(struct work_struct *work)
83358 {
83359 ipcns_notify(IPCNS_MEMCHANGED);
83360@@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
83361 granted_mode >>= 6;
83362 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
83363 granted_mode >>= 3;
83364+
83365+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
83366+ return -1;
83367+
83368 /* is there some bit set in requested_mode but not in granted_mode? */
83369 if ((requested_mode & ~granted_mode & 0007) &&
83370 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
83371diff --git a/kernel/acct.c b/kernel/acct.c
83372index 8d6e145..33e0b1e 100644
83373--- a/kernel/acct.c
83374+++ b/kernel/acct.c
83375@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
83376 */
83377 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
83378 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
83379- file->f_op->write(file, (char *)&ac,
83380+ file->f_op->write(file, (char __force_user *)&ac,
83381 sizeof(acct_t), &file->f_pos);
83382 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
83383 set_fs(fs);
83384diff --git a/kernel/audit.c b/kernel/audit.c
83385index 906ae5a0..a7ad0b4 100644
83386--- a/kernel/audit.c
83387+++ b/kernel/audit.c
83388@@ -117,7 +117,7 @@ u32 audit_sig_sid = 0;
83389 3) suppressed due to audit_rate_limit
83390 4) suppressed due to audit_backlog_limit
83391 */
83392-static atomic_t audit_lost = ATOMIC_INIT(0);
83393+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
83394
83395 /* The netlink socket. */
83396 static struct sock *audit_sock;
83397@@ -250,7 +250,7 @@ void audit_log_lost(const char *message)
83398 unsigned long now;
83399 int print;
83400
83401- atomic_inc(&audit_lost);
83402+ atomic_inc_unchecked(&audit_lost);
83403
83404 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
83405
83406@@ -269,7 +269,7 @@ void audit_log_lost(const char *message)
83407 printk(KERN_WARNING
83408 "audit: audit_lost=%d audit_rate_limit=%d "
83409 "audit_backlog_limit=%d\n",
83410- atomic_read(&audit_lost),
83411+ atomic_read_unchecked(&audit_lost),
83412 audit_rate_limit,
83413 audit_backlog_limit);
83414 audit_panic(message);
83415@@ -765,7 +765,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
83416 status_set.pid = audit_pid;
83417 status_set.rate_limit = audit_rate_limit;
83418 status_set.backlog_limit = audit_backlog_limit;
83419- status_set.lost = atomic_read(&audit_lost);
83420+ status_set.lost = atomic_read_unchecked(&audit_lost);
83421 status_set.backlog = skb_queue_len(&audit_skb_queue);
83422 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
83423 &status_set, sizeof(status_set));
83424@@ -1356,7 +1356,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
83425 int i, avail, new_len;
83426 unsigned char *ptr;
83427 struct sk_buff *skb;
83428- static const unsigned char *hex = "0123456789ABCDEF";
83429+ static const unsigned char hex[] = "0123456789ABCDEF";
83430
83431 if (!ab)
83432 return;
83433diff --git a/kernel/auditsc.c b/kernel/auditsc.c
83434index 90594c9..abbeed7 100644
83435--- a/kernel/auditsc.c
83436+++ b/kernel/auditsc.c
83437@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
83438 }
83439
83440 /* global counter which is incremented every time something logs in */
83441-static atomic_t session_id = ATOMIC_INIT(0);
83442+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
83443
83444 static int audit_set_loginuid_perm(kuid_t loginuid)
83445 {
83446@@ -2008,7 +2008,7 @@ int audit_set_loginuid(kuid_t loginuid)
83447
83448 /* are we setting or clearing? */
83449 if (uid_valid(loginuid))
83450- sessionid = atomic_inc_return(&session_id);
83451+ sessionid = atomic_inc_return_unchecked(&session_id);
83452
83453 task->sessionid = sessionid;
83454 task->loginuid = loginuid;
83455diff --git a/kernel/capability.c b/kernel/capability.c
83456index 4e66bf9..cdccecf 100644
83457--- a/kernel/capability.c
83458+++ b/kernel/capability.c
83459@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
83460 * before modification is attempted and the application
83461 * fails.
83462 */
83463+ if (tocopy > ARRAY_SIZE(kdata))
83464+ return -EFAULT;
83465+
83466 if (copy_to_user(dataptr, kdata, tocopy
83467 * sizeof(struct __user_cap_data_struct))) {
83468 return -EFAULT;
83469@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
83470 int ret;
83471
83472 rcu_read_lock();
83473- ret = security_capable(__task_cred(t), ns, cap);
83474+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
83475+ gr_task_is_capable(t, __task_cred(t), cap);
83476 rcu_read_unlock();
83477
83478- return (ret == 0);
83479+ return ret;
83480 }
83481
83482 /**
83483@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
83484 int ret;
83485
83486 rcu_read_lock();
83487- ret = security_capable_noaudit(__task_cred(t), ns, cap);
83488+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
83489 rcu_read_unlock();
83490
83491- return (ret == 0);
83492+ return ret;
83493 }
83494
83495 /**
83496@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
83497 BUG();
83498 }
83499
83500- if (security_capable(current_cred(), ns, cap) == 0) {
83501+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
83502 current->flags |= PF_SUPERPRIV;
83503 return true;
83504 }
83505@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
83506 }
83507 EXPORT_SYMBOL(ns_capable);
83508
83509+bool ns_capable_nolog(struct user_namespace *ns, int cap)
83510+{
83511+ if (unlikely(!cap_valid(cap))) {
83512+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
83513+ BUG();
83514+ }
83515+
83516+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
83517+ current->flags |= PF_SUPERPRIV;
83518+ return true;
83519+ }
83520+ return false;
83521+}
83522+EXPORT_SYMBOL(ns_capable_nolog);
83523+
83524 /**
83525 * file_ns_capable - Determine if the file's opener had a capability in effect
83526 * @file: The file we want to check
83527@@ -432,6 +451,12 @@ bool capable(int cap)
83528 }
83529 EXPORT_SYMBOL(capable);
83530
83531+bool capable_nolog(int cap)
83532+{
83533+ return ns_capable_nolog(&init_user_ns, cap);
83534+}
83535+EXPORT_SYMBOL(capable_nolog);
83536+
83537 /**
83538 * inode_capable - Check superior capability over inode
83539 * @inode: The inode in question
83540@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
83541 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83542 }
83543 EXPORT_SYMBOL(inode_capable);
83544+
83545+bool inode_capable_nolog(const struct inode *inode, int cap)
83546+{
83547+ struct user_namespace *ns = current_user_ns();
83548+
83549+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83550+}
83551+EXPORT_SYMBOL(inode_capable_nolog);
83552diff --git a/kernel/cgroup.c b/kernel/cgroup.c
83553index bc1dcab..f3a6b42 100644
83554--- a/kernel/cgroup.c
83555+++ b/kernel/cgroup.c
83556@@ -5607,7 +5607,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
83557 struct css_set *cset = link->cset;
83558 struct task_struct *task;
83559 int count = 0;
83560- seq_printf(seq, "css_set %p\n", cset);
83561+ seq_printf(seq, "css_set %pK\n", cset);
83562 list_for_each_entry(task, &cset->tasks, cg_list) {
83563 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
83564 seq_puts(seq, " ...\n");
83565diff --git a/kernel/compat.c b/kernel/compat.c
83566index 0a09e48..b46b3d78 100644
83567--- a/kernel/compat.c
83568+++ b/kernel/compat.c
83569@@ -13,6 +13,7 @@
83570
83571 #include <linux/linkage.h>
83572 #include <linux/compat.h>
83573+#include <linux/module.h>
83574 #include <linux/errno.h>
83575 #include <linux/time.h>
83576 #include <linux/signal.h>
83577@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
83578 mm_segment_t oldfs;
83579 long ret;
83580
83581- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
83582+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
83583 oldfs = get_fs();
83584 set_fs(KERNEL_DS);
83585 ret = hrtimer_nanosleep_restart(restart);
83586@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
83587 oldfs = get_fs();
83588 set_fs(KERNEL_DS);
83589 ret = hrtimer_nanosleep(&tu,
83590- rmtp ? (struct timespec __user *)&rmt : NULL,
83591+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
83592 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
83593 set_fs(oldfs);
83594
83595@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
83596 mm_segment_t old_fs = get_fs();
83597
83598 set_fs(KERNEL_DS);
83599- ret = sys_sigpending((old_sigset_t __user *) &s);
83600+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
83601 set_fs(old_fs);
83602 if (ret == 0)
83603 ret = put_user(s, set);
83604@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
83605 mm_segment_t old_fs = get_fs();
83606
83607 set_fs(KERNEL_DS);
83608- ret = sys_old_getrlimit(resource, &r);
83609+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
83610 set_fs(old_fs);
83611
83612 if (!ret) {
83613@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
83614 set_fs (KERNEL_DS);
83615 ret = sys_wait4(pid,
83616 (stat_addr ?
83617- (unsigned int __user *) &status : NULL),
83618- options, (struct rusage __user *) &r);
83619+ (unsigned int __force_user *) &status : NULL),
83620+ options, (struct rusage __force_user *) &r);
83621 set_fs (old_fs);
83622
83623 if (ret > 0) {
83624@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
83625 memset(&info, 0, sizeof(info));
83626
83627 set_fs(KERNEL_DS);
83628- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
83629- uru ? (struct rusage __user *)&ru : NULL);
83630+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
83631+ uru ? (struct rusage __force_user *)&ru : NULL);
83632 set_fs(old_fs);
83633
83634 if ((ret < 0) || (info.si_signo == 0))
83635@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
83636 oldfs = get_fs();
83637 set_fs(KERNEL_DS);
83638 err = sys_timer_settime(timer_id, flags,
83639- (struct itimerspec __user *) &newts,
83640- (struct itimerspec __user *) &oldts);
83641+ (struct itimerspec __force_user *) &newts,
83642+ (struct itimerspec __force_user *) &oldts);
83643 set_fs(oldfs);
83644 if (!err && old && put_compat_itimerspec(old, &oldts))
83645 return -EFAULT;
83646@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
83647 oldfs = get_fs();
83648 set_fs(KERNEL_DS);
83649 err = sys_timer_gettime(timer_id,
83650- (struct itimerspec __user *) &ts);
83651+ (struct itimerspec __force_user *) &ts);
83652 set_fs(oldfs);
83653 if (!err && put_compat_itimerspec(setting, &ts))
83654 return -EFAULT;
83655@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
83656 oldfs = get_fs();
83657 set_fs(KERNEL_DS);
83658 err = sys_clock_settime(which_clock,
83659- (struct timespec __user *) &ts);
83660+ (struct timespec __force_user *) &ts);
83661 set_fs(oldfs);
83662 return err;
83663 }
83664@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
83665 oldfs = get_fs();
83666 set_fs(KERNEL_DS);
83667 err = sys_clock_gettime(which_clock,
83668- (struct timespec __user *) &ts);
83669+ (struct timespec __force_user *) &ts);
83670 set_fs(oldfs);
83671 if (!err && put_compat_timespec(&ts, tp))
83672 return -EFAULT;
83673@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
83674
83675 oldfs = get_fs();
83676 set_fs(KERNEL_DS);
83677- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
83678+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
83679 set_fs(oldfs);
83680
83681 err = compat_put_timex(utp, &txc);
83682@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
83683 oldfs = get_fs();
83684 set_fs(KERNEL_DS);
83685 err = sys_clock_getres(which_clock,
83686- (struct timespec __user *) &ts);
83687+ (struct timespec __force_user *) &ts);
83688 set_fs(oldfs);
83689 if (!err && tp && put_compat_timespec(&ts, tp))
83690 return -EFAULT;
83691@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
83692 long err;
83693 mm_segment_t oldfs;
83694 struct timespec tu;
83695- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
83696+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
83697
83698- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
83699+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
83700 oldfs = get_fs();
83701 set_fs(KERNEL_DS);
83702 err = clock_nanosleep_restart(restart);
83703@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
83704 oldfs = get_fs();
83705 set_fs(KERNEL_DS);
83706 err = sys_clock_nanosleep(which_clock, flags,
83707- (struct timespec __user *) &in,
83708- (struct timespec __user *) &out);
83709+ (struct timespec __force_user *) &in,
83710+ (struct timespec __force_user *) &out);
83711 set_fs(oldfs);
83712
83713 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
83714@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
83715 mm_segment_t old_fs = get_fs();
83716
83717 set_fs(KERNEL_DS);
83718- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
83719+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
83720 set_fs(old_fs);
83721 if (put_compat_timespec(&t, interval))
83722 return -EFAULT;
83723diff --git a/kernel/configs.c b/kernel/configs.c
83724index c18b1f1..b9a0132 100644
83725--- a/kernel/configs.c
83726+++ b/kernel/configs.c
83727@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
83728 struct proc_dir_entry *entry;
83729
83730 /* create the current config file */
83731+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
83732+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
83733+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
83734+ &ikconfig_file_ops);
83735+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83736+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
83737+ &ikconfig_file_ops);
83738+#endif
83739+#else
83740 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
83741 &ikconfig_file_ops);
83742+#endif
83743+
83744 if (!entry)
83745 return -ENOMEM;
83746
83747diff --git a/kernel/cred.c b/kernel/cred.c
83748index e0573a4..3874e41 100644
83749--- a/kernel/cred.c
83750+++ b/kernel/cred.c
83751@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
83752 validate_creds(cred);
83753 alter_cred_subscribers(cred, -1);
83754 put_cred(cred);
83755+
83756+#ifdef CONFIG_GRKERNSEC_SETXID
83757+ cred = (struct cred *) tsk->delayed_cred;
83758+ if (cred != NULL) {
83759+ tsk->delayed_cred = NULL;
83760+ validate_creds(cred);
83761+ alter_cred_subscribers(cred, -1);
83762+ put_cred(cred);
83763+ }
83764+#endif
83765 }
83766
83767 /**
83768@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
83769 * Always returns 0 thus allowing this function to be tail-called at the end
83770 * of, say, sys_setgid().
83771 */
83772-int commit_creds(struct cred *new)
83773+static int __commit_creds(struct cred *new)
83774 {
83775 struct task_struct *task = current;
83776 const struct cred *old = task->real_cred;
83777@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
83778
83779 get_cred(new); /* we will require a ref for the subj creds too */
83780
83781+ gr_set_role_label(task, new->uid, new->gid);
83782+
83783 /* dumpability changes */
83784 if (!uid_eq(old->euid, new->euid) ||
83785 !gid_eq(old->egid, new->egid) ||
83786@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
83787 put_cred(old);
83788 return 0;
83789 }
83790+#ifdef CONFIG_GRKERNSEC_SETXID
83791+extern int set_user(struct cred *new);
83792+
83793+void gr_delayed_cred_worker(void)
83794+{
83795+ const struct cred *new = current->delayed_cred;
83796+ struct cred *ncred;
83797+
83798+ current->delayed_cred = NULL;
83799+
83800+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
83801+ // from doing get_cred on it when queueing this
83802+ put_cred(new);
83803+ return;
83804+ } else if (new == NULL)
83805+ return;
83806+
83807+ ncred = prepare_creds();
83808+ if (!ncred)
83809+ goto die;
83810+ // uids
83811+ ncred->uid = new->uid;
83812+ ncred->euid = new->euid;
83813+ ncred->suid = new->suid;
83814+ ncred->fsuid = new->fsuid;
83815+ // gids
83816+ ncred->gid = new->gid;
83817+ ncred->egid = new->egid;
83818+ ncred->sgid = new->sgid;
83819+ ncred->fsgid = new->fsgid;
83820+ // groups
83821+ if (set_groups(ncred, new->group_info) < 0) {
83822+ abort_creds(ncred);
83823+ goto die;
83824+ }
83825+ // caps
83826+ ncred->securebits = new->securebits;
83827+ ncred->cap_inheritable = new->cap_inheritable;
83828+ ncred->cap_permitted = new->cap_permitted;
83829+ ncred->cap_effective = new->cap_effective;
83830+ ncred->cap_bset = new->cap_bset;
83831+
83832+ if (set_user(ncred)) {
83833+ abort_creds(ncred);
83834+ goto die;
83835+ }
83836+
83837+ // from doing get_cred on it when queueing this
83838+ put_cred(new);
83839+
83840+ __commit_creds(ncred);
83841+ return;
83842+die:
83843+ // from doing get_cred on it when queueing this
83844+ put_cred(new);
83845+ do_group_exit(SIGKILL);
83846+}
83847+#endif
83848+
83849+int commit_creds(struct cred *new)
83850+{
83851+#ifdef CONFIG_GRKERNSEC_SETXID
83852+ int ret;
83853+ int schedule_it = 0;
83854+ struct task_struct *t;
83855+
83856+ /* we won't get called with tasklist_lock held for writing
83857+ and interrupts disabled as the cred struct in that case is
83858+ init_cred
83859+ */
83860+ if (grsec_enable_setxid && !current_is_single_threaded() &&
83861+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
83862+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
83863+ schedule_it = 1;
83864+ }
83865+ ret = __commit_creds(new);
83866+ if (schedule_it) {
83867+ rcu_read_lock();
83868+ read_lock(&tasklist_lock);
83869+ for (t = next_thread(current); t != current;
83870+ t = next_thread(t)) {
83871+ if (t->delayed_cred == NULL) {
83872+ t->delayed_cred = get_cred(new);
83873+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
83874+ set_tsk_need_resched(t);
83875+ }
83876+ }
83877+ read_unlock(&tasklist_lock);
83878+ rcu_read_unlock();
83879+ }
83880+ return ret;
83881+#else
83882+ return __commit_creds(new);
83883+#endif
83884+}
83885+
83886 EXPORT_SYMBOL(commit_creds);
83887
83888 /**
83889diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
83890index 7d2f35e..1bafcd0 100644
83891--- a/kernel/debug/debug_core.c
83892+++ b/kernel/debug/debug_core.c
83893@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
83894 */
83895 static atomic_t masters_in_kgdb;
83896 static atomic_t slaves_in_kgdb;
83897-static atomic_t kgdb_break_tasklet_var;
83898+static atomic_unchecked_t kgdb_break_tasklet_var;
83899 atomic_t kgdb_setting_breakpoint;
83900
83901 struct task_struct *kgdb_usethread;
83902@@ -133,7 +133,7 @@ int kgdb_single_step;
83903 static pid_t kgdb_sstep_pid;
83904
83905 /* to keep track of the CPU which is doing the single stepping*/
83906-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
83907+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
83908
83909 /*
83910 * If you are debugging a problem where roundup (the collection of
83911@@ -541,7 +541,7 @@ return_normal:
83912 * kernel will only try for the value of sstep_tries before
83913 * giving up and continuing on.
83914 */
83915- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
83916+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
83917 (kgdb_info[cpu].task &&
83918 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
83919 atomic_set(&kgdb_active, -1);
83920@@ -639,8 +639,8 @@ cpu_master_loop:
83921 }
83922
83923 kgdb_restore:
83924- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
83925- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
83926+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
83927+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
83928 if (kgdb_info[sstep_cpu].task)
83929 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
83930 else
83931@@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
83932 static void kgdb_tasklet_bpt(unsigned long ing)
83933 {
83934 kgdb_breakpoint();
83935- atomic_set(&kgdb_break_tasklet_var, 0);
83936+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
83937 }
83938
83939 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
83940
83941 void kgdb_schedule_breakpoint(void)
83942 {
83943- if (atomic_read(&kgdb_break_tasklet_var) ||
83944+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
83945 atomic_read(&kgdb_active) != -1 ||
83946 atomic_read(&kgdb_setting_breakpoint))
83947 return;
83948- atomic_inc(&kgdb_break_tasklet_var);
83949+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
83950 tasklet_schedule(&kgdb_tasklet_breakpoint);
83951 }
83952 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
83953diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
83954index 0b097c8..11dd5c5 100644
83955--- a/kernel/debug/kdb/kdb_main.c
83956+++ b/kernel/debug/kdb/kdb_main.c
83957@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
83958 continue;
83959
83960 kdb_printf("%-20s%8u 0x%p ", mod->name,
83961- mod->core_size, (void *)mod);
83962+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
83963 #ifdef CONFIG_MODULE_UNLOAD
83964 kdb_printf("%4ld ", module_refcount(mod));
83965 #endif
83966@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
83967 kdb_printf(" (Loading)");
83968 else
83969 kdb_printf(" (Live)");
83970- kdb_printf(" 0x%p", mod->module_core);
83971+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
83972
83973 #ifdef CONFIG_MODULE_UNLOAD
83974 {
83975diff --git a/kernel/events/core.c b/kernel/events/core.c
83976index f574401..11b21f0 100644
83977--- a/kernel/events/core.c
83978+++ b/kernel/events/core.c
83979@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
83980 * 0 - disallow raw tracepoint access for unpriv
83981 * 1 - disallow cpu events for unpriv
83982 * 2 - disallow kernel profiling for unpriv
83983+ * 3 - disallow all unpriv perf event use
83984 */
83985-int sysctl_perf_event_paranoid __read_mostly = 1;
83986+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
83987+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
83988+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
83989+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
83990+#else
83991+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
83992+#endif
83993
83994 /* Minimum for 512 kiB + 1 user control page */
83995 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
83996@@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
83997
83998 tmp *= sysctl_perf_cpu_time_max_percent;
83999 do_div(tmp, 100);
84000- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
84001+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
84002 }
84003
84004 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
84005@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
84006 update_perf_cpu_limits();
84007 }
84008
84009-static atomic64_t perf_event_id;
84010+static atomic64_unchecked_t perf_event_id;
84011
84012 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
84013 enum event_type_t event_type);
84014@@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
84015
84016 static inline u64 perf_event_count(struct perf_event *event)
84017 {
84018- return local64_read(&event->count) + atomic64_read(&event->child_count);
84019+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
84020 }
84021
84022 static u64 perf_event_read(struct perf_event *event)
84023@@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
84024 mutex_lock(&event->child_mutex);
84025 total += perf_event_read(event);
84026 *enabled += event->total_time_enabled +
84027- atomic64_read(&event->child_total_time_enabled);
84028+ atomic64_read_unchecked(&event->child_total_time_enabled);
84029 *running += event->total_time_running +
84030- atomic64_read(&event->child_total_time_running);
84031+ atomic64_read_unchecked(&event->child_total_time_running);
84032
84033 list_for_each_entry(child, &event->child_list, child_list) {
84034 total += perf_event_read(child);
84035@@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
84036 userpg->offset -= local64_read(&event->hw.prev_count);
84037
84038 userpg->time_enabled = enabled +
84039- atomic64_read(&event->child_total_time_enabled);
84040+ atomic64_read_unchecked(&event->child_total_time_enabled);
84041
84042 userpg->time_running = running +
84043- atomic64_read(&event->child_total_time_running);
84044+ atomic64_read_unchecked(&event->child_total_time_running);
84045
84046 arch_perf_update_userpage(userpg, now);
84047
84048@@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
84049
84050 /* Data. */
84051 sp = perf_user_stack_pointer(regs);
84052- rem = __output_copy_user(handle, (void *) sp, dump_size);
84053+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
84054 dyn_size = dump_size - rem;
84055
84056 perf_output_skip(handle, rem);
84057@@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
84058 values[n++] = perf_event_count(event);
84059 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
84060 values[n++] = enabled +
84061- atomic64_read(&event->child_total_time_enabled);
84062+ atomic64_read_unchecked(&event->child_total_time_enabled);
84063 }
84064 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
84065 values[n++] = running +
84066- atomic64_read(&event->child_total_time_running);
84067+ atomic64_read_unchecked(&event->child_total_time_running);
84068 }
84069 if (read_format & PERF_FORMAT_ID)
84070 values[n++] = primary_event_id(event);
84071@@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
84072 event->parent = parent_event;
84073
84074 event->ns = get_pid_ns(task_active_pid_ns(current));
84075- event->id = atomic64_inc_return(&perf_event_id);
84076+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
84077
84078 event->state = PERF_EVENT_STATE_INACTIVE;
84079
84080@@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
84081 if (flags & ~PERF_FLAG_ALL)
84082 return -EINVAL;
84083
84084+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84085+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
84086+ return -EACCES;
84087+#endif
84088+
84089 err = perf_copy_attr(attr_uptr, &attr);
84090 if (err)
84091 return err;
84092@@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
84093 /*
84094 * Add back the child's count to the parent's count:
84095 */
84096- atomic64_add(child_val, &parent_event->child_count);
84097- atomic64_add(child_event->total_time_enabled,
84098+ atomic64_add_unchecked(child_val, &parent_event->child_count);
84099+ atomic64_add_unchecked(child_event->total_time_enabled,
84100 &parent_event->child_total_time_enabled);
84101- atomic64_add(child_event->total_time_running,
84102+ atomic64_add_unchecked(child_event->total_time_running,
84103 &parent_event->child_total_time_running);
84104
84105 /*
84106diff --git a/kernel/events/internal.h b/kernel/events/internal.h
84107index 569b2187..19940d9 100644
84108--- a/kernel/events/internal.h
84109+++ b/kernel/events/internal.h
84110@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
84111 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
84112 }
84113
84114-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
84115+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
84116 static inline unsigned long \
84117 func_name(struct perf_output_handle *handle, \
84118- const void *buf, unsigned long len) \
84119+ const void user *buf, unsigned long len) \
84120 { \
84121 unsigned long size, written; \
84122 \
84123@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
84124 return 0;
84125 }
84126
84127-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
84128+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
84129
84130 static inline unsigned long
84131 memcpy_skip(void *dst, const void *src, unsigned long n)
84132@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
84133 return 0;
84134 }
84135
84136-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
84137+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
84138
84139 #ifndef arch_perf_out_copy_user
84140 #define arch_perf_out_copy_user arch_perf_out_copy_user
84141@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
84142 }
84143 #endif
84144
84145-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
84146+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
84147
84148 /* Callchain handling */
84149 extern struct perf_callchain_entry *
84150diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
84151index 24b7d6c..40cf797 100644
84152--- a/kernel/events/uprobes.c
84153+++ b/kernel/events/uprobes.c
84154@@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
84155 {
84156 struct page *page;
84157 uprobe_opcode_t opcode;
84158- int result;
84159+ long result;
84160
84161 pagefault_disable();
84162 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
84163diff --git a/kernel/exit.c b/kernel/exit.c
84164index a949819..a5f127d 100644
84165--- a/kernel/exit.c
84166+++ b/kernel/exit.c
84167@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
84168 struct task_struct *leader;
84169 int zap_leader;
84170 repeat:
84171+#ifdef CONFIG_NET
84172+ gr_del_task_from_ip_table(p);
84173+#endif
84174+
84175 /* don't need to get the RCU readlock here - the process is dead and
84176 * can't be modifying its own credentials. But shut RCU-lockdep up */
84177 rcu_read_lock();
84178@@ -329,7 +333,7 @@ int allow_signal(int sig)
84179 * know it'll be handled, so that they don't get converted to
84180 * SIGKILL or just silently dropped.
84181 */
84182- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
84183+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
84184 recalc_sigpending();
84185 spin_unlock_irq(&current->sighand->siglock);
84186 return 0;
84187@@ -698,6 +702,8 @@ void do_exit(long code)
84188 struct task_struct *tsk = current;
84189 int group_dead;
84190
84191+ set_fs(USER_DS);
84192+
84193 profile_task_exit(tsk);
84194
84195 WARN_ON(blk_needs_flush_plug(tsk));
84196@@ -714,7 +720,6 @@ void do_exit(long code)
84197 * mm_release()->clear_child_tid() from writing to a user-controlled
84198 * kernel address.
84199 */
84200- set_fs(USER_DS);
84201
84202 ptrace_event(PTRACE_EVENT_EXIT, code);
84203
84204@@ -773,6 +778,9 @@ void do_exit(long code)
84205 tsk->exit_code = code;
84206 taskstats_exit(tsk, group_dead);
84207
84208+ gr_acl_handle_psacct(tsk, code);
84209+ gr_acl_handle_exit();
84210+
84211 exit_mm(tsk);
84212
84213 if (group_dead)
84214@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
84215 * Take down every thread in the group. This is called by fatal signals
84216 * as well as by sys_exit_group (below).
84217 */
84218-void
84219+__noreturn void
84220 do_group_exit(int exit_code)
84221 {
84222 struct signal_struct *sig = current->signal;
84223diff --git a/kernel/fork.c b/kernel/fork.c
84224index dfa736c..d170f9b 100644
84225--- a/kernel/fork.c
84226+++ b/kernel/fork.c
84227@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
84228 *stackend = STACK_END_MAGIC; /* for overflow detection */
84229
84230 #ifdef CONFIG_CC_STACKPROTECTOR
84231- tsk->stack_canary = get_random_int();
84232+ tsk->stack_canary = pax_get_random_long();
84233 #endif
84234
84235 /*
84236@@ -345,12 +345,80 @@ free_tsk:
84237 }
84238
84239 #ifdef CONFIG_MMU
84240-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84241+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
84242+{
84243+ struct vm_area_struct *tmp;
84244+ unsigned long charge;
84245+ struct file *file;
84246+ int retval;
84247+
84248+ charge = 0;
84249+ if (mpnt->vm_flags & VM_ACCOUNT) {
84250+ unsigned long len = vma_pages(mpnt);
84251+
84252+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84253+ goto fail_nomem;
84254+ charge = len;
84255+ }
84256+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84257+ if (!tmp)
84258+ goto fail_nomem;
84259+ *tmp = *mpnt;
84260+ tmp->vm_mm = mm;
84261+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
84262+ retval = vma_dup_policy(mpnt, tmp);
84263+ if (retval)
84264+ goto fail_nomem_policy;
84265+ if (anon_vma_fork(tmp, mpnt))
84266+ goto fail_nomem_anon_vma_fork;
84267+ tmp->vm_flags &= ~VM_LOCKED;
84268+ tmp->vm_next = tmp->vm_prev = NULL;
84269+ tmp->vm_mirror = NULL;
84270+ file = tmp->vm_file;
84271+ if (file) {
84272+ struct inode *inode = file_inode(file);
84273+ struct address_space *mapping = file->f_mapping;
84274+
84275+ get_file(file);
84276+ if (tmp->vm_flags & VM_DENYWRITE)
84277+ atomic_dec(&inode->i_writecount);
84278+ mutex_lock(&mapping->i_mmap_mutex);
84279+ if (tmp->vm_flags & VM_SHARED)
84280+ mapping->i_mmap_writable++;
84281+ flush_dcache_mmap_lock(mapping);
84282+ /* insert tmp into the share list, just after mpnt */
84283+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84284+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
84285+ else
84286+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
84287+ flush_dcache_mmap_unlock(mapping);
84288+ mutex_unlock(&mapping->i_mmap_mutex);
84289+ }
84290+
84291+ /*
84292+ * Clear hugetlb-related page reserves for children. This only
84293+ * affects MAP_PRIVATE mappings. Faults generated by the child
84294+ * are not guaranteed to succeed, even if read-only
84295+ */
84296+ if (is_vm_hugetlb_page(tmp))
84297+ reset_vma_resv_huge_pages(tmp);
84298+
84299+ return tmp;
84300+
84301+fail_nomem_anon_vma_fork:
84302+ mpol_put(vma_policy(tmp));
84303+fail_nomem_policy:
84304+ kmem_cache_free(vm_area_cachep, tmp);
84305+fail_nomem:
84306+ vm_unacct_memory(charge);
84307+ return NULL;
84308+}
84309+
84310+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84311 {
84312 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
84313 struct rb_node **rb_link, *rb_parent;
84314 int retval;
84315- unsigned long charge;
84316
84317 uprobe_start_dup_mmap();
84318 down_write(&oldmm->mmap_sem);
84319@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84320
84321 prev = NULL;
84322 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
84323- struct file *file;
84324-
84325 if (mpnt->vm_flags & VM_DONTCOPY) {
84326 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
84327 -vma_pages(mpnt));
84328 continue;
84329 }
84330- charge = 0;
84331- if (mpnt->vm_flags & VM_ACCOUNT) {
84332- unsigned long len = vma_pages(mpnt);
84333-
84334- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84335- goto fail_nomem;
84336- charge = len;
84337- }
84338- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84339- if (!tmp)
84340- goto fail_nomem;
84341- *tmp = *mpnt;
84342- INIT_LIST_HEAD(&tmp->anon_vma_chain);
84343- retval = vma_dup_policy(mpnt, tmp);
84344- if (retval)
84345- goto fail_nomem_policy;
84346- tmp->vm_mm = mm;
84347- if (anon_vma_fork(tmp, mpnt))
84348- goto fail_nomem_anon_vma_fork;
84349- tmp->vm_flags &= ~VM_LOCKED;
84350- tmp->vm_next = tmp->vm_prev = NULL;
84351- file = tmp->vm_file;
84352- if (file) {
84353- struct inode *inode = file_inode(file);
84354- struct address_space *mapping = file->f_mapping;
84355-
84356- get_file(file);
84357- if (tmp->vm_flags & VM_DENYWRITE)
84358- atomic_dec(&inode->i_writecount);
84359- mutex_lock(&mapping->i_mmap_mutex);
84360- if (tmp->vm_flags & VM_SHARED)
84361- mapping->i_mmap_writable++;
84362- flush_dcache_mmap_lock(mapping);
84363- /* insert tmp into the share list, just after mpnt */
84364- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84365- vma_nonlinear_insert(tmp,
84366- &mapping->i_mmap_nonlinear);
84367- else
84368- vma_interval_tree_insert_after(tmp, mpnt,
84369- &mapping->i_mmap);
84370- flush_dcache_mmap_unlock(mapping);
84371- mutex_unlock(&mapping->i_mmap_mutex);
84372+ tmp = dup_vma(mm, oldmm, mpnt);
84373+ if (!tmp) {
84374+ retval = -ENOMEM;
84375+ goto out;
84376 }
84377
84378 /*
84379@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84380 if (retval)
84381 goto out;
84382 }
84383+
84384+#ifdef CONFIG_PAX_SEGMEXEC
84385+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
84386+ struct vm_area_struct *mpnt_m;
84387+
84388+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
84389+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
84390+
84391+ if (!mpnt->vm_mirror)
84392+ continue;
84393+
84394+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
84395+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
84396+ mpnt->vm_mirror = mpnt_m;
84397+ } else {
84398+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
84399+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
84400+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
84401+ mpnt->vm_mirror->vm_mirror = mpnt;
84402+ }
84403+ }
84404+ BUG_ON(mpnt_m);
84405+ }
84406+#endif
84407+
84408 /* a new mm has just been created */
84409 arch_dup_mmap(oldmm, mm);
84410 retval = 0;
84411@@ -468,14 +521,6 @@ out:
84412 up_write(&oldmm->mmap_sem);
84413 uprobe_end_dup_mmap();
84414 return retval;
84415-fail_nomem_anon_vma_fork:
84416- mpol_put(vma_policy(tmp));
84417-fail_nomem_policy:
84418- kmem_cache_free(vm_area_cachep, tmp);
84419-fail_nomem:
84420- retval = -ENOMEM;
84421- vm_unacct_memory(charge);
84422- goto out;
84423 }
84424
84425 static inline int mm_alloc_pgd(struct mm_struct *mm)
84426@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
84427 return ERR_PTR(err);
84428
84429 mm = get_task_mm(task);
84430- if (mm && mm != current->mm &&
84431- !ptrace_may_access(task, mode)) {
84432+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
84433+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
84434 mmput(mm);
84435 mm = ERR_PTR(-EACCES);
84436 }
84437@@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
84438 spin_unlock(&fs->lock);
84439 return -EAGAIN;
84440 }
84441- fs->users++;
84442+ atomic_inc(&fs->users);
84443 spin_unlock(&fs->lock);
84444 return 0;
84445 }
84446 tsk->fs = copy_fs_struct(fs);
84447 if (!tsk->fs)
84448 return -ENOMEM;
84449+ /* Carry through gr_chroot_dentry and is_chrooted instead
84450+ of recomputing it here. Already copied when the task struct
84451+ is duplicated. This allows pivot_root to not be treated as
84452+ a chroot
84453+ */
84454+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
84455+
84456 return 0;
84457 }
84458
84459@@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
84460 * parts of the process environment (as per the clone
84461 * flags). The actual kick-off is left to the caller.
84462 */
84463-static struct task_struct *copy_process(unsigned long clone_flags,
84464+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
84465 unsigned long stack_start,
84466 unsigned long stack_size,
84467 int __user *child_tidptr,
84468@@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84469 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
84470 #endif
84471 retval = -EAGAIN;
84472+
84473+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
84474+
84475 if (atomic_read(&p->real_cred->user->processes) >=
84476 task_rlimit(p, RLIMIT_NPROC)) {
84477 if (p->real_cred->user != INIT_USER &&
84478@@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84479 goto bad_fork_free_pid;
84480 }
84481
84482+ /* synchronizes with gr_set_acls()
84483+ we need to call this past the point of no return for fork()
84484+ */
84485+ gr_copy_label(p);
84486+
84487 if (likely(p->pid)) {
84488 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
84489
84490@@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
84491 bad_fork_free:
84492 free_task(p);
84493 fork_out:
84494+ gr_log_forkfail(retval);
84495+
84496 return ERR_PTR(retval);
84497 }
84498
84499@@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
84500
84501 p = copy_process(clone_flags, stack_start, stack_size,
84502 child_tidptr, NULL, trace);
84503+ add_latent_entropy();
84504 /*
84505 * Do this prior waking up the new thread - the thread pointer
84506 * might get invalid after that point, if the thread exits quickly.
84507@@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
84508 if (clone_flags & CLONE_PARENT_SETTID)
84509 put_user(nr, parent_tidptr);
84510
84511+ gr_handle_brute_check();
84512+
84513 if (clone_flags & CLONE_VFORK) {
84514 p->vfork_done = &vfork;
84515 init_completion(&vfork);
84516@@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
84517 mm_cachep = kmem_cache_create("mm_struct",
84518 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
84519 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
84520- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
84521+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
84522 mmap_init();
84523 nsproxy_cache_init();
84524 }
84525@@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
84526 return 0;
84527
84528 /* don't need lock here; in the worst case we'll do useless copy */
84529- if (fs->users == 1)
84530+ if (atomic_read(&fs->users) == 1)
84531 return 0;
84532
84533 *new_fsp = copy_fs_struct(fs);
84534@@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
84535 fs = current->fs;
84536 spin_lock(&fs->lock);
84537 current->fs = new_fs;
84538- if (--fs->users)
84539+ gr_set_chroot_entries(current, &current->fs->root);
84540+ if (atomic_dec_return(&fs->users))
84541 new_fs = NULL;
84542 else
84543 new_fs = fs;
84544diff --git a/kernel/futex.c b/kernel/futex.c
84545index f6ff019..ac53307 100644
84546--- a/kernel/futex.c
84547+++ b/kernel/futex.c
84548@@ -54,6 +54,7 @@
84549 #include <linux/mount.h>
84550 #include <linux/pagemap.h>
84551 #include <linux/syscalls.h>
84552+#include <linux/ptrace.h>
84553 #include <linux/signal.h>
84554 #include <linux/export.h>
84555 #include <linux/magic.h>
84556@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
84557 struct page *page, *page_head;
84558 int err, ro = 0;
84559
84560+#ifdef CONFIG_PAX_SEGMEXEC
84561+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
84562+ return -EFAULT;
84563+#endif
84564+
84565 /*
84566 * The futex address must be "naturally" aligned.
84567 */
84568@@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
84569
84570 static int get_futex_value_locked(u32 *dest, u32 __user *from)
84571 {
84572- int ret;
84573+ unsigned long ret;
84574
84575 pagefault_disable();
84576 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
84577@@ -2735,6 +2741,7 @@ static int __init futex_init(void)
84578 {
84579 u32 curval;
84580 int i;
84581+ mm_segment_t oldfs;
84582
84583 /*
84584 * This will fail and we want it. Some arch implementations do
84585@@ -2746,8 +2753,11 @@ static int __init futex_init(void)
84586 * implementation, the non-functional ones will return
84587 * -ENOSYS.
84588 */
84589+ oldfs = get_fs();
84590+ set_fs(USER_DS);
84591 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
84592 futex_cmpxchg_enabled = 1;
84593+ set_fs(oldfs);
84594
84595 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
84596 plist_head_init(&futex_queues[i].chain);
84597diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
84598index f9f44fd..29885e4 100644
84599--- a/kernel/futex_compat.c
84600+++ b/kernel/futex_compat.c
84601@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
84602 return 0;
84603 }
84604
84605-static void __user *futex_uaddr(struct robust_list __user *entry,
84606+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
84607 compat_long_t futex_offset)
84608 {
84609 compat_uptr_t base = ptr_to_compat(entry);
84610diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
84611index f45b75b..bfac6d5 100644
84612--- a/kernel/gcov/base.c
84613+++ b/kernel/gcov/base.c
84614@@ -108,11 +108,6 @@ void gcov_enable_events(void)
84615 }
84616
84617 #ifdef CONFIG_MODULES
84618-static inline int within(void *addr, void *start, unsigned long size)
84619-{
84620- return ((addr >= start) && (addr < start + size));
84621-}
84622-
84623 /* Update list and generate events when modules are unloaded. */
84624 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84625 void *data)
84626@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84627
84628 /* Remove entries located in module from linked list. */
84629 while ((info = gcov_info_next(info))) {
84630- if (within(info, mod->module_core, mod->core_size)) {
84631+ if (within_module_core_rw((unsigned long)info, mod)) {
84632 gcov_info_unlink(prev, info);
84633 if (gcov_events_enabled)
84634 gcov_event(GCOV_REMOVE, info);
84635diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
84636index 383319b..56ebb13 100644
84637--- a/kernel/hrtimer.c
84638+++ b/kernel/hrtimer.c
84639@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
84640 local_irq_restore(flags);
84641 }
84642
84643-static void run_hrtimer_softirq(struct softirq_action *h)
84644+static __latent_entropy void run_hrtimer_softirq(void)
84645 {
84646 hrtimer_peek_ahead_timers();
84647 }
84648diff --git a/kernel/irq_work.c b/kernel/irq_work.c
84649index 55fcce6..0e4cf34 100644
84650--- a/kernel/irq_work.c
84651+++ b/kernel/irq_work.c
84652@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
84653 return NOTIFY_OK;
84654 }
84655
84656-static struct notifier_block cpu_notify;
84657+static struct notifier_block cpu_notify = {
84658+ .notifier_call = irq_work_cpu_notify,
84659+ .priority = 0,
84660+};
84661
84662 static __init int irq_work_init_cpu_notifier(void)
84663 {
84664- cpu_notify.notifier_call = irq_work_cpu_notify;
84665- cpu_notify.priority = 0;
84666 register_cpu_notifier(&cpu_notify);
84667 return 0;
84668 }
84669diff --git a/kernel/jump_label.c b/kernel/jump_label.c
84670index 9019f15..9a3c42e 100644
84671--- a/kernel/jump_label.c
84672+++ b/kernel/jump_label.c
84673@@ -14,6 +14,7 @@
84674 #include <linux/err.h>
84675 #include <linux/static_key.h>
84676 #include <linux/jump_label_ratelimit.h>
84677+#include <linux/mm.h>
84678
84679 #ifdef HAVE_JUMP_LABEL
84680
84681@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
84682
84683 size = (((unsigned long)stop - (unsigned long)start)
84684 / sizeof(struct jump_entry));
84685+ pax_open_kernel();
84686 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
84687+ pax_close_kernel();
84688 }
84689
84690 static void jump_label_update(struct static_key *key, int enable);
84691@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
84692 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
84693 struct jump_entry *iter;
84694
84695+ pax_open_kernel();
84696 for (iter = iter_start; iter < iter_stop; iter++) {
84697 if (within_module_init(iter->code, mod))
84698 iter->code = 0;
84699 }
84700+ pax_close_kernel();
84701 }
84702
84703 static int
84704diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
84705index 3127ad5..159d880 100644
84706--- a/kernel/kallsyms.c
84707+++ b/kernel/kallsyms.c
84708@@ -11,6 +11,9 @@
84709 * Changed the compression method from stem compression to "table lookup"
84710 * compression (see scripts/kallsyms.c for a more complete description)
84711 */
84712+#ifdef CONFIG_GRKERNSEC_HIDESYM
84713+#define __INCLUDED_BY_HIDESYM 1
84714+#endif
84715 #include <linux/kallsyms.h>
84716 #include <linux/module.h>
84717 #include <linux/init.h>
84718@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
84719
84720 static inline int is_kernel_inittext(unsigned long addr)
84721 {
84722+ if (system_state != SYSTEM_BOOTING)
84723+ return 0;
84724+
84725 if (addr >= (unsigned long)_sinittext
84726 && addr <= (unsigned long)_einittext)
84727 return 1;
84728 return 0;
84729 }
84730
84731+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84732+#ifdef CONFIG_MODULES
84733+static inline int is_module_text(unsigned long addr)
84734+{
84735+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
84736+ return 1;
84737+
84738+ addr = ktla_ktva(addr);
84739+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
84740+}
84741+#else
84742+static inline int is_module_text(unsigned long addr)
84743+{
84744+ return 0;
84745+}
84746+#endif
84747+#endif
84748+
84749 static inline int is_kernel_text(unsigned long addr)
84750 {
84751 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
84752@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
84753
84754 static inline int is_kernel(unsigned long addr)
84755 {
84756+
84757+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84758+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
84759+ return 1;
84760+
84761+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
84762+#else
84763 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
84764+#endif
84765+
84766 return 1;
84767 return in_gate_area_no_mm(addr);
84768 }
84769
84770 static int is_ksym_addr(unsigned long addr)
84771 {
84772+
84773+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84774+ if (is_module_text(addr))
84775+ return 0;
84776+#endif
84777+
84778 if (all_var)
84779 return is_kernel(addr);
84780
84781@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
84782
84783 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
84784 {
84785- iter->name[0] = '\0';
84786 iter->nameoff = get_symbol_offset(new_pos);
84787 iter->pos = new_pos;
84788 }
84789@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
84790 {
84791 struct kallsym_iter *iter = m->private;
84792
84793+#ifdef CONFIG_GRKERNSEC_HIDESYM
84794+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
84795+ return 0;
84796+#endif
84797+
84798 /* Some debugging symbols have no name. Ignore them. */
84799 if (!iter->name[0])
84800 return 0;
84801@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
84802 */
84803 type = iter->exported ? toupper(iter->type) :
84804 tolower(iter->type);
84805+
84806 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
84807 type, iter->name, iter->module_name);
84808 } else
84809@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
84810 struct kallsym_iter *iter;
84811 int ret;
84812
84813- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
84814+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
84815 if (!iter)
84816 return -ENOMEM;
84817 reset_iter(iter, 0);
84818diff --git a/kernel/kcmp.c b/kernel/kcmp.c
84819index e30ac0f..3528cac 100644
84820--- a/kernel/kcmp.c
84821+++ b/kernel/kcmp.c
84822@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
84823 struct task_struct *task1, *task2;
84824 int ret;
84825
84826+#ifdef CONFIG_GRKERNSEC
84827+ return -ENOSYS;
84828+#endif
84829+
84830 rcu_read_lock();
84831
84832 /*
84833diff --git a/kernel/kexec.c b/kernel/kexec.c
84834index 9c97016..df438f8 100644
84835--- a/kernel/kexec.c
84836+++ b/kernel/kexec.c
84837@@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
84838 unsigned long flags)
84839 {
84840 struct compat_kexec_segment in;
84841- struct kexec_segment out, __user *ksegments;
84842+ struct kexec_segment out;
84843+ struct kexec_segment __user *ksegments;
84844 unsigned long i, result;
84845
84846 /* Don't allow clients that don't understand the native
84847diff --git a/kernel/kmod.c b/kernel/kmod.c
84848index b086006..655e2aa 100644
84849--- a/kernel/kmod.c
84850+++ b/kernel/kmod.c
84851@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
84852 kfree(info->argv);
84853 }
84854
84855-static int call_modprobe(char *module_name, int wait)
84856+static int call_modprobe(char *module_name, char *module_param, int wait)
84857 {
84858 struct subprocess_info *info;
84859 static char *envp[] = {
84860@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
84861 NULL
84862 };
84863
84864- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
84865+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
84866 if (!argv)
84867 goto out;
84868
84869@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
84870 argv[1] = "-q";
84871 argv[2] = "--";
84872 argv[3] = module_name; /* check free_modprobe_argv() */
84873- argv[4] = NULL;
84874+ argv[4] = module_param;
84875+ argv[5] = NULL;
84876
84877 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
84878 NULL, free_modprobe_argv, NULL);
84879@@ -129,9 +130,8 @@ out:
84880 * If module auto-loading support is disabled then this function
84881 * becomes a no-operation.
84882 */
84883-int __request_module(bool wait, const char *fmt, ...)
84884+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
84885 {
84886- va_list args;
84887 char module_name[MODULE_NAME_LEN];
84888 unsigned int max_modprobes;
84889 int ret;
84890@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
84891 if (!modprobe_path[0])
84892 return 0;
84893
84894- va_start(args, fmt);
84895- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
84896- va_end(args);
84897+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
84898 if (ret >= MODULE_NAME_LEN)
84899 return -ENAMETOOLONG;
84900
84901@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
84902 if (ret)
84903 return ret;
84904
84905+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84906+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
84907+ /* hack to workaround consolekit/udisks stupidity */
84908+ read_lock(&tasklist_lock);
84909+ if (!strcmp(current->comm, "mount") &&
84910+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
84911+ read_unlock(&tasklist_lock);
84912+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
84913+ return -EPERM;
84914+ }
84915+ read_unlock(&tasklist_lock);
84916+ }
84917+#endif
84918+
84919 /* If modprobe needs a service that is in a module, we get a recursive
84920 * loop. Limit the number of running kmod threads to max_threads/2 or
84921 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
84922@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
84923
84924 trace_module_request(module_name, wait, _RET_IP_);
84925
84926- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
84927+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
84928
84929 atomic_dec(&kmod_concurrent);
84930 return ret;
84931 }
84932+
84933+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
84934+{
84935+ va_list args;
84936+ int ret;
84937+
84938+ va_start(args, fmt);
84939+ ret = ____request_module(wait, module_param, fmt, args);
84940+ va_end(args);
84941+
84942+ return ret;
84943+}
84944+
84945+int __request_module(bool wait, const char *fmt, ...)
84946+{
84947+ va_list args;
84948+ int ret;
84949+
84950+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84951+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
84952+ char module_param[MODULE_NAME_LEN];
84953+
84954+ memset(module_param, 0, sizeof(module_param));
84955+
84956+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
84957+
84958+ va_start(args, fmt);
84959+ ret = ____request_module(wait, module_param, fmt, args);
84960+ va_end(args);
84961+
84962+ return ret;
84963+ }
84964+#endif
84965+
84966+ va_start(args, fmt);
84967+ ret = ____request_module(wait, NULL, fmt, args);
84968+ va_end(args);
84969+
84970+ return ret;
84971+}
84972+
84973 EXPORT_SYMBOL(__request_module);
84974 #endif /* CONFIG_MODULES */
84975
84976@@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
84977 */
84978 set_user_nice(current, 0);
84979
84980+#ifdef CONFIG_GRKERNSEC
84981+ /* this is race-free as far as userland is concerned as we copied
84982+ out the path to be used prior to this point and are now operating
84983+ on that copy
84984+ */
84985+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
84986+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
84987+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
84988+ retval = -EPERM;
84989+ goto fail;
84990+ }
84991+#endif
84992+
84993 retval = -ENOMEM;
84994 new = prepare_kernel_cred(current);
84995 if (!new)
84996@@ -240,8 +306,8 @@ static int ____call_usermodehelper(void *data)
84997 commit_creds(new);
84998
84999 retval = do_execve(sub_info->path,
85000- (const char __user *const __user *)sub_info->argv,
85001- (const char __user *const __user *)sub_info->envp);
85002+ (const char __user *const __force_user *)sub_info->argv,
85003+ (const char __user *const __force_user *)sub_info->envp);
85004 if (!retval)
85005 return 0;
85006
85007@@ -260,6 +326,10 @@ static int call_helper(void *data)
85008
85009 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
85010 {
85011+#ifdef CONFIG_GRKERNSEC
85012+ kfree(info->path);
85013+ info->path = info->origpath;
85014+#endif
85015 if (info->cleanup)
85016 (*info->cleanup)(info);
85017 kfree(info);
85018@@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
85019 *
85020 * Thus the __user pointer cast is valid here.
85021 */
85022- sys_wait4(pid, (int __user *)&ret, 0, NULL);
85023+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
85024
85025 /*
85026 * If ret is 0, either ____call_usermodehelper failed and the
85027@@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
85028 goto out;
85029
85030 INIT_WORK(&sub_info->work, __call_usermodehelper);
85031+#ifdef CONFIG_GRKERNSEC
85032+ sub_info->origpath = path;
85033+ sub_info->path = kstrdup(path, gfp_mask);
85034+#else
85035 sub_info->path = path;
85036+#endif
85037 sub_info->argv = argv;
85038 sub_info->envp = envp;
85039
85040@@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
85041 static int proc_cap_handler(struct ctl_table *table, int write,
85042 void __user *buffer, size_t *lenp, loff_t *ppos)
85043 {
85044- struct ctl_table t;
85045+ ctl_table_no_const t;
85046 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
85047 kernel_cap_t new_cap;
85048 int err, i;
85049diff --git a/kernel/kprobes.c b/kernel/kprobes.c
85050index ceeadfc..11c18b6 100644
85051--- a/kernel/kprobes.c
85052+++ b/kernel/kprobes.c
85053@@ -31,6 +31,9 @@
85054 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
85055 * <prasanna@in.ibm.com> added function-return probes.
85056 */
85057+#ifdef CONFIG_GRKERNSEC_HIDESYM
85058+#define __INCLUDED_BY_HIDESYM 1
85059+#endif
85060 #include <linux/kprobes.h>
85061 #include <linux/hash.h>
85062 #include <linux/init.h>
85063@@ -135,12 +138,12 @@ enum kprobe_slot_state {
85064
85065 static void *alloc_insn_page(void)
85066 {
85067- return module_alloc(PAGE_SIZE);
85068+ return module_alloc_exec(PAGE_SIZE);
85069 }
85070
85071 static void free_insn_page(void *page)
85072 {
85073- module_free(NULL, page);
85074+ module_free_exec(NULL, page);
85075 }
85076
85077 struct kprobe_insn_cache kprobe_insn_slots = {
85078@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
85079 kprobe_type = "k";
85080
85081 if (sym)
85082- seq_printf(pi, "%p %s %s+0x%x %s ",
85083+ seq_printf(pi, "%pK %s %s+0x%x %s ",
85084 p->addr, kprobe_type, sym, offset,
85085 (modname ? modname : " "));
85086 else
85087- seq_printf(pi, "%p %s %p ",
85088+ seq_printf(pi, "%pK %s %pK ",
85089 p->addr, kprobe_type, p->addr);
85090
85091 if (!pp)
85092diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
85093index 9659d38..bffd520 100644
85094--- a/kernel/ksysfs.c
85095+++ b/kernel/ksysfs.c
85096@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
85097 {
85098 if (count+1 > UEVENT_HELPER_PATH_LEN)
85099 return -ENOENT;
85100+ if (!capable(CAP_SYS_ADMIN))
85101+ return -EPERM;
85102 memcpy(uevent_helper, buf, count);
85103 uevent_helper[count] = '\0';
85104 if (count && uevent_helper[count-1] == '\n')
85105@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
85106 return count;
85107 }
85108
85109-static struct bin_attribute notes_attr = {
85110+static bin_attribute_no_const notes_attr __read_only = {
85111 .attr = {
85112 .name = "notes",
85113 .mode = S_IRUGO,
85114diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
85115index 576ba75..7c256e4 100644
85116--- a/kernel/locking/lockdep.c
85117+++ b/kernel/locking/lockdep.c
85118@@ -596,6 +596,10 @@ static int static_obj(void *obj)
85119 end = (unsigned long) &_end,
85120 addr = (unsigned long) obj;
85121
85122+#ifdef CONFIG_PAX_KERNEXEC
85123+ start = ktla_ktva(start);
85124+#endif
85125+
85126 /*
85127 * static variable?
85128 */
85129@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
85130 if (!static_obj(lock->key)) {
85131 debug_locks_off();
85132 printk("INFO: trying to register non-static key.\n");
85133+ printk("lock:%pS key:%pS.\n", lock, lock->key);
85134 printk("the code is fine but needs lockdep annotation.\n");
85135 printk("turning off the locking correctness validator.\n");
85136 dump_stack();
85137@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
85138 if (!class)
85139 return 0;
85140 }
85141- atomic_inc((atomic_t *)&class->ops);
85142+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
85143 if (very_verbose(class)) {
85144 printk("\nacquire class [%p] %s", class->key, class->name);
85145 if (class->name_version > 1)
85146diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
85147index ef43ac4..2720dfa 100644
85148--- a/kernel/locking/lockdep_proc.c
85149+++ b/kernel/locking/lockdep_proc.c
85150@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
85151 return 0;
85152 }
85153
85154- seq_printf(m, "%p", class->key);
85155+ seq_printf(m, "%pK", class->key);
85156 #ifdef CONFIG_DEBUG_LOCKDEP
85157 seq_printf(m, " OPS:%8ld", class->ops);
85158 #endif
85159@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
85160
85161 list_for_each_entry(entry, &class->locks_after, entry) {
85162 if (entry->distance == 1) {
85163- seq_printf(m, " -> [%p] ", entry->class->key);
85164+ seq_printf(m, " -> [%pK] ", entry->class->key);
85165 print_name(m, entry->class);
85166 seq_puts(m, "\n");
85167 }
85168@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
85169 if (!class->key)
85170 continue;
85171
85172- seq_printf(m, "[%p] ", class->key);
85173+ seq_printf(m, "[%pK] ", class->key);
85174 print_name(m, class);
85175 seq_puts(m, "\n");
85176 }
85177@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85178 if (!i)
85179 seq_line(m, '-', 40-namelen, namelen);
85180
85181- snprintf(ip, sizeof(ip), "[<%p>]",
85182+ snprintf(ip, sizeof(ip), "[<%pK>]",
85183 (void *)class->contention_point[i]);
85184 seq_printf(m, "%40s %14lu %29s %pS\n",
85185 name, stats->contention_point[i],
85186@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85187 if (!i)
85188 seq_line(m, '-', 40-namelen, namelen);
85189
85190- snprintf(ip, sizeof(ip), "[<%p>]",
85191+ snprintf(ip, sizeof(ip), "[<%pK>]",
85192 (void *)class->contending_point[i]);
85193 seq_printf(m, "%40s %14lu %29s %pS\n",
85194 name, stats->contending_point[i],
85195diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
85196index 7e3443f..b2a1e6b 100644
85197--- a/kernel/locking/mutex-debug.c
85198+++ b/kernel/locking/mutex-debug.c
85199@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
85200 }
85201
85202 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85203- struct thread_info *ti)
85204+ struct task_struct *task)
85205 {
85206 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
85207
85208 /* Mark the current thread as blocked on the lock: */
85209- ti->task->blocked_on = waiter;
85210+ task->blocked_on = waiter;
85211 }
85212
85213 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85214- struct thread_info *ti)
85215+ struct task_struct *task)
85216 {
85217 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
85218- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
85219- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
85220- ti->task->blocked_on = NULL;
85221+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
85222+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
85223+ task->blocked_on = NULL;
85224
85225 list_del_init(&waiter->list);
85226 waiter->task = NULL;
85227diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
85228index 0799fd3..d06ae3b 100644
85229--- a/kernel/locking/mutex-debug.h
85230+++ b/kernel/locking/mutex-debug.h
85231@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
85232 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
85233 extern void debug_mutex_add_waiter(struct mutex *lock,
85234 struct mutex_waiter *waiter,
85235- struct thread_info *ti);
85236+ struct task_struct *task);
85237 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85238- struct thread_info *ti);
85239+ struct task_struct *task);
85240 extern void debug_mutex_unlock(struct mutex *lock);
85241 extern void debug_mutex_init(struct mutex *lock, const char *name,
85242 struct lock_class_key *key);
85243diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
85244index 4dd6e4c..df52693 100644
85245--- a/kernel/locking/mutex.c
85246+++ b/kernel/locking/mutex.c
85247@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
85248 node->locked = 1;
85249 return;
85250 }
85251- ACCESS_ONCE(prev->next) = node;
85252+ ACCESS_ONCE_RW(prev->next) = node;
85253 smp_wmb();
85254 /* Wait until the lock holder passes the lock down */
85255 while (!ACCESS_ONCE(node->locked))
85256@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
85257 while (!(next = ACCESS_ONCE(node->next)))
85258 arch_mutex_cpu_relax();
85259 }
85260- ACCESS_ONCE(next->locked) = 1;
85261+ ACCESS_ONCE_RW(next->locked) = 1;
85262 smp_wmb();
85263 }
85264
85265@@ -520,7 +520,7 @@ slowpath:
85266 goto skip_wait;
85267
85268 debug_mutex_lock_common(lock, &waiter);
85269- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
85270+ debug_mutex_add_waiter(lock, &waiter, task);
85271
85272 /* add waiting tasks to the end of the waitqueue (FIFO): */
85273 list_add_tail(&waiter.list, &lock->wait_list);
85274@@ -564,7 +564,7 @@ slowpath:
85275 schedule_preempt_disabled();
85276 spin_lock_mutex(&lock->wait_lock, flags);
85277 }
85278- mutex_remove_waiter(lock, &waiter, current_thread_info());
85279+ mutex_remove_waiter(lock, &waiter, task);
85280 /* set it to 0 if there are no waiters left: */
85281 if (likely(list_empty(&lock->wait_list)))
85282 atomic_set(&lock->count, 0);
85283@@ -601,7 +601,7 @@ skip_wait:
85284 return 0;
85285
85286 err:
85287- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
85288+ mutex_remove_waiter(lock, &waiter, task);
85289 spin_unlock_mutex(&lock->wait_lock, flags);
85290 debug_mutex_free_waiter(&waiter);
85291 mutex_release(&lock->dep_map, 1, ip);
85292diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
85293index 1d96dd0..994ff19 100644
85294--- a/kernel/locking/rtmutex-tester.c
85295+++ b/kernel/locking/rtmutex-tester.c
85296@@ -22,7 +22,7 @@
85297 #define MAX_RT_TEST_MUTEXES 8
85298
85299 static spinlock_t rttest_lock;
85300-static atomic_t rttest_event;
85301+static atomic_unchecked_t rttest_event;
85302
85303 struct test_thread_data {
85304 int opcode;
85305@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85306
85307 case RTTEST_LOCKCONT:
85308 td->mutexes[td->opdata] = 1;
85309- td->event = atomic_add_return(1, &rttest_event);
85310+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85311 return 0;
85312
85313 case RTTEST_RESET:
85314@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85315 return 0;
85316
85317 case RTTEST_RESETEVENT:
85318- atomic_set(&rttest_event, 0);
85319+ atomic_set_unchecked(&rttest_event, 0);
85320 return 0;
85321
85322 default:
85323@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85324 return ret;
85325
85326 td->mutexes[id] = 1;
85327- td->event = atomic_add_return(1, &rttest_event);
85328+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85329 rt_mutex_lock(&mutexes[id]);
85330- td->event = atomic_add_return(1, &rttest_event);
85331+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85332 td->mutexes[id] = 4;
85333 return 0;
85334
85335@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85336 return ret;
85337
85338 td->mutexes[id] = 1;
85339- td->event = atomic_add_return(1, &rttest_event);
85340+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85341 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
85342- td->event = atomic_add_return(1, &rttest_event);
85343+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85344 td->mutexes[id] = ret ? 0 : 4;
85345 return ret ? -EINTR : 0;
85346
85347@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85348 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
85349 return ret;
85350
85351- td->event = atomic_add_return(1, &rttest_event);
85352+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85353 rt_mutex_unlock(&mutexes[id]);
85354- td->event = atomic_add_return(1, &rttest_event);
85355+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85356 td->mutexes[id] = 0;
85357 return 0;
85358
85359@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85360 break;
85361
85362 td->mutexes[dat] = 2;
85363- td->event = atomic_add_return(1, &rttest_event);
85364+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85365 break;
85366
85367 default:
85368@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85369 return;
85370
85371 td->mutexes[dat] = 3;
85372- td->event = atomic_add_return(1, &rttest_event);
85373+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85374 break;
85375
85376 case RTTEST_LOCKNOWAIT:
85377@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85378 return;
85379
85380 td->mutexes[dat] = 1;
85381- td->event = atomic_add_return(1, &rttest_event);
85382+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85383 return;
85384
85385 default:
85386diff --git a/kernel/module.c b/kernel/module.c
85387index f5a3b1e..1f5578b 100644
85388--- a/kernel/module.c
85389+++ b/kernel/module.c
85390@@ -61,6 +61,7 @@
85391 #include <linux/pfn.h>
85392 #include <linux/bsearch.h>
85393 #include <linux/fips.h>
85394+#include <linux/grsecurity.h>
85395 #include <uapi/linux/module.h>
85396 #include "module-internal.h"
85397
85398@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
85399
85400 /* Bounds of module allocation, for speeding __module_address.
85401 * Protected by module_mutex. */
85402-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
85403+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
85404+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
85405
85406 int register_module_notifier(struct notifier_block * nb)
85407 {
85408@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85409 return true;
85410
85411 list_for_each_entry_rcu(mod, &modules, list) {
85412- struct symsearch arr[] = {
85413+ struct symsearch modarr[] = {
85414 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
85415 NOT_GPL_ONLY, false },
85416 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
85417@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85418 if (mod->state == MODULE_STATE_UNFORMED)
85419 continue;
85420
85421- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
85422+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
85423 return true;
85424 }
85425 return false;
85426@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
85427 if (!pcpusec->sh_size)
85428 return 0;
85429
85430- if (align > PAGE_SIZE) {
85431+ if (align-1 >= PAGE_SIZE) {
85432 pr_warn("%s: per-cpu alignment %li > %li\n",
85433 mod->name, align, PAGE_SIZE);
85434 align = PAGE_SIZE;
85435@@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
85436 static ssize_t show_coresize(struct module_attribute *mattr,
85437 struct module_kobject *mk, char *buffer)
85438 {
85439- return sprintf(buffer, "%u\n", mk->mod->core_size);
85440+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
85441 }
85442
85443 static struct module_attribute modinfo_coresize =
85444@@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
85445 static ssize_t show_initsize(struct module_attribute *mattr,
85446 struct module_kobject *mk, char *buffer)
85447 {
85448- return sprintf(buffer, "%u\n", mk->mod->init_size);
85449+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
85450 }
85451
85452 static struct module_attribute modinfo_initsize =
85453@@ -1286,7 +1288,7 @@ resolve_symbol_wait(struct module *mod,
85454 */
85455 #ifdef CONFIG_SYSFS
85456
85457-#ifdef CONFIG_KALLSYMS
85458+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
85459 static inline bool sect_empty(const Elf_Shdr *sect)
85460 {
85461 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
85462@@ -1426,7 +1428,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
85463 {
85464 unsigned int notes, loaded, i;
85465 struct module_notes_attrs *notes_attrs;
85466- struct bin_attribute *nattr;
85467+ bin_attribute_no_const *nattr;
85468
85469 /* failed to create section attributes, so can't create notes */
85470 if (!mod->sect_attrs)
85471@@ -1538,7 +1540,7 @@ static void del_usage_links(struct module *mod)
85472 static int module_add_modinfo_attrs(struct module *mod)
85473 {
85474 struct module_attribute *attr;
85475- struct module_attribute *temp_attr;
85476+ module_attribute_no_const *temp_attr;
85477 int error = 0;
85478 int i;
85479
85480@@ -1759,21 +1761,21 @@ static void set_section_ro_nx(void *base,
85481
85482 static void unset_module_core_ro_nx(struct module *mod)
85483 {
85484- set_page_attributes(mod->module_core + mod->core_text_size,
85485- mod->module_core + mod->core_size,
85486+ set_page_attributes(mod->module_core_rw,
85487+ mod->module_core_rw + mod->core_size_rw,
85488 set_memory_x);
85489- set_page_attributes(mod->module_core,
85490- mod->module_core + mod->core_ro_size,
85491+ set_page_attributes(mod->module_core_rx,
85492+ mod->module_core_rx + mod->core_size_rx,
85493 set_memory_rw);
85494 }
85495
85496 static void unset_module_init_ro_nx(struct module *mod)
85497 {
85498- set_page_attributes(mod->module_init + mod->init_text_size,
85499- mod->module_init + mod->init_size,
85500+ set_page_attributes(mod->module_init_rw,
85501+ mod->module_init_rw + mod->init_size_rw,
85502 set_memory_x);
85503- set_page_attributes(mod->module_init,
85504- mod->module_init + mod->init_ro_size,
85505+ set_page_attributes(mod->module_init_rx,
85506+ mod->module_init_rx + mod->init_size_rx,
85507 set_memory_rw);
85508 }
85509
85510@@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
85511 list_for_each_entry_rcu(mod, &modules, list) {
85512 if (mod->state == MODULE_STATE_UNFORMED)
85513 continue;
85514- if ((mod->module_core) && (mod->core_text_size)) {
85515- set_page_attributes(mod->module_core,
85516- mod->module_core + mod->core_text_size,
85517+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
85518+ set_page_attributes(mod->module_core_rx,
85519+ mod->module_core_rx + mod->core_size_rx,
85520 set_memory_rw);
85521 }
85522- if ((mod->module_init) && (mod->init_text_size)) {
85523- set_page_attributes(mod->module_init,
85524- mod->module_init + mod->init_text_size,
85525+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
85526+ set_page_attributes(mod->module_init_rx,
85527+ mod->module_init_rx + mod->init_size_rx,
85528 set_memory_rw);
85529 }
85530 }
85531@@ -1809,14 +1811,14 @@ void set_all_modules_text_ro(void)
85532 list_for_each_entry_rcu(mod, &modules, list) {
85533 if (mod->state == MODULE_STATE_UNFORMED)
85534 continue;
85535- if ((mod->module_core) && (mod->core_text_size)) {
85536- set_page_attributes(mod->module_core,
85537- mod->module_core + mod->core_text_size,
85538+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
85539+ set_page_attributes(mod->module_core_rx,
85540+ mod->module_core_rx + mod->core_size_rx,
85541 set_memory_ro);
85542 }
85543- if ((mod->module_init) && (mod->init_text_size)) {
85544- set_page_attributes(mod->module_init,
85545- mod->module_init + mod->init_text_size,
85546+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
85547+ set_page_attributes(mod->module_init_rx,
85548+ mod->module_init_rx + mod->init_size_rx,
85549 set_memory_ro);
85550 }
85551 }
85552@@ -1867,16 +1869,19 @@ static void free_module(struct module *mod)
85553
85554 /* This may be NULL, but that's OK */
85555 unset_module_init_ro_nx(mod);
85556- module_free(mod, mod->module_init);
85557+ module_free(mod, mod->module_init_rw);
85558+ module_free_exec(mod, mod->module_init_rx);
85559 kfree(mod->args);
85560 percpu_modfree(mod);
85561
85562 /* Free lock-classes: */
85563- lockdep_free_key_range(mod->module_core, mod->core_size);
85564+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
85565+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
85566
85567 /* Finally, free the core (containing the module structure) */
85568 unset_module_core_ro_nx(mod);
85569- module_free(mod, mod->module_core);
85570+ module_free_exec(mod, mod->module_core_rx);
85571+ module_free(mod, mod->module_core_rw);
85572
85573 #ifdef CONFIG_MPU
85574 update_protections(current->mm);
85575@@ -1945,9 +1950,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85576 int ret = 0;
85577 const struct kernel_symbol *ksym;
85578
85579+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85580+ int is_fs_load = 0;
85581+ int register_filesystem_found = 0;
85582+ char *p;
85583+
85584+ p = strstr(mod->args, "grsec_modharden_fs");
85585+ if (p) {
85586+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
85587+ /* copy \0 as well */
85588+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
85589+ is_fs_load = 1;
85590+ }
85591+#endif
85592+
85593 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
85594 const char *name = info->strtab + sym[i].st_name;
85595
85596+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85597+ /* it's a real shame this will never get ripped and copied
85598+ upstream! ;(
85599+ */
85600+ if (is_fs_load && !strcmp(name, "register_filesystem"))
85601+ register_filesystem_found = 1;
85602+#endif
85603+
85604 switch (sym[i].st_shndx) {
85605 case SHN_COMMON:
85606 /* We compiled with -fno-common. These are not
85607@@ -1968,7 +1995,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85608 ksym = resolve_symbol_wait(mod, info, name);
85609 /* Ok if resolved. */
85610 if (ksym && !IS_ERR(ksym)) {
85611+ pax_open_kernel();
85612 sym[i].st_value = ksym->value;
85613+ pax_close_kernel();
85614 break;
85615 }
85616
85617@@ -1987,11 +2016,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85618 secbase = (unsigned long)mod_percpu(mod);
85619 else
85620 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
85621+ pax_open_kernel();
85622 sym[i].st_value += secbase;
85623+ pax_close_kernel();
85624 break;
85625 }
85626 }
85627
85628+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85629+ if (is_fs_load && !register_filesystem_found) {
85630+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
85631+ ret = -EPERM;
85632+ }
85633+#endif
85634+
85635 return ret;
85636 }
85637
85638@@ -2075,22 +2113,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
85639 || s->sh_entsize != ~0UL
85640 || strstarts(sname, ".init"))
85641 continue;
85642- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
85643+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85644+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
85645+ else
85646+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
85647 pr_debug("\t%s\n", sname);
85648 }
85649- switch (m) {
85650- case 0: /* executable */
85651- mod->core_size = debug_align(mod->core_size);
85652- mod->core_text_size = mod->core_size;
85653- break;
85654- case 1: /* RO: text and ro-data */
85655- mod->core_size = debug_align(mod->core_size);
85656- mod->core_ro_size = mod->core_size;
85657- break;
85658- case 3: /* whole core */
85659- mod->core_size = debug_align(mod->core_size);
85660- break;
85661- }
85662 }
85663
85664 pr_debug("Init section allocation order:\n");
85665@@ -2104,23 +2132,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
85666 || s->sh_entsize != ~0UL
85667 || !strstarts(sname, ".init"))
85668 continue;
85669- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
85670- | INIT_OFFSET_MASK);
85671+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85672+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
85673+ else
85674+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
85675+ s->sh_entsize |= INIT_OFFSET_MASK;
85676 pr_debug("\t%s\n", sname);
85677 }
85678- switch (m) {
85679- case 0: /* executable */
85680- mod->init_size = debug_align(mod->init_size);
85681- mod->init_text_size = mod->init_size;
85682- break;
85683- case 1: /* RO: text and ro-data */
85684- mod->init_size = debug_align(mod->init_size);
85685- mod->init_ro_size = mod->init_size;
85686- break;
85687- case 3: /* whole init */
85688- mod->init_size = debug_align(mod->init_size);
85689- break;
85690- }
85691 }
85692 }
85693
85694@@ -2293,7 +2311,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85695
85696 /* Put symbol section at end of init part of module. */
85697 symsect->sh_flags |= SHF_ALLOC;
85698- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
85699+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
85700 info->index.sym) | INIT_OFFSET_MASK;
85701 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
85702
85703@@ -2310,13 +2328,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85704 }
85705
85706 /* Append room for core symbols at end of core part. */
85707- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
85708- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
85709- mod->core_size += strtab_size;
85710+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
85711+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
85712+ mod->core_size_rx += strtab_size;
85713
85714 /* Put string table section at end of init part of module. */
85715 strsect->sh_flags |= SHF_ALLOC;
85716- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
85717+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
85718 info->index.str) | INIT_OFFSET_MASK;
85719 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
85720 }
85721@@ -2334,12 +2352,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85722 /* Make sure we get permanent strtab: don't use info->strtab. */
85723 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
85724
85725+ pax_open_kernel();
85726+
85727 /* Set types up while we still have access to sections. */
85728 for (i = 0; i < mod->num_symtab; i++)
85729 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
85730
85731- mod->core_symtab = dst = mod->module_core + info->symoffs;
85732- mod->core_strtab = s = mod->module_core + info->stroffs;
85733+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
85734+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
85735 src = mod->symtab;
85736 for (ndst = i = 0; i < mod->num_symtab; i++) {
85737 if (i == 0 ||
85738@@ -2351,6 +2371,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85739 }
85740 }
85741 mod->core_num_syms = ndst;
85742+
85743+ pax_close_kernel();
85744 }
85745 #else
85746 static inline void layout_symtab(struct module *mod, struct load_info *info)
85747@@ -2384,17 +2406,33 @@ void * __weak module_alloc(unsigned long size)
85748 return vmalloc_exec(size);
85749 }
85750
85751-static void *module_alloc_update_bounds(unsigned long size)
85752+static void *module_alloc_update_bounds_rw(unsigned long size)
85753 {
85754 void *ret = module_alloc(size);
85755
85756 if (ret) {
85757 mutex_lock(&module_mutex);
85758 /* Update module bounds. */
85759- if ((unsigned long)ret < module_addr_min)
85760- module_addr_min = (unsigned long)ret;
85761- if ((unsigned long)ret + size > module_addr_max)
85762- module_addr_max = (unsigned long)ret + size;
85763+ if ((unsigned long)ret < module_addr_min_rw)
85764+ module_addr_min_rw = (unsigned long)ret;
85765+ if ((unsigned long)ret + size > module_addr_max_rw)
85766+ module_addr_max_rw = (unsigned long)ret + size;
85767+ mutex_unlock(&module_mutex);
85768+ }
85769+ return ret;
85770+}
85771+
85772+static void *module_alloc_update_bounds_rx(unsigned long size)
85773+{
85774+ void *ret = module_alloc_exec(size);
85775+
85776+ if (ret) {
85777+ mutex_lock(&module_mutex);
85778+ /* Update module bounds. */
85779+ if ((unsigned long)ret < module_addr_min_rx)
85780+ module_addr_min_rx = (unsigned long)ret;
85781+ if ((unsigned long)ret + size > module_addr_max_rx)
85782+ module_addr_max_rx = (unsigned long)ret + size;
85783 mutex_unlock(&module_mutex);
85784 }
85785 return ret;
85786@@ -2667,8 +2705,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
85787 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
85788 {
85789 const char *modmagic = get_modinfo(info, "vermagic");
85790+ const char *license = get_modinfo(info, "license");
85791 int err;
85792
85793+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
85794+ if (!license || !license_is_gpl_compatible(license))
85795+ return -ENOEXEC;
85796+#endif
85797+
85798 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
85799 modmagic = NULL;
85800
85801@@ -2693,7 +2737,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
85802 }
85803
85804 /* Set up license info based on the info section */
85805- set_license(mod, get_modinfo(info, "license"));
85806+ set_license(mod, license);
85807
85808 return 0;
85809 }
85810@@ -2787,7 +2831,7 @@ static int move_module(struct module *mod, struct load_info *info)
85811 void *ptr;
85812
85813 /* Do the allocs. */
85814- ptr = module_alloc_update_bounds(mod->core_size);
85815+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
85816 /*
85817 * The pointer to this block is stored in the module structure
85818 * which is inside the block. Just mark it as not being a
85819@@ -2797,11 +2841,11 @@ static int move_module(struct module *mod, struct load_info *info)
85820 if (!ptr)
85821 return -ENOMEM;
85822
85823- memset(ptr, 0, mod->core_size);
85824- mod->module_core = ptr;
85825+ memset(ptr, 0, mod->core_size_rw);
85826+ mod->module_core_rw = ptr;
85827
85828- if (mod->init_size) {
85829- ptr = module_alloc_update_bounds(mod->init_size);
85830+ if (mod->init_size_rw) {
85831+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
85832 /*
85833 * The pointer to this block is stored in the module structure
85834 * which is inside the block. This block doesn't need to be
85835@@ -2810,13 +2854,45 @@ static int move_module(struct module *mod, struct load_info *info)
85836 */
85837 kmemleak_ignore(ptr);
85838 if (!ptr) {
85839- module_free(mod, mod->module_core);
85840+ module_free(mod, mod->module_core_rw);
85841 return -ENOMEM;
85842 }
85843- memset(ptr, 0, mod->init_size);
85844- mod->module_init = ptr;
85845+ memset(ptr, 0, mod->init_size_rw);
85846+ mod->module_init_rw = ptr;
85847 } else
85848- mod->module_init = NULL;
85849+ mod->module_init_rw = NULL;
85850+
85851+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
85852+ kmemleak_not_leak(ptr);
85853+ if (!ptr) {
85854+ if (mod->module_init_rw)
85855+ module_free(mod, mod->module_init_rw);
85856+ module_free(mod, mod->module_core_rw);
85857+ return -ENOMEM;
85858+ }
85859+
85860+ pax_open_kernel();
85861+ memset(ptr, 0, mod->core_size_rx);
85862+ pax_close_kernel();
85863+ mod->module_core_rx = ptr;
85864+
85865+ if (mod->init_size_rx) {
85866+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
85867+ kmemleak_ignore(ptr);
85868+ if (!ptr && mod->init_size_rx) {
85869+ module_free_exec(mod, mod->module_core_rx);
85870+ if (mod->module_init_rw)
85871+ module_free(mod, mod->module_init_rw);
85872+ module_free(mod, mod->module_core_rw);
85873+ return -ENOMEM;
85874+ }
85875+
85876+ pax_open_kernel();
85877+ memset(ptr, 0, mod->init_size_rx);
85878+ pax_close_kernel();
85879+ mod->module_init_rx = ptr;
85880+ } else
85881+ mod->module_init_rx = NULL;
85882
85883 /* Transfer each section which specifies SHF_ALLOC */
85884 pr_debug("final section addresses:\n");
85885@@ -2827,16 +2903,45 @@ static int move_module(struct module *mod, struct load_info *info)
85886 if (!(shdr->sh_flags & SHF_ALLOC))
85887 continue;
85888
85889- if (shdr->sh_entsize & INIT_OFFSET_MASK)
85890- dest = mod->module_init
85891- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
85892- else
85893- dest = mod->module_core + shdr->sh_entsize;
85894+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
85895+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
85896+ dest = mod->module_init_rw
85897+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
85898+ else
85899+ dest = mod->module_init_rx
85900+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
85901+ } else {
85902+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
85903+ dest = mod->module_core_rw + shdr->sh_entsize;
85904+ else
85905+ dest = mod->module_core_rx + shdr->sh_entsize;
85906+ }
85907+
85908+ if (shdr->sh_type != SHT_NOBITS) {
85909+
85910+#ifdef CONFIG_PAX_KERNEXEC
85911+#ifdef CONFIG_X86_64
85912+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
85913+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
85914+#endif
85915+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
85916+ pax_open_kernel();
85917+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
85918+ pax_close_kernel();
85919+ } else
85920+#endif
85921
85922- if (shdr->sh_type != SHT_NOBITS)
85923 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
85924+ }
85925 /* Update sh_addr to point to copy in image. */
85926- shdr->sh_addr = (unsigned long)dest;
85927+
85928+#ifdef CONFIG_PAX_KERNEXEC
85929+ if (shdr->sh_flags & SHF_EXECINSTR)
85930+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
85931+ else
85932+#endif
85933+
85934+ shdr->sh_addr = (unsigned long)dest;
85935 pr_debug("\t0x%lx %s\n",
85936 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
85937 }
85938@@ -2893,12 +2998,12 @@ static void flush_module_icache(const struct module *mod)
85939 * Do it before processing of module parameters, so the module
85940 * can provide parameter accessor functions of its own.
85941 */
85942- if (mod->module_init)
85943- flush_icache_range((unsigned long)mod->module_init,
85944- (unsigned long)mod->module_init
85945- + mod->init_size);
85946- flush_icache_range((unsigned long)mod->module_core,
85947- (unsigned long)mod->module_core + mod->core_size);
85948+ if (mod->module_init_rx)
85949+ flush_icache_range((unsigned long)mod->module_init_rx,
85950+ (unsigned long)mod->module_init_rx
85951+ + mod->init_size_rx);
85952+ flush_icache_range((unsigned long)mod->module_core_rx,
85953+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
85954
85955 set_fs(old_fs);
85956 }
85957@@ -2955,8 +3060,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
85958 static void module_deallocate(struct module *mod, struct load_info *info)
85959 {
85960 percpu_modfree(mod);
85961- module_free(mod, mod->module_init);
85962- module_free(mod, mod->module_core);
85963+ module_free_exec(mod, mod->module_init_rx);
85964+ module_free_exec(mod, mod->module_core_rx);
85965+ module_free(mod, mod->module_init_rw);
85966+ module_free(mod, mod->module_core_rw);
85967 }
85968
85969 int __weak module_finalize(const Elf_Ehdr *hdr,
85970@@ -2969,7 +3076,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
85971 static int post_relocation(struct module *mod, const struct load_info *info)
85972 {
85973 /* Sort exception table now relocations are done. */
85974+ pax_open_kernel();
85975 sort_extable(mod->extable, mod->extable + mod->num_exentries);
85976+ pax_close_kernel();
85977
85978 /* Copy relocated percpu area over. */
85979 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
85980@@ -3023,16 +3132,16 @@ static int do_init_module(struct module *mod)
85981 MODULE_STATE_COMING, mod);
85982
85983 /* Set RO and NX regions for core */
85984- set_section_ro_nx(mod->module_core,
85985- mod->core_text_size,
85986- mod->core_ro_size,
85987- mod->core_size);
85988+ set_section_ro_nx(mod->module_core_rx,
85989+ mod->core_size_rx,
85990+ mod->core_size_rx,
85991+ mod->core_size_rx);
85992
85993 /* Set RO and NX regions for init */
85994- set_section_ro_nx(mod->module_init,
85995- mod->init_text_size,
85996- mod->init_ro_size,
85997- mod->init_size);
85998+ set_section_ro_nx(mod->module_init_rx,
85999+ mod->init_size_rx,
86000+ mod->init_size_rx,
86001+ mod->init_size_rx);
86002
86003 do_mod_ctors(mod);
86004 /* Start the module */
86005@@ -3093,11 +3202,12 @@ static int do_init_module(struct module *mod)
86006 mod->strtab = mod->core_strtab;
86007 #endif
86008 unset_module_init_ro_nx(mod);
86009- module_free(mod, mod->module_init);
86010- mod->module_init = NULL;
86011- mod->init_size = 0;
86012- mod->init_ro_size = 0;
86013- mod->init_text_size = 0;
86014+ module_free(mod, mod->module_init_rw);
86015+ module_free_exec(mod, mod->module_init_rx);
86016+ mod->module_init_rw = NULL;
86017+ mod->module_init_rx = NULL;
86018+ mod->init_size_rw = 0;
86019+ mod->init_size_rx = 0;
86020 mutex_unlock(&module_mutex);
86021 wake_up_all(&module_wq);
86022
86023@@ -3240,9 +3350,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
86024 if (err)
86025 goto free_unload;
86026
86027+ /* Now copy in args */
86028+ mod->args = strndup_user(uargs, ~0UL >> 1);
86029+ if (IS_ERR(mod->args)) {
86030+ err = PTR_ERR(mod->args);
86031+ goto free_unload;
86032+ }
86033+
86034 /* Set up MODINFO_ATTR fields */
86035 setup_modinfo(mod, info);
86036
86037+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86038+ {
86039+ char *p, *p2;
86040+
86041+ if (strstr(mod->args, "grsec_modharden_netdev")) {
86042+ 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);
86043+ err = -EPERM;
86044+ goto free_modinfo;
86045+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
86046+ p += sizeof("grsec_modharden_normal") - 1;
86047+ p2 = strstr(p, "_");
86048+ if (p2) {
86049+ *p2 = '\0';
86050+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
86051+ *p2 = '_';
86052+ }
86053+ err = -EPERM;
86054+ goto free_modinfo;
86055+ }
86056+ }
86057+#endif
86058+
86059 /* Fix up syms, so that st_value is a pointer to location. */
86060 err = simplify_symbols(mod, info);
86061 if (err < 0)
86062@@ -3258,13 +3397,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
86063
86064 flush_module_icache(mod);
86065
86066- /* Now copy in args */
86067- mod->args = strndup_user(uargs, ~0UL >> 1);
86068- if (IS_ERR(mod->args)) {
86069- err = PTR_ERR(mod->args);
86070- goto free_arch_cleanup;
86071- }
86072-
86073 dynamic_debug_setup(info->debug, info->num_debug);
86074
86075 /* Finally it's fully formed, ready to start executing. */
86076@@ -3299,11 +3431,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
86077 ddebug_cleanup:
86078 dynamic_debug_remove(info->debug);
86079 synchronize_sched();
86080- kfree(mod->args);
86081- free_arch_cleanup:
86082 module_arch_cleanup(mod);
86083 free_modinfo:
86084 free_modinfo(mod);
86085+ kfree(mod->args);
86086 free_unload:
86087 module_unload_free(mod);
86088 unlink_mod:
86089@@ -3386,10 +3517,16 @@ static const char *get_ksymbol(struct module *mod,
86090 unsigned long nextval;
86091
86092 /* At worse, next value is at end of module */
86093- if (within_module_init(addr, mod))
86094- nextval = (unsigned long)mod->module_init+mod->init_text_size;
86095+ if (within_module_init_rx(addr, mod))
86096+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
86097+ else if (within_module_init_rw(addr, mod))
86098+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
86099+ else if (within_module_core_rx(addr, mod))
86100+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
86101+ else if (within_module_core_rw(addr, mod))
86102+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
86103 else
86104- nextval = (unsigned long)mod->module_core+mod->core_text_size;
86105+ return NULL;
86106
86107 /* Scan for closest preceding symbol, and next symbol. (ELF
86108 starts real symbols at 1). */
86109@@ -3640,7 +3777,7 @@ static int m_show(struct seq_file *m, void *p)
86110 return 0;
86111
86112 seq_printf(m, "%s %u",
86113- mod->name, mod->init_size + mod->core_size);
86114+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
86115 print_unload_info(m, mod);
86116
86117 /* Informative for users. */
86118@@ -3649,7 +3786,7 @@ static int m_show(struct seq_file *m, void *p)
86119 mod->state == MODULE_STATE_COMING ? "Loading":
86120 "Live");
86121 /* Used by oprofile and other similar tools. */
86122- seq_printf(m, " 0x%pK", mod->module_core);
86123+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
86124
86125 /* Taints info */
86126 if (mod->taints)
86127@@ -3685,7 +3822,17 @@ static const struct file_operations proc_modules_operations = {
86128
86129 static int __init proc_modules_init(void)
86130 {
86131+#ifndef CONFIG_GRKERNSEC_HIDESYM
86132+#ifdef CONFIG_GRKERNSEC_PROC_USER
86133+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86134+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86135+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
86136+#else
86137 proc_create("modules", 0, NULL, &proc_modules_operations);
86138+#endif
86139+#else
86140+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86141+#endif
86142 return 0;
86143 }
86144 module_init(proc_modules_init);
86145@@ -3746,14 +3893,14 @@ struct module *__module_address(unsigned long addr)
86146 {
86147 struct module *mod;
86148
86149- if (addr < module_addr_min || addr > module_addr_max)
86150+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
86151+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
86152 return NULL;
86153
86154 list_for_each_entry_rcu(mod, &modules, list) {
86155 if (mod->state == MODULE_STATE_UNFORMED)
86156 continue;
86157- if (within_module_core(addr, mod)
86158- || within_module_init(addr, mod))
86159+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
86160 return mod;
86161 }
86162 return NULL;
86163@@ -3788,11 +3935,20 @@ bool is_module_text_address(unsigned long addr)
86164 */
86165 struct module *__module_text_address(unsigned long addr)
86166 {
86167- struct module *mod = __module_address(addr);
86168+ struct module *mod;
86169+
86170+#ifdef CONFIG_X86_32
86171+ addr = ktla_ktva(addr);
86172+#endif
86173+
86174+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
86175+ return NULL;
86176+
86177+ mod = __module_address(addr);
86178+
86179 if (mod) {
86180 /* Make sure it's within the text section. */
86181- if (!within(addr, mod->module_init, mod->init_text_size)
86182- && !within(addr, mod->module_core, mod->core_text_size))
86183+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
86184 mod = NULL;
86185 }
86186 return mod;
86187diff --git a/kernel/notifier.c b/kernel/notifier.c
86188index 2d5cc4c..d9ea600 100644
86189--- a/kernel/notifier.c
86190+++ b/kernel/notifier.c
86191@@ -5,6 +5,7 @@
86192 #include <linux/rcupdate.h>
86193 #include <linux/vmalloc.h>
86194 #include <linux/reboot.h>
86195+#include <linux/mm.h>
86196
86197 /*
86198 * Notifier list for kernel code which wants to be called
86199@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
86200 while ((*nl) != NULL) {
86201 if (n->priority > (*nl)->priority)
86202 break;
86203- nl = &((*nl)->next);
86204+ nl = (struct notifier_block **)&((*nl)->next);
86205 }
86206- n->next = *nl;
86207+ pax_open_kernel();
86208+ *(const void **)&n->next = *nl;
86209 rcu_assign_pointer(*nl, n);
86210+ pax_close_kernel();
86211 return 0;
86212 }
86213
86214@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
86215 return 0;
86216 if (n->priority > (*nl)->priority)
86217 break;
86218- nl = &((*nl)->next);
86219+ nl = (struct notifier_block **)&((*nl)->next);
86220 }
86221- n->next = *nl;
86222+ pax_open_kernel();
86223+ *(const void **)&n->next = *nl;
86224 rcu_assign_pointer(*nl, n);
86225+ pax_close_kernel();
86226 return 0;
86227 }
86228
86229@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
86230 {
86231 while ((*nl) != NULL) {
86232 if ((*nl) == n) {
86233+ pax_open_kernel();
86234 rcu_assign_pointer(*nl, n->next);
86235+ pax_close_kernel();
86236 return 0;
86237 }
86238- nl = &((*nl)->next);
86239+ nl = (struct notifier_block **)&((*nl)->next);
86240 }
86241 return -ENOENT;
86242 }
86243diff --git a/kernel/padata.c b/kernel/padata.c
86244index 2abd25d..02c4faa 100644
86245--- a/kernel/padata.c
86246+++ b/kernel/padata.c
86247@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
86248 * seq_nr mod. number of cpus in use.
86249 */
86250
86251- seq_nr = atomic_inc_return(&pd->seq_nr);
86252+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
86253 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
86254
86255 return padata_index_to_cpu(pd, cpu_index);
86256@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
86257 padata_init_pqueues(pd);
86258 padata_init_squeues(pd);
86259 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
86260- atomic_set(&pd->seq_nr, -1);
86261+ atomic_set_unchecked(&pd->seq_nr, -1);
86262 atomic_set(&pd->reorder_objects, 0);
86263 atomic_set(&pd->refcnt, 0);
86264 pd->pinst = pinst;
86265diff --git a/kernel/panic.c b/kernel/panic.c
86266index c00b4ce..a846117 100644
86267--- a/kernel/panic.c
86268+++ b/kernel/panic.c
86269@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
86270 disable_trace_on_warning();
86271
86272 pr_warn("------------[ cut here ]------------\n");
86273- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
86274+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
86275 raw_smp_processor_id(), current->pid, file, line, caller);
86276
86277 if (args)
86278@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
86279 */
86280 void __stack_chk_fail(void)
86281 {
86282- panic("stack-protector: Kernel stack is corrupted in: %p\n",
86283+ dump_stack();
86284+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
86285 __builtin_return_address(0));
86286 }
86287 EXPORT_SYMBOL(__stack_chk_fail);
86288diff --git a/kernel/pid.c b/kernel/pid.c
86289index 9b9a266..c20ef80 100644
86290--- a/kernel/pid.c
86291+++ b/kernel/pid.c
86292@@ -33,6 +33,7 @@
86293 #include <linux/rculist.h>
86294 #include <linux/bootmem.h>
86295 #include <linux/hash.h>
86296+#include <linux/security.h>
86297 #include <linux/pid_namespace.h>
86298 #include <linux/init_task.h>
86299 #include <linux/syscalls.h>
86300@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
86301
86302 int pid_max = PID_MAX_DEFAULT;
86303
86304-#define RESERVED_PIDS 300
86305+#define RESERVED_PIDS 500
86306
86307 int pid_max_min = RESERVED_PIDS + 1;
86308 int pid_max_max = PID_MAX_LIMIT;
86309@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
86310 */
86311 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
86312 {
86313+ struct task_struct *task;
86314+
86315 rcu_lockdep_assert(rcu_read_lock_held(),
86316 "find_task_by_pid_ns() needs rcu_read_lock()"
86317 " protection");
86318- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86319+
86320+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86321+
86322+ if (gr_pid_is_chrooted(task))
86323+ return NULL;
86324+
86325+ return task;
86326 }
86327
86328 struct task_struct *find_task_by_vpid(pid_t vnr)
86329@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
86330 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
86331 }
86332
86333+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
86334+{
86335+ rcu_lockdep_assert(rcu_read_lock_held(),
86336+ "find_task_by_pid_ns() needs rcu_read_lock()"
86337+ " protection");
86338+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
86339+}
86340+
86341 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
86342 {
86343 struct pid *pid;
86344diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
86345index 06c62de..b08cc6c 100644
86346--- a/kernel/pid_namespace.c
86347+++ b/kernel/pid_namespace.c
86348@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
86349 void __user *buffer, size_t *lenp, loff_t *ppos)
86350 {
86351 struct pid_namespace *pid_ns = task_active_pid_ns(current);
86352- struct ctl_table tmp = *table;
86353+ ctl_table_no_const tmp = *table;
86354
86355 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
86356 return -EPERM;
86357diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
86358index c7f31aa..2b44977 100644
86359--- a/kernel/posix-cpu-timers.c
86360+++ b/kernel/posix-cpu-timers.c
86361@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
86362
86363 static __init int init_posix_cpu_timers(void)
86364 {
86365- struct k_clock process = {
86366+ static struct k_clock process = {
86367 .clock_getres = process_cpu_clock_getres,
86368 .clock_get = process_cpu_clock_get,
86369 .timer_create = process_cpu_timer_create,
86370 .nsleep = process_cpu_nsleep,
86371 .nsleep_restart = process_cpu_nsleep_restart,
86372 };
86373- struct k_clock thread = {
86374+ static struct k_clock thread = {
86375 .clock_getres = thread_cpu_clock_getres,
86376 .clock_get = thread_cpu_clock_get,
86377 .timer_create = thread_cpu_timer_create,
86378diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
86379index 424c2d4..679242f 100644
86380--- a/kernel/posix-timers.c
86381+++ b/kernel/posix-timers.c
86382@@ -43,6 +43,7 @@
86383 #include <linux/hash.h>
86384 #include <linux/posix-clock.h>
86385 #include <linux/posix-timers.h>
86386+#include <linux/grsecurity.h>
86387 #include <linux/syscalls.h>
86388 #include <linux/wait.h>
86389 #include <linux/workqueue.h>
86390@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
86391 * which we beg off on and pass to do_sys_settimeofday().
86392 */
86393
86394-static struct k_clock posix_clocks[MAX_CLOCKS];
86395+static struct k_clock *posix_clocks[MAX_CLOCKS];
86396
86397 /*
86398 * These ones are defined below.
86399@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
86400 */
86401 static __init int init_posix_timers(void)
86402 {
86403- struct k_clock clock_realtime = {
86404+ static struct k_clock clock_realtime = {
86405 .clock_getres = hrtimer_get_res,
86406 .clock_get = posix_clock_realtime_get,
86407 .clock_set = posix_clock_realtime_set,
86408@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
86409 .timer_get = common_timer_get,
86410 .timer_del = common_timer_del,
86411 };
86412- struct k_clock clock_monotonic = {
86413+ static struct k_clock clock_monotonic = {
86414 .clock_getres = hrtimer_get_res,
86415 .clock_get = posix_ktime_get_ts,
86416 .nsleep = common_nsleep,
86417@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
86418 .timer_get = common_timer_get,
86419 .timer_del = common_timer_del,
86420 };
86421- struct k_clock clock_monotonic_raw = {
86422+ static struct k_clock clock_monotonic_raw = {
86423 .clock_getres = hrtimer_get_res,
86424 .clock_get = posix_get_monotonic_raw,
86425 };
86426- struct k_clock clock_realtime_coarse = {
86427+ static struct k_clock clock_realtime_coarse = {
86428 .clock_getres = posix_get_coarse_res,
86429 .clock_get = posix_get_realtime_coarse,
86430 };
86431- struct k_clock clock_monotonic_coarse = {
86432+ static struct k_clock clock_monotonic_coarse = {
86433 .clock_getres = posix_get_coarse_res,
86434 .clock_get = posix_get_monotonic_coarse,
86435 };
86436- struct k_clock clock_tai = {
86437+ static struct k_clock clock_tai = {
86438 .clock_getres = hrtimer_get_res,
86439 .clock_get = posix_get_tai,
86440 .nsleep = common_nsleep,
86441@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
86442 .timer_get = common_timer_get,
86443 .timer_del = common_timer_del,
86444 };
86445- struct k_clock clock_boottime = {
86446+ static struct k_clock clock_boottime = {
86447 .clock_getres = hrtimer_get_res,
86448 .clock_get = posix_get_boottime,
86449 .nsleep = common_nsleep,
86450@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
86451 return;
86452 }
86453
86454- posix_clocks[clock_id] = *new_clock;
86455+ posix_clocks[clock_id] = new_clock;
86456 }
86457 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
86458
86459@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
86460 return (id & CLOCKFD_MASK) == CLOCKFD ?
86461 &clock_posix_dynamic : &clock_posix_cpu;
86462
86463- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
86464+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
86465 return NULL;
86466- return &posix_clocks[id];
86467+ return posix_clocks[id];
86468 }
86469
86470 static int common_timer_create(struct k_itimer *new_timer)
86471@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
86472 struct k_clock *kc = clockid_to_kclock(which_clock);
86473 struct k_itimer *new_timer;
86474 int error, new_timer_id;
86475- sigevent_t event;
86476+ sigevent_t event = { };
86477 int it_id_set = IT_ID_NOT_SET;
86478
86479 if (!kc)
86480@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
86481 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
86482 return -EFAULT;
86483
86484+ /* only the CLOCK_REALTIME clock can be set, all other clocks
86485+ have their clock_set fptr set to a nosettime dummy function
86486+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
86487+ call common_clock_set, which calls do_sys_settimeofday, which
86488+ we hook
86489+ */
86490+
86491 return kc->clock_set(which_clock, &new_tp);
86492 }
86493
86494diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
86495index 2fac9cc..56fef29 100644
86496--- a/kernel/power/Kconfig
86497+++ b/kernel/power/Kconfig
86498@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
86499 config HIBERNATION
86500 bool "Hibernation (aka 'suspend to disk')"
86501 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
86502+ depends on !GRKERNSEC_KMEM
86503+ depends on !PAX_MEMORY_SANITIZE
86504 select HIBERNATE_CALLBACKS
86505 select LZO_COMPRESS
86506 select LZO_DECOMPRESS
86507diff --git a/kernel/power/process.c b/kernel/power/process.c
86508index 06ec886..9dba35e 100644
86509--- a/kernel/power/process.c
86510+++ b/kernel/power/process.c
86511@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
86512 unsigned int elapsed_msecs;
86513 bool wakeup = false;
86514 int sleep_usecs = USEC_PER_MSEC;
86515+ bool timedout = false;
86516
86517 do_gettimeofday(&start);
86518
86519@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
86520
86521 while (true) {
86522 todo = 0;
86523+ if (time_after(jiffies, end_time))
86524+ timedout = true;
86525 read_lock(&tasklist_lock);
86526 do_each_thread(g, p) {
86527 if (p == current || !freeze_task(p))
86528 continue;
86529
86530- if (!freezer_should_skip(p))
86531+ if (!freezer_should_skip(p)) {
86532 todo++;
86533+ if (timedout) {
86534+ printk(KERN_ERR "Task refusing to freeze:\n");
86535+ sched_show_task(p);
86536+ }
86537+ }
86538 } while_each_thread(g, p);
86539 read_unlock(&tasklist_lock);
86540
86541@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
86542 todo += wq_busy;
86543 }
86544
86545- if (!todo || time_after(jiffies, end_time))
86546+ if (!todo || timedout)
86547 break;
86548
86549 if (pm_wakeup_pending()) {
86550diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
86551index be7c86b..c741464 100644
86552--- a/kernel/printk/printk.c
86553+++ b/kernel/printk/printk.c
86554@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
86555 if (from_file && type != SYSLOG_ACTION_OPEN)
86556 return 0;
86557
86558+#ifdef CONFIG_GRKERNSEC_DMESG
86559+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
86560+ return -EPERM;
86561+#endif
86562+
86563 if (syslog_action_restricted(type)) {
86564 if (capable(CAP_SYSLOG))
86565 return 0;
86566diff --git a/kernel/profile.c b/kernel/profile.c
86567index 6631e1e..310c266 100644
86568--- a/kernel/profile.c
86569+++ b/kernel/profile.c
86570@@ -37,7 +37,7 @@ struct profile_hit {
86571 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
86572 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
86573
86574-static atomic_t *prof_buffer;
86575+static atomic_unchecked_t *prof_buffer;
86576 static unsigned long prof_len, prof_shift;
86577
86578 int prof_on __read_mostly;
86579@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
86580 hits[i].pc = 0;
86581 continue;
86582 }
86583- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86584+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86585 hits[i].hits = hits[i].pc = 0;
86586 }
86587 }
86588@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86589 * Add the current hit(s) and flush the write-queue out
86590 * to the global buffer:
86591 */
86592- atomic_add(nr_hits, &prof_buffer[pc]);
86593+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
86594 for (i = 0; i < NR_PROFILE_HIT; ++i) {
86595- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86596+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86597 hits[i].pc = hits[i].hits = 0;
86598 }
86599 out:
86600@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86601 {
86602 unsigned long pc;
86603 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
86604- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86605+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86606 }
86607 #endif /* !CONFIG_SMP */
86608
86609@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
86610 return -EFAULT;
86611 buf++; p++; count--; read++;
86612 }
86613- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
86614+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
86615 if (copy_to_user(buf, (void *)pnt, count))
86616 return -EFAULT;
86617 read += count;
86618@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
86619 }
86620 #endif
86621 profile_discard_flip_buffers();
86622- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
86623+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
86624 return count;
86625 }
86626
86627diff --git a/kernel/ptrace.c b/kernel/ptrace.c
86628index 1f4bcb3..99cf7ab 100644
86629--- a/kernel/ptrace.c
86630+++ b/kernel/ptrace.c
86631@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
86632 if (seize)
86633 flags |= PT_SEIZED;
86634 rcu_read_lock();
86635- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86636+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86637 flags |= PT_PTRACE_CAP;
86638 rcu_read_unlock();
86639 task->ptrace = flags;
86640@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
86641 break;
86642 return -EIO;
86643 }
86644- if (copy_to_user(dst, buf, retval))
86645+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
86646 return -EFAULT;
86647 copied += retval;
86648 src += retval;
86649@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
86650 bool seized = child->ptrace & PT_SEIZED;
86651 int ret = -EIO;
86652 siginfo_t siginfo, *si;
86653- void __user *datavp = (void __user *) data;
86654+ void __user *datavp = (__force void __user *) data;
86655 unsigned long __user *datalp = datavp;
86656 unsigned long flags;
86657
86658@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
86659 goto out;
86660 }
86661
86662+ if (gr_handle_ptrace(child, request)) {
86663+ ret = -EPERM;
86664+ goto out_put_task_struct;
86665+ }
86666+
86667 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86668 ret = ptrace_attach(child, request, addr, data);
86669 /*
86670 * Some architectures need to do book-keeping after
86671 * a ptrace attach.
86672 */
86673- if (!ret)
86674+ if (!ret) {
86675 arch_ptrace_attach(child);
86676+ gr_audit_ptrace(child);
86677+ }
86678 goto out_put_task_struct;
86679 }
86680
86681@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
86682 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
86683 if (copied != sizeof(tmp))
86684 return -EIO;
86685- return put_user(tmp, (unsigned long __user *)data);
86686+ return put_user(tmp, (__force unsigned long __user *)data);
86687 }
86688
86689 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
86690@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
86691 }
86692
86693 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86694- compat_long_t addr, compat_long_t data)
86695+ compat_ulong_t addr, compat_ulong_t data)
86696 {
86697 struct task_struct *child;
86698 long ret;
86699@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86700 goto out;
86701 }
86702
86703+ if (gr_handle_ptrace(child, request)) {
86704+ ret = -EPERM;
86705+ goto out_put_task_struct;
86706+ }
86707+
86708 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86709 ret = ptrace_attach(child, request, addr, data);
86710 /*
86711 * Some architectures need to do book-keeping after
86712 * a ptrace attach.
86713 */
86714- if (!ret)
86715+ if (!ret) {
86716 arch_ptrace_attach(child);
86717+ gr_audit_ptrace(child);
86718+ }
86719 goto out_put_task_struct;
86720 }
86721
86722diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
86723index 01d5ccb..cdcbee6 100644
86724--- a/kernel/rcu/srcu.c
86725+++ b/kernel/rcu/srcu.c
86726@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
86727
86728 idx = ACCESS_ONCE(sp->completed) & 0x1;
86729 preempt_disable();
86730- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
86731+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
86732 smp_mb(); /* B */ /* Avoid leaking the critical section. */
86733- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
86734+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
86735 preempt_enable();
86736 return idx;
86737 }
86738diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
86739index 1254f31..16258dc 100644
86740--- a/kernel/rcu/tiny.c
86741+++ b/kernel/rcu/tiny.c
86742@@ -46,7 +46,7 @@
86743 /* Forward declarations for tiny_plugin.h. */
86744 struct rcu_ctrlblk;
86745 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
86746-static void rcu_process_callbacks(struct softirq_action *unused);
86747+static void rcu_process_callbacks(void);
86748 static void __call_rcu(struct rcu_head *head,
86749 void (*func)(struct rcu_head *rcu),
86750 struct rcu_ctrlblk *rcp);
86751@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
86752 false));
86753 }
86754
86755-static void rcu_process_callbacks(struct softirq_action *unused)
86756+static __latent_entropy void rcu_process_callbacks(void)
86757 {
86758 __rcu_process_callbacks(&rcu_sched_ctrlblk);
86759 __rcu_process_callbacks(&rcu_bh_ctrlblk);
86760diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
86761index 3929cd4..421624d 100644
86762--- a/kernel/rcu/torture.c
86763+++ b/kernel/rcu/torture.c
86764@@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
86765 { 0 };
86766 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
86767 { 0 };
86768-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
86769-static atomic_t n_rcu_torture_alloc;
86770-static atomic_t n_rcu_torture_alloc_fail;
86771-static atomic_t n_rcu_torture_free;
86772-static atomic_t n_rcu_torture_mberror;
86773-static atomic_t n_rcu_torture_error;
86774+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
86775+static atomic_unchecked_t n_rcu_torture_alloc;
86776+static atomic_unchecked_t n_rcu_torture_alloc_fail;
86777+static atomic_unchecked_t n_rcu_torture_free;
86778+static atomic_unchecked_t n_rcu_torture_mberror;
86779+static atomic_unchecked_t n_rcu_torture_error;
86780 static long n_rcu_torture_barrier_error;
86781 static long n_rcu_torture_boost_ktrerror;
86782 static long n_rcu_torture_boost_rterror;
86783@@ -299,11 +299,11 @@ rcu_torture_alloc(void)
86784
86785 spin_lock_bh(&rcu_torture_lock);
86786 if (list_empty(&rcu_torture_freelist)) {
86787- atomic_inc(&n_rcu_torture_alloc_fail);
86788+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
86789 spin_unlock_bh(&rcu_torture_lock);
86790 return NULL;
86791 }
86792- atomic_inc(&n_rcu_torture_alloc);
86793+ atomic_inc_unchecked(&n_rcu_torture_alloc);
86794 p = rcu_torture_freelist.next;
86795 list_del_init(p);
86796 spin_unlock_bh(&rcu_torture_lock);
86797@@ -316,7 +316,7 @@ rcu_torture_alloc(void)
86798 static void
86799 rcu_torture_free(struct rcu_torture *p)
86800 {
86801- atomic_inc(&n_rcu_torture_free);
86802+ atomic_inc_unchecked(&n_rcu_torture_free);
86803 spin_lock_bh(&rcu_torture_lock);
86804 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
86805 spin_unlock_bh(&rcu_torture_lock);
86806@@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
86807 i = rp->rtort_pipe_count;
86808 if (i > RCU_TORTURE_PIPE_LEN)
86809 i = RCU_TORTURE_PIPE_LEN;
86810- atomic_inc(&rcu_torture_wcount[i]);
86811+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
86812 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
86813 rp->rtort_mbtest = 0;
86814 rcu_torture_free(rp);
86815@@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
86816 i = old_rp->rtort_pipe_count;
86817 if (i > RCU_TORTURE_PIPE_LEN)
86818 i = RCU_TORTURE_PIPE_LEN;
86819- atomic_inc(&rcu_torture_wcount[i]);
86820+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
86821 old_rp->rtort_pipe_count++;
86822 if (gp_normal == gp_exp)
86823 exp = !!(rcu_random(&rand) & 0x80);
86824@@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
86825 i = rp->rtort_pipe_count;
86826 if (i > RCU_TORTURE_PIPE_LEN)
86827 i = RCU_TORTURE_PIPE_LEN;
86828- atomic_inc(&rcu_torture_wcount[i]);
86829+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
86830 if (++rp->rtort_pipe_count >=
86831 RCU_TORTURE_PIPE_LEN) {
86832 rp->rtort_mbtest = 0;
86833@@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
86834 return;
86835 }
86836 if (p->rtort_mbtest == 0)
86837- atomic_inc(&n_rcu_torture_mberror);
86838+ atomic_inc_unchecked(&n_rcu_torture_mberror);
86839 spin_lock(&rand_lock);
86840 cur_ops->read_delay(&rand);
86841 n_rcu_torture_timers++;
86842@@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
86843 continue;
86844 }
86845 if (p->rtort_mbtest == 0)
86846- atomic_inc(&n_rcu_torture_mberror);
86847+ atomic_inc_unchecked(&n_rcu_torture_mberror);
86848 cur_ops->read_delay(&rand);
86849 preempt_disable();
86850 pipe_count = p->rtort_pipe_count;
86851@@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
86852 rcu_torture_current,
86853 rcu_torture_current_version,
86854 list_empty(&rcu_torture_freelist),
86855- atomic_read(&n_rcu_torture_alloc),
86856- atomic_read(&n_rcu_torture_alloc_fail),
86857- atomic_read(&n_rcu_torture_free));
86858+ atomic_read_unchecked(&n_rcu_torture_alloc),
86859+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
86860+ atomic_read_unchecked(&n_rcu_torture_free));
86861 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
86862- atomic_read(&n_rcu_torture_mberror),
86863+ atomic_read_unchecked(&n_rcu_torture_mberror),
86864 n_rcu_torture_boost_ktrerror,
86865 n_rcu_torture_boost_rterror);
86866 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
86867@@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
86868 n_barrier_attempts,
86869 n_rcu_torture_barrier_error);
86870 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
86871- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
86872+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
86873 n_rcu_torture_barrier_error != 0 ||
86874 n_rcu_torture_boost_ktrerror != 0 ||
86875 n_rcu_torture_boost_rterror != 0 ||
86876 n_rcu_torture_boost_failure != 0 ||
86877 i > 1) {
86878 cnt += sprintf(&page[cnt], "!!! ");
86879- atomic_inc(&n_rcu_torture_error);
86880+ atomic_inc_unchecked(&n_rcu_torture_error);
86881 WARN_ON_ONCE(1);
86882 }
86883 cnt += sprintf(&page[cnt], "Reader Pipe: ");
86884@@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
86885 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
86886 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
86887 cnt += sprintf(&page[cnt], " %d",
86888- atomic_read(&rcu_torture_wcount[i]));
86889+ atomic_read_unchecked(&rcu_torture_wcount[i]));
86890 }
86891 cnt += sprintf(&page[cnt], "\n");
86892 if (cur_ops->stats)
86893@@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
86894
86895 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
86896
86897- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
86898+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
86899 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
86900 else if (n_online_successes != n_online_attempts ||
86901 n_offline_successes != n_offline_attempts)
86902@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
86903
86904 rcu_torture_current = NULL;
86905 rcu_torture_current_version = 0;
86906- atomic_set(&n_rcu_torture_alloc, 0);
86907- atomic_set(&n_rcu_torture_alloc_fail, 0);
86908- atomic_set(&n_rcu_torture_free, 0);
86909- atomic_set(&n_rcu_torture_mberror, 0);
86910- atomic_set(&n_rcu_torture_error, 0);
86911+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
86912+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
86913+ atomic_set_unchecked(&n_rcu_torture_free, 0);
86914+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
86915+ atomic_set_unchecked(&n_rcu_torture_error, 0);
86916 n_rcu_torture_barrier_error = 0;
86917 n_rcu_torture_boost_ktrerror = 0;
86918 n_rcu_torture_boost_rterror = 0;
86919 n_rcu_torture_boost_failure = 0;
86920 n_rcu_torture_boosts = 0;
86921 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
86922- atomic_set(&rcu_torture_wcount[i], 0);
86923+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
86924 for_each_possible_cpu(cpu) {
86925 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
86926 per_cpu(rcu_torture_count, cpu)[i] = 0;
86927diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
86928index dd08198..5ccccbe 100644
86929--- a/kernel/rcu/tree.c
86930+++ b/kernel/rcu/tree.c
86931@@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
86932 rcu_prepare_for_idle(smp_processor_id());
86933 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
86934 smp_mb__before_atomic_inc(); /* See above. */
86935- atomic_inc(&rdtp->dynticks);
86936+ atomic_inc_unchecked(&rdtp->dynticks);
86937 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
86938- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
86939+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
86940
86941 /*
86942 * It is illegal to enter an extended quiescent state while
86943@@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
86944 int user)
86945 {
86946 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
86947- atomic_inc(&rdtp->dynticks);
86948+ atomic_inc_unchecked(&rdtp->dynticks);
86949 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
86950 smp_mb__after_atomic_inc(); /* See above. */
86951- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
86952+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
86953 rcu_cleanup_after_idle(smp_processor_id());
86954 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
86955 if (!user && !is_idle_task(current)) {
86956@@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
86957 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
86958
86959 if (rdtp->dynticks_nmi_nesting == 0 &&
86960- (atomic_read(&rdtp->dynticks) & 0x1))
86961+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
86962 return;
86963 rdtp->dynticks_nmi_nesting++;
86964 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
86965- atomic_inc(&rdtp->dynticks);
86966+ atomic_inc_unchecked(&rdtp->dynticks);
86967 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
86968 smp_mb__after_atomic_inc(); /* See above. */
86969- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
86970+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
86971 }
86972
86973 /**
86974@@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
86975 return;
86976 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
86977 smp_mb__before_atomic_inc(); /* See above. */
86978- atomic_inc(&rdtp->dynticks);
86979+ atomic_inc_unchecked(&rdtp->dynticks);
86980 smp_mb__after_atomic_inc(); /* Force delay to next write. */
86981- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
86982+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
86983 }
86984
86985 /**
86986@@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
86987 */
86988 bool notrace __rcu_is_watching(void)
86989 {
86990- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
86991+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
86992 }
86993
86994 /**
86995@@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
86996 static int dyntick_save_progress_counter(struct rcu_data *rdp,
86997 bool *isidle, unsigned long *maxj)
86998 {
86999- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
87000+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87001 rcu_sysidle_check_cpu(rdp, isidle, maxj);
87002 return (rdp->dynticks_snap & 0x1) == 0;
87003 }
87004@@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
87005 unsigned int curr;
87006 unsigned int snap;
87007
87008- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
87009+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87010 snap = (unsigned int)rdp->dynticks_snap;
87011
87012 /*
87013@@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
87014 rdp = this_cpu_ptr(rsp->rda);
87015 rcu_preempt_check_blocked_tasks(rnp);
87016 rnp->qsmask = rnp->qsmaskinit;
87017- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
87018+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
87019 WARN_ON_ONCE(rnp->completed != rsp->completed);
87020- ACCESS_ONCE(rnp->completed) = rsp->completed;
87021+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
87022 if (rnp == rdp->mynode)
87023 __note_gp_changes(rsp, rnp, rdp);
87024 rcu_preempt_boost_start_gp(rnp);
87025@@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
87026 */
87027 rcu_for_each_node_breadth_first(rsp, rnp) {
87028 raw_spin_lock_irq(&rnp->lock);
87029- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
87030+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
87031 rdp = this_cpu_ptr(rsp->rda);
87032 if (rnp == rdp->mynode)
87033 __note_gp_changes(rsp, rnp, rdp);
87034@@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
87035 rsp->qlen += rdp->qlen;
87036 rdp->n_cbs_orphaned += rdp->qlen;
87037 rdp->qlen_lazy = 0;
87038- ACCESS_ONCE(rdp->qlen) = 0;
87039+ ACCESS_ONCE_RW(rdp->qlen) = 0;
87040 }
87041
87042 /*
87043@@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
87044 }
87045 smp_mb(); /* List handling before counting for rcu_barrier(). */
87046 rdp->qlen_lazy -= count_lazy;
87047- ACCESS_ONCE(rdp->qlen) -= count;
87048+ ACCESS_ONCE_RW(rdp->qlen) -= count;
87049 rdp->n_cbs_invoked += count;
87050
87051 /* Reinstate batch limit if we have worked down the excess. */
87052@@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
87053 /*
87054 * Do RCU core processing for the current CPU.
87055 */
87056-static void rcu_process_callbacks(struct softirq_action *unused)
87057+static void rcu_process_callbacks(void)
87058 {
87059 struct rcu_state *rsp;
87060
87061@@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87062 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
87063 if (debug_rcu_head_queue(head)) {
87064 /* Probable double call_rcu(), so leak the callback. */
87065- ACCESS_ONCE(head->func) = rcu_leak_callback;
87066+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
87067 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
87068 return;
87069 }
87070@@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87071 local_irq_restore(flags);
87072 return;
87073 }
87074- ACCESS_ONCE(rdp->qlen)++;
87075+ ACCESS_ONCE_RW(rdp->qlen)++;
87076 if (lazy)
87077 rdp->qlen_lazy++;
87078 else
87079@@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
87080 * counter wrap on a 32-bit system. Quite a few more CPUs would of
87081 * course be required on a 64-bit system.
87082 */
87083- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
87084+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
87085 (ulong)atomic_long_read(&rsp->expedited_done) +
87086 ULONG_MAX / 8)) {
87087 synchronize_sched();
87088- atomic_long_inc(&rsp->expedited_wrap);
87089+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
87090 return;
87091 }
87092
87093@@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
87094 * Take a ticket. Note that atomic_inc_return() implies a
87095 * full memory barrier.
87096 */
87097- snap = atomic_long_inc_return(&rsp->expedited_start);
87098+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
87099 firstsnap = snap;
87100 get_online_cpus();
87101 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
87102@@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
87103 synchronize_sched_expedited_cpu_stop,
87104 NULL) == -EAGAIN) {
87105 put_online_cpus();
87106- atomic_long_inc(&rsp->expedited_tryfail);
87107+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
87108
87109 /* Check to see if someone else did our work for us. */
87110 s = atomic_long_read(&rsp->expedited_done);
87111 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87112 /* ensure test happens before caller kfree */
87113 smp_mb__before_atomic_inc(); /* ^^^ */
87114- atomic_long_inc(&rsp->expedited_workdone1);
87115+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
87116 return;
87117 }
87118
87119@@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
87120 udelay(trycount * num_online_cpus());
87121 } else {
87122 wait_rcu_gp(call_rcu_sched);
87123- atomic_long_inc(&rsp->expedited_normal);
87124+ atomic_long_inc_unchecked(&rsp->expedited_normal);
87125 return;
87126 }
87127
87128@@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
87129 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87130 /* ensure test happens before caller kfree */
87131 smp_mb__before_atomic_inc(); /* ^^^ */
87132- atomic_long_inc(&rsp->expedited_workdone2);
87133+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
87134 return;
87135 }
87136
87137@@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
87138 * period works for us.
87139 */
87140 get_online_cpus();
87141- snap = atomic_long_read(&rsp->expedited_start);
87142+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
87143 smp_mb(); /* ensure read is before try_stop_cpus(). */
87144 }
87145- atomic_long_inc(&rsp->expedited_stoppedcpus);
87146+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
87147
87148 /*
87149 * Everyone up to our most recent fetch is covered by our grace
87150@@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
87151 * than we did already did their update.
87152 */
87153 do {
87154- atomic_long_inc(&rsp->expedited_done_tries);
87155+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
87156 s = atomic_long_read(&rsp->expedited_done);
87157 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
87158 /* ensure test happens before caller kfree */
87159 smp_mb__before_atomic_inc(); /* ^^^ */
87160- atomic_long_inc(&rsp->expedited_done_lost);
87161+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
87162 break;
87163 }
87164 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
87165- atomic_long_inc(&rsp->expedited_done_exit);
87166+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
87167
87168 put_online_cpus();
87169 }
87170@@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87171 * ACCESS_ONCE() to prevent the compiler from speculating
87172 * the increment to precede the early-exit check.
87173 */
87174- ACCESS_ONCE(rsp->n_barrier_done)++;
87175+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87176 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
87177 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
87178 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
87179@@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87180
87181 /* Increment ->n_barrier_done to prevent duplicate work. */
87182 smp_mb(); /* Keep increment after above mechanism. */
87183- ACCESS_ONCE(rsp->n_barrier_done)++;
87184+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87185 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
87186 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
87187 smp_mb(); /* Keep increment before caller's subsequent code. */
87188@@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
87189 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
87190 init_callback_list(rdp);
87191 rdp->qlen_lazy = 0;
87192- ACCESS_ONCE(rdp->qlen) = 0;
87193+ ACCESS_ONCE_RW(rdp->qlen) = 0;
87194 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
87195 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
87196- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
87197+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
87198 rdp->cpu = cpu;
87199 rdp->rsp = rsp;
87200 rcu_boot_init_nocb_percpu_data(rdp);
87201@@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
87202 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
87203 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
87204 rcu_sysidle_init_percpu_data(rdp->dynticks);
87205- atomic_set(&rdp->dynticks->dynticks,
87206- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
87207+ atomic_set_unchecked(&rdp->dynticks->dynticks,
87208+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
87209 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
87210
87211 /* Add CPU to rcu_node bitmasks. */
87212diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
87213index 52be957..365ded3 100644
87214--- a/kernel/rcu/tree.h
87215+++ b/kernel/rcu/tree.h
87216@@ -87,11 +87,11 @@ struct rcu_dynticks {
87217 long long dynticks_nesting; /* Track irq/process nesting level. */
87218 /* Process level is worth LLONG_MAX/2. */
87219 int dynticks_nmi_nesting; /* Track NMI nesting level. */
87220- atomic_t dynticks; /* Even value for idle, else odd. */
87221+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
87222 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
87223 long long dynticks_idle_nesting;
87224 /* irq/process nesting level from idle. */
87225- atomic_t dynticks_idle; /* Even value for idle, else odd. */
87226+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
87227 /* "Idle" excludes userspace execution. */
87228 unsigned long dynticks_idle_jiffies;
87229 /* End of last non-NMI non-idle period. */
87230@@ -429,17 +429,17 @@ struct rcu_state {
87231 /* _rcu_barrier(). */
87232 /* End of fields guarded by barrier_mutex. */
87233
87234- atomic_long_t expedited_start; /* Starting ticket. */
87235- atomic_long_t expedited_done; /* Done ticket. */
87236- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
87237- atomic_long_t expedited_tryfail; /* # acquisition failures. */
87238- atomic_long_t expedited_workdone1; /* # done by others #1. */
87239- atomic_long_t expedited_workdone2; /* # done by others #2. */
87240- atomic_long_t expedited_normal; /* # fallbacks to normal. */
87241- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
87242- atomic_long_t expedited_done_tries; /* # tries to update _done. */
87243- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
87244- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
87245+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
87246+ atomic_long_t expedited_done; /* Done ticket. */
87247+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
87248+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
87249+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
87250+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
87251+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
87252+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
87253+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
87254+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
87255+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
87256
87257 unsigned long jiffies_force_qs; /* Time at which to invoke */
87258 /* force_quiescent_state(). */
87259diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
87260index 08a7652..3598c7e 100644
87261--- a/kernel/rcu/tree_plugin.h
87262+++ b/kernel/rcu/tree_plugin.h
87263@@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
87264 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
87265 {
87266 return !rcu_preempted_readers_exp(rnp) &&
87267- ACCESS_ONCE(rnp->expmask) == 0;
87268+ ACCESS_ONCE_RW(rnp->expmask) == 0;
87269 }
87270
87271 /*
87272@@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
87273
87274 /* Clean up and exit. */
87275 smp_mb(); /* ensure expedited GP seen before counter increment. */
87276- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
87277+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
87278 unlock_mb_ret:
87279 mutex_unlock(&sync_rcu_preempt_exp_mutex);
87280 mb_ret:
87281@@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
87282 free_cpumask_var(cm);
87283 }
87284
87285-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
87286+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
87287 .store = &rcu_cpu_kthread_task,
87288 .thread_should_run = rcu_cpu_kthread_should_run,
87289 .thread_fn = rcu_cpu_kthread,
87290@@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
87291 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
87292 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
87293 cpu, ticks_value, ticks_title,
87294- atomic_read(&rdtp->dynticks) & 0xfff,
87295+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
87296 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
87297 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
87298 fast_no_hz);
87299@@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
87300
87301 /* Enqueue the callback on the nocb list and update counts. */
87302 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
87303- ACCESS_ONCE(*old_rhpp) = rhp;
87304+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
87305 atomic_long_add(rhcount, &rdp->nocb_q_count);
87306 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
87307
87308@@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
87309 * Extract queued callbacks, update counts, and wait
87310 * for a grace period to elapse.
87311 */
87312- ACCESS_ONCE(rdp->nocb_head) = NULL;
87313+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
87314 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
87315 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
87316 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
87317- ACCESS_ONCE(rdp->nocb_p_count) += c;
87318- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
87319+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
87320+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
87321 rcu_nocb_wait_gp(rdp);
87322
87323 /* Each pass through the following loop invokes a callback. */
87324@@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
87325 list = next;
87326 }
87327 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
87328- ACCESS_ONCE(rdp->nocb_p_count) -= c;
87329- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
87330+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
87331+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
87332 rdp->n_nocbs_invoked += c;
87333 }
87334 return 0;
87335@@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
87336 t = kthread_run(rcu_nocb_kthread, rdp,
87337 "rcuo%c/%d", rsp->abbr, cpu);
87338 BUG_ON(IS_ERR(t));
87339- ACCESS_ONCE(rdp->nocb_kthread) = t;
87340+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
87341 }
87342 }
87343
87344@@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
87345
87346 /* Record start of fully idle period. */
87347 j = jiffies;
87348- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
87349+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
87350 smp_mb__before_atomic_inc();
87351- atomic_inc(&rdtp->dynticks_idle);
87352+ atomic_inc_unchecked(&rdtp->dynticks_idle);
87353 smp_mb__after_atomic_inc();
87354- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
87355+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
87356 }
87357
87358 /*
87359@@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
87360
87361 /* Record end of idle period. */
87362 smp_mb__before_atomic_inc();
87363- atomic_inc(&rdtp->dynticks_idle);
87364+ atomic_inc_unchecked(&rdtp->dynticks_idle);
87365 smp_mb__after_atomic_inc();
87366- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
87367+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
87368
87369 /*
87370 * If we are the timekeeping CPU, we are permitted to be non-idle
87371@@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
87372 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
87373
87374 /* Pick up current idle and NMI-nesting counter and check. */
87375- cur = atomic_read(&rdtp->dynticks_idle);
87376+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
87377 if (cur & 0x1) {
87378 *isidle = false; /* We are not idle! */
87379 return;
87380@@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
87381 case RCU_SYSIDLE_NOT:
87382
87383 /* First time all are idle, so note a short idle period. */
87384- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87385+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87386 break;
87387
87388 case RCU_SYSIDLE_SHORT:
87389@@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
87390 static void rcu_sysidle_cancel(void)
87391 {
87392 smp_mb();
87393- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
87394+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
87395 }
87396
87397 /*
87398@@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
87399 smp_mb(); /* grace period precedes setting inuse. */
87400
87401 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
87402- ACCESS_ONCE(rshp->inuse) = 0;
87403+ ACCESS_ONCE_RW(rshp->inuse) = 0;
87404 }
87405
87406 /*
87407diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
87408index 3596797..f78391c 100644
87409--- a/kernel/rcu/tree_trace.c
87410+++ b/kernel/rcu/tree_trace.c
87411@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
87412 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
87413 rdp->passed_quiesce, rdp->qs_pending);
87414 seq_printf(m, " dt=%d/%llx/%d df=%lu",
87415- atomic_read(&rdp->dynticks->dynticks),
87416+ atomic_read_unchecked(&rdp->dynticks->dynticks),
87417 rdp->dynticks->dynticks_nesting,
87418 rdp->dynticks->dynticks_nmi_nesting,
87419 rdp->dynticks_fqs);
87420@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
87421 struct rcu_state *rsp = (struct rcu_state *)m->private;
87422
87423 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",
87424- atomic_long_read(&rsp->expedited_start),
87425+ atomic_long_read_unchecked(&rsp->expedited_start),
87426 atomic_long_read(&rsp->expedited_done),
87427- atomic_long_read(&rsp->expedited_wrap),
87428- atomic_long_read(&rsp->expedited_tryfail),
87429- atomic_long_read(&rsp->expedited_workdone1),
87430- atomic_long_read(&rsp->expedited_workdone2),
87431- atomic_long_read(&rsp->expedited_normal),
87432- atomic_long_read(&rsp->expedited_stoppedcpus),
87433- atomic_long_read(&rsp->expedited_done_tries),
87434- atomic_long_read(&rsp->expedited_done_lost),
87435- atomic_long_read(&rsp->expedited_done_exit));
87436+ atomic_long_read_unchecked(&rsp->expedited_wrap),
87437+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
87438+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
87439+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
87440+ atomic_long_read_unchecked(&rsp->expedited_normal),
87441+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
87442+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
87443+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
87444+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
87445 return 0;
87446 }
87447
87448diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
87449index 6cb3dff..dc5710f 100644
87450--- a/kernel/rcu/update.c
87451+++ b/kernel/rcu/update.c
87452@@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
87453 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
87454 */
87455 if (till_stall_check < 3) {
87456- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
87457+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
87458 till_stall_check = 3;
87459 } else if (till_stall_check > 300) {
87460- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
87461+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
87462 till_stall_check = 300;
87463 }
87464 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
87465diff --git a/kernel/resource.c b/kernel/resource.c
87466index 3f285dc..5755f62 100644
87467--- a/kernel/resource.c
87468+++ b/kernel/resource.c
87469@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
87470
87471 static int __init ioresources_init(void)
87472 {
87473+#ifdef CONFIG_GRKERNSEC_PROC_ADD
87474+#ifdef CONFIG_GRKERNSEC_PROC_USER
87475+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
87476+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
87477+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87478+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
87479+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
87480+#endif
87481+#else
87482 proc_create("ioports", 0, NULL, &proc_ioports_operations);
87483 proc_create("iomem", 0, NULL, &proc_iomem_operations);
87484+#endif
87485 return 0;
87486 }
87487 __initcall(ioresources_init);
87488diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
87489index 4a07353..66b5291 100644
87490--- a/kernel/sched/auto_group.c
87491+++ b/kernel/sched/auto_group.c
87492@@ -11,7 +11,7 @@
87493
87494 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
87495 static struct autogroup autogroup_default;
87496-static atomic_t autogroup_seq_nr;
87497+static atomic_unchecked_t autogroup_seq_nr;
87498
87499 void __init autogroup_init(struct task_struct *init_task)
87500 {
87501@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
87502
87503 kref_init(&ag->kref);
87504 init_rwsem(&ag->lock);
87505- ag->id = atomic_inc_return(&autogroup_seq_nr);
87506+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
87507 ag->tg = tg;
87508 #ifdef CONFIG_RT_GROUP_SCHED
87509 /*
87510diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
87511index a63f4dc..349bbb0 100644
87512--- a/kernel/sched/completion.c
87513+++ b/kernel/sched/completion.c
87514@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
87515 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87516 * or number of jiffies left till timeout) if completed.
87517 */
87518-long __sched
87519+long __sched __intentional_overflow(-1)
87520 wait_for_completion_interruptible_timeout(struct completion *x,
87521 unsigned long timeout)
87522 {
87523@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
87524 *
87525 * Return: -ERESTARTSYS if interrupted, 0 if completed.
87526 */
87527-int __sched wait_for_completion_killable(struct completion *x)
87528+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
87529 {
87530 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
87531 if (t == -ERESTARTSYS)
87532@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
87533 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87534 * or number of jiffies left till timeout) if completed.
87535 */
87536-long __sched
87537+long __sched __intentional_overflow(-1)
87538 wait_for_completion_killable_timeout(struct completion *x,
87539 unsigned long timeout)
87540 {
87541diff --git a/kernel/sched/core.c b/kernel/sched/core.c
87542index a88f4a4..9d57ac9 100644
87543--- a/kernel/sched/core.c
87544+++ b/kernel/sched/core.c
87545@@ -2871,6 +2871,8 @@ int can_nice(const struct task_struct *p, const int nice)
87546 /* convert nice value [19,-20] to rlimit style value [1,40] */
87547 int nice_rlim = 20 - nice;
87548
87549+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
87550+
87551 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
87552 capable(CAP_SYS_NICE));
87553 }
87554@@ -2904,7 +2906,8 @@ SYSCALL_DEFINE1(nice, int, increment)
87555 if (nice > 19)
87556 nice = 19;
87557
87558- if (increment < 0 && !can_nice(current, nice))
87559+ if (increment < 0 && (!can_nice(current, nice) ||
87560+ gr_handle_chroot_nice()))
87561 return -EPERM;
87562
87563 retval = security_task_setnice(current, nice);
87564@@ -3066,6 +3069,7 @@ recheck:
87565 unsigned long rlim_rtprio =
87566 task_rlimit(p, RLIMIT_RTPRIO);
87567
87568+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
87569 /* can't set/change the rt policy */
87570 if (policy != p->policy && !rlim_rtprio)
87571 return -EPERM;
87572@@ -4232,7 +4236,7 @@ static void migrate_tasks(unsigned int dead_cpu)
87573
87574 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
87575
87576-static struct ctl_table sd_ctl_dir[] = {
87577+static ctl_table_no_const sd_ctl_dir[] __read_only = {
87578 {
87579 .procname = "sched_domain",
87580 .mode = 0555,
87581@@ -4249,17 +4253,17 @@ static struct ctl_table sd_ctl_root[] = {
87582 {}
87583 };
87584
87585-static struct ctl_table *sd_alloc_ctl_entry(int n)
87586+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
87587 {
87588- struct ctl_table *entry =
87589+ ctl_table_no_const *entry =
87590 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
87591
87592 return entry;
87593 }
87594
87595-static void sd_free_ctl_entry(struct ctl_table **tablep)
87596+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
87597 {
87598- struct ctl_table *entry;
87599+ ctl_table_no_const *entry;
87600
87601 /*
87602 * In the intermediate directories, both the child directory and
87603@@ -4267,22 +4271,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
87604 * will always be set. In the lowest directory the names are
87605 * static strings and all have proc handlers.
87606 */
87607- for (entry = *tablep; entry->mode; entry++) {
87608- if (entry->child)
87609- sd_free_ctl_entry(&entry->child);
87610+ for (entry = tablep; entry->mode; entry++) {
87611+ if (entry->child) {
87612+ sd_free_ctl_entry(entry->child);
87613+ pax_open_kernel();
87614+ entry->child = NULL;
87615+ pax_close_kernel();
87616+ }
87617 if (entry->proc_handler == NULL)
87618 kfree(entry->procname);
87619 }
87620
87621- kfree(*tablep);
87622- *tablep = NULL;
87623+ kfree(tablep);
87624 }
87625
87626 static int min_load_idx = 0;
87627 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
87628
87629 static void
87630-set_table_entry(struct ctl_table *entry,
87631+set_table_entry(ctl_table_no_const *entry,
87632 const char *procname, void *data, int maxlen,
87633 umode_t mode, proc_handler *proc_handler,
87634 bool load_idx)
87635@@ -4302,7 +4309,7 @@ set_table_entry(struct ctl_table *entry,
87636 static struct ctl_table *
87637 sd_alloc_ctl_domain_table(struct sched_domain *sd)
87638 {
87639- struct ctl_table *table = sd_alloc_ctl_entry(13);
87640+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
87641
87642 if (table == NULL)
87643 return NULL;
87644@@ -4337,9 +4344,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
87645 return table;
87646 }
87647
87648-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
87649+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
87650 {
87651- struct ctl_table *entry, *table;
87652+ ctl_table_no_const *entry, *table;
87653 struct sched_domain *sd;
87654 int domain_num = 0, i;
87655 char buf[32];
87656@@ -4366,11 +4373,13 @@ static struct ctl_table_header *sd_sysctl_header;
87657 static void register_sched_domain_sysctl(void)
87658 {
87659 int i, cpu_num = num_possible_cpus();
87660- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
87661+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
87662 char buf[32];
87663
87664 WARN_ON(sd_ctl_dir[0].child);
87665+ pax_open_kernel();
87666 sd_ctl_dir[0].child = entry;
87667+ pax_close_kernel();
87668
87669 if (entry == NULL)
87670 return;
87671@@ -4393,8 +4402,12 @@ static void unregister_sched_domain_sysctl(void)
87672 if (sd_sysctl_header)
87673 unregister_sysctl_table(sd_sysctl_header);
87674 sd_sysctl_header = NULL;
87675- if (sd_ctl_dir[0].child)
87676- sd_free_ctl_entry(&sd_ctl_dir[0].child);
87677+ if (sd_ctl_dir[0].child) {
87678+ sd_free_ctl_entry(sd_ctl_dir[0].child);
87679+ pax_open_kernel();
87680+ sd_ctl_dir[0].child = NULL;
87681+ pax_close_kernel();
87682+ }
87683 }
87684 #else
87685 static void register_sched_domain_sysctl(void)
87686diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
87687index e64b079..a46bd34 100644
87688--- a/kernel/sched/fair.c
87689+++ b/kernel/sched/fair.c
87690@@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
87691
87692 static void reset_ptenuma_scan(struct task_struct *p)
87693 {
87694- ACCESS_ONCE(p->mm->numa_scan_seq)++;
87695+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
87696 p->mm->numa_scan_offset = 0;
87697 }
87698
87699@@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
87700 * run_rebalance_domains is triggered when needed from the scheduler tick.
87701 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
87702 */
87703-static void run_rebalance_domains(struct softirq_action *h)
87704+static __latent_entropy void run_rebalance_domains(void)
87705 {
87706 int this_cpu = smp_processor_id();
87707 struct rq *this_rq = cpu_rq(this_cpu);
87708diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
87709index 88c85b2..a1dec86 100644
87710--- a/kernel/sched/sched.h
87711+++ b/kernel/sched/sched.h
87712@@ -1035,7 +1035,7 @@ struct sched_class {
87713 #ifdef CONFIG_FAIR_GROUP_SCHED
87714 void (*task_move_group) (struct task_struct *p, int on_rq);
87715 #endif
87716-};
87717+} __do_const;
87718
87719 #define sched_class_highest (&stop_sched_class)
87720 #define for_each_class(class) \
87721diff --git a/kernel/signal.c b/kernel/signal.c
87722index 940b30e..7fd6041 100644
87723--- a/kernel/signal.c
87724+++ b/kernel/signal.c
87725@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
87726
87727 int print_fatal_signals __read_mostly;
87728
87729-static void __user *sig_handler(struct task_struct *t, int sig)
87730+static __sighandler_t sig_handler(struct task_struct *t, int sig)
87731 {
87732 return t->sighand->action[sig - 1].sa.sa_handler;
87733 }
87734
87735-static int sig_handler_ignored(void __user *handler, int sig)
87736+static int sig_handler_ignored(__sighandler_t handler, int sig)
87737 {
87738 /* Is it explicitly or implicitly ignored? */
87739 return handler == SIG_IGN ||
87740@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
87741
87742 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
87743 {
87744- void __user *handler;
87745+ __sighandler_t handler;
87746
87747 handler = sig_handler(t, sig);
87748
87749@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
87750 atomic_inc(&user->sigpending);
87751 rcu_read_unlock();
87752
87753+ if (!override_rlimit)
87754+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
87755+
87756 if (override_rlimit ||
87757 atomic_read(&user->sigpending) <=
87758 task_rlimit(t, RLIMIT_SIGPENDING)) {
87759@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
87760
87761 int unhandled_signal(struct task_struct *tsk, int sig)
87762 {
87763- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
87764+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
87765 if (is_global_init(tsk))
87766 return 1;
87767 if (handler != SIG_IGN && handler != SIG_DFL)
87768@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
87769 }
87770 }
87771
87772+ /* allow glibc communication via tgkill to other threads in our
87773+ thread group */
87774+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
87775+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
87776+ && gr_handle_signal(t, sig))
87777+ return -EPERM;
87778+
87779 return security_task_kill(t, info, sig, 0);
87780 }
87781
87782@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
87783 return send_signal(sig, info, p, 1);
87784 }
87785
87786-static int
87787+int
87788 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87789 {
87790 return send_signal(sig, info, t, 0);
87791@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87792 unsigned long int flags;
87793 int ret, blocked, ignored;
87794 struct k_sigaction *action;
87795+ int is_unhandled = 0;
87796
87797 spin_lock_irqsave(&t->sighand->siglock, flags);
87798 action = &t->sighand->action[sig-1];
87799@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87800 }
87801 if (action->sa.sa_handler == SIG_DFL)
87802 t->signal->flags &= ~SIGNAL_UNKILLABLE;
87803+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
87804+ is_unhandled = 1;
87805 ret = specific_send_sig_info(sig, info, t);
87806 spin_unlock_irqrestore(&t->sighand->siglock, flags);
87807
87808+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
87809+ normal operation */
87810+ if (is_unhandled) {
87811+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
87812+ gr_handle_crash(t, sig);
87813+ }
87814+
87815 return ret;
87816 }
87817
87818@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
87819 ret = check_kill_permission(sig, info, p);
87820 rcu_read_unlock();
87821
87822- if (!ret && sig)
87823+ if (!ret && sig) {
87824 ret = do_send_sig_info(sig, info, p, true);
87825+ if (!ret)
87826+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
87827+ }
87828
87829 return ret;
87830 }
87831@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
87832 int error = -ESRCH;
87833
87834 rcu_read_lock();
87835- p = find_task_by_vpid(pid);
87836+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
87837+ /* allow glibc communication via tgkill to other threads in our
87838+ thread group */
87839+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
87840+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
87841+ p = find_task_by_vpid_unrestricted(pid);
87842+ else
87843+#endif
87844+ p = find_task_by_vpid(pid);
87845 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
87846 error = check_kill_permission(sig, info, p);
87847 /*
87848@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
87849 }
87850 seg = get_fs();
87851 set_fs(KERNEL_DS);
87852- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
87853- (stack_t __force __user *) &uoss,
87854+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
87855+ (stack_t __force_user *) &uoss,
87856 compat_user_stack_pointer());
87857 set_fs(seg);
87858 if (ret >= 0 && uoss_ptr) {
87859diff --git a/kernel/smpboot.c b/kernel/smpboot.c
87860index eb89e18..a4e6792 100644
87861--- a/kernel/smpboot.c
87862+++ b/kernel/smpboot.c
87863@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
87864 }
87865 smpboot_unpark_thread(plug_thread, cpu);
87866 }
87867- list_add(&plug_thread->list, &hotplug_threads);
87868+ pax_list_add(&plug_thread->list, &hotplug_threads);
87869 out:
87870 mutex_unlock(&smpboot_threads_lock);
87871 return ret;
87872@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
87873 {
87874 get_online_cpus();
87875 mutex_lock(&smpboot_threads_lock);
87876- list_del(&plug_thread->list);
87877+ pax_list_del(&plug_thread->list);
87878 smpboot_destroy_threads(plug_thread);
87879 mutex_unlock(&smpboot_threads_lock);
87880 put_online_cpus();
87881diff --git a/kernel/softirq.c b/kernel/softirq.c
87882index 11025cc..bc0e4dc 100644
87883--- a/kernel/softirq.c
87884+++ b/kernel/softirq.c
87885@@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
87886 EXPORT_SYMBOL(irq_stat);
87887 #endif
87888
87889-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
87890+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
87891
87892 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
87893
87894-char *softirq_to_name[NR_SOFTIRQS] = {
87895+const char * const softirq_to_name[NR_SOFTIRQS] = {
87896 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
87897 "TASKLET", "SCHED", "HRTIMER", "RCU"
87898 };
87899@@ -250,7 +250,7 @@ restart:
87900 kstat_incr_softirqs_this_cpu(vec_nr);
87901
87902 trace_softirq_entry(vec_nr);
87903- h->action(h);
87904+ h->action();
87905 trace_softirq_exit(vec_nr);
87906 if (unlikely(prev_count != preempt_count())) {
87907 printk(KERN_ERR "huh, entered softirq %u %s %p"
87908@@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
87909 or_softirq_pending(1UL << nr);
87910 }
87911
87912-void open_softirq(int nr, void (*action)(struct softirq_action *))
87913+void __init open_softirq(int nr, void (*action)(void))
87914 {
87915 softirq_vec[nr].action = action;
87916 }
87917@@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
87918
87919 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
87920
87921-static void tasklet_action(struct softirq_action *a)
87922+static __latent_entropy void tasklet_action(void)
87923 {
87924 struct tasklet_struct *list;
87925
87926@@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
87927 }
87928 }
87929
87930-static void tasklet_hi_action(struct softirq_action *a)
87931+static __latent_entropy void tasklet_hi_action(void)
87932 {
87933 struct tasklet_struct *list;
87934
87935@@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
87936 .notifier_call = cpu_callback
87937 };
87938
87939-static struct smp_hotplug_thread softirq_threads = {
87940+static struct smp_hotplug_thread softirq_threads __read_only = {
87941 .store = &ksoftirqd,
87942 .thread_should_run = ksoftirqd_should_run,
87943 .thread_fn = run_ksoftirqd,
87944diff --git a/kernel/sys.c b/kernel/sys.c
87945index c723113..46bf922 100644
87946--- a/kernel/sys.c
87947+++ b/kernel/sys.c
87948@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
87949 error = -EACCES;
87950 goto out;
87951 }
87952+
87953+ if (gr_handle_chroot_setpriority(p, niceval)) {
87954+ error = -EACCES;
87955+ goto out;
87956+ }
87957+
87958 no_nice = security_task_setnice(p, niceval);
87959 if (no_nice) {
87960 error = no_nice;
87961@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
87962 goto error;
87963 }
87964
87965+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
87966+ goto error;
87967+
87968 if (rgid != (gid_t) -1 ||
87969 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
87970 new->sgid = new->egid;
87971@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
87972 old = current_cred();
87973
87974 retval = -EPERM;
87975+
87976+ if (gr_check_group_change(kgid, kgid, kgid))
87977+ goto error;
87978+
87979 if (ns_capable(old->user_ns, CAP_SETGID))
87980 new->gid = new->egid = new->sgid = new->fsgid = kgid;
87981 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
87982@@ -403,7 +416,7 @@ error:
87983 /*
87984 * change the user struct in a credentials set to match the new UID
87985 */
87986-static int set_user(struct cred *new)
87987+int set_user(struct cred *new)
87988 {
87989 struct user_struct *new_user;
87990
87991@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
87992 goto error;
87993 }
87994
87995+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
87996+ goto error;
87997+
87998 if (!uid_eq(new->uid, old->uid)) {
87999 retval = set_user(new);
88000 if (retval < 0)
88001@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
88002 old = current_cred();
88003
88004 retval = -EPERM;
88005+
88006+ if (gr_check_crash_uid(kuid))
88007+ goto error;
88008+ if (gr_check_user_change(kuid, kuid, kuid))
88009+ goto error;
88010+
88011 if (ns_capable(old->user_ns, CAP_SETUID)) {
88012 new->suid = new->uid = kuid;
88013 if (!uid_eq(kuid, old->uid)) {
88014@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
88015 goto error;
88016 }
88017
88018+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
88019+ goto error;
88020+
88021 if (ruid != (uid_t) -1) {
88022 new->uid = kruid;
88023 if (!uid_eq(kruid, old->uid)) {
88024@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
88025 goto error;
88026 }
88027
88028+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
88029+ goto error;
88030+
88031 if (rgid != (gid_t) -1)
88032 new->gid = krgid;
88033 if (egid != (gid_t) -1)
88034@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
88035 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
88036 ns_capable(old->user_ns, CAP_SETUID)) {
88037 if (!uid_eq(kuid, old->fsuid)) {
88038+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
88039+ goto error;
88040+
88041 new->fsuid = kuid;
88042 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
88043 goto change_okay;
88044 }
88045 }
88046
88047+error:
88048 abort_creds(new);
88049 return old_fsuid;
88050
88051@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
88052 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
88053 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
88054 ns_capable(old->user_ns, CAP_SETGID)) {
88055+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
88056+ goto error;
88057+
88058 if (!gid_eq(kgid, old->fsgid)) {
88059 new->fsgid = kgid;
88060 goto change_okay;
88061 }
88062 }
88063
88064+error:
88065 abort_creds(new);
88066 return old_fsgid;
88067
88068@@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
88069 return -EFAULT;
88070
88071 down_read(&uts_sem);
88072- error = __copy_to_user(&name->sysname, &utsname()->sysname,
88073+ error = __copy_to_user(name->sysname, &utsname()->sysname,
88074 __OLD_UTS_LEN);
88075 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
88076- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
88077+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
88078 __OLD_UTS_LEN);
88079 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
88080- error |= __copy_to_user(&name->release, &utsname()->release,
88081+ error |= __copy_to_user(name->release, &utsname()->release,
88082 __OLD_UTS_LEN);
88083 error |= __put_user(0, name->release + __OLD_UTS_LEN);
88084- error |= __copy_to_user(&name->version, &utsname()->version,
88085+ error |= __copy_to_user(name->version, &utsname()->version,
88086 __OLD_UTS_LEN);
88087 error |= __put_user(0, name->version + __OLD_UTS_LEN);
88088- error |= __copy_to_user(&name->machine, &utsname()->machine,
88089+ error |= __copy_to_user(name->machine, &utsname()->machine,
88090 __OLD_UTS_LEN);
88091 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
88092 up_read(&uts_sem);
88093@@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
88094 */
88095 new_rlim->rlim_cur = 1;
88096 }
88097+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
88098+ is changed to a lower value. Since tasks can be created by the same
88099+ user in between this limit change and an execve by this task, force
88100+ a recheck only for this task by setting PF_NPROC_EXCEEDED
88101+ */
88102+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
88103+ tsk->flags |= PF_NPROC_EXCEEDED;
88104 }
88105 if (!retval) {
88106 if (old_rlim)
88107diff --git a/kernel/sysctl.c b/kernel/sysctl.c
88108index 34a6047..5665aa7 100644
88109--- a/kernel/sysctl.c
88110+++ b/kernel/sysctl.c
88111@@ -93,7 +93,6 @@
88112
88113
88114 #if defined(CONFIG_SYSCTL)
88115-
88116 /* External variables not in a header file. */
88117 extern int sysctl_overcommit_memory;
88118 extern int sysctl_overcommit_ratio;
88119@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
88120
88121 /* Constants used for minimum and maximum */
88122 #ifdef CONFIG_LOCKUP_DETECTOR
88123-static int sixty = 60;
88124+static int sixty __read_only = 60;
88125 #endif
88126
88127-static int zero;
88128-static int __maybe_unused one = 1;
88129-static int __maybe_unused two = 2;
88130-static int __maybe_unused three = 3;
88131-static unsigned long one_ul = 1;
88132-static int one_hundred = 100;
88133+static int neg_one __read_only = -1;
88134+static int zero __read_only = 0;
88135+static int __maybe_unused one __read_only = 1;
88136+static int __maybe_unused two __read_only = 2;
88137+static int __maybe_unused three __read_only = 3;
88138+static unsigned long one_ul __read_only = 1;
88139+static int one_hundred __read_only = 100;
88140 #ifdef CONFIG_PRINTK
88141-static int ten_thousand = 10000;
88142+static int ten_thousand __read_only = 10000;
88143 #endif
88144
88145 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
88146@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
88147 void __user *buffer, size_t *lenp, loff_t *ppos);
88148 #endif
88149
88150-#ifdef CONFIG_PRINTK
88151 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88152 void __user *buffer, size_t *lenp, loff_t *ppos);
88153-#endif
88154
88155 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
88156 void __user *buffer, size_t *lenp, loff_t *ppos);
88157@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
88158
88159 #endif
88160
88161+extern struct ctl_table grsecurity_table[];
88162+
88163 static struct ctl_table kern_table[];
88164 static struct ctl_table vm_table[];
88165 static struct ctl_table fs_table[];
88166@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
88167 int sysctl_legacy_va_layout;
88168 #endif
88169
88170+#ifdef CONFIG_PAX_SOFTMODE
88171+static ctl_table pax_table[] = {
88172+ {
88173+ .procname = "softmode",
88174+ .data = &pax_softmode,
88175+ .maxlen = sizeof(unsigned int),
88176+ .mode = 0600,
88177+ .proc_handler = &proc_dointvec,
88178+ },
88179+
88180+ { }
88181+};
88182+#endif
88183+
88184 /* The default sysctl tables: */
88185
88186 static struct ctl_table sysctl_base_table[] = {
88187@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
88188 #endif
88189
88190 static struct ctl_table kern_table[] = {
88191+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
88192+ {
88193+ .procname = "grsecurity",
88194+ .mode = 0500,
88195+ .child = grsecurity_table,
88196+ },
88197+#endif
88198+
88199+#ifdef CONFIG_PAX_SOFTMODE
88200+ {
88201+ .procname = "pax",
88202+ .mode = 0500,
88203+ .child = pax_table,
88204+ },
88205+#endif
88206+
88207 {
88208 .procname = "sched_child_runs_first",
88209 .data = &sysctl_sched_child_runs_first,
88210@@ -620,7 +650,7 @@ static struct ctl_table kern_table[] = {
88211 .data = &modprobe_path,
88212 .maxlen = KMOD_PATH_LEN,
88213 .mode = 0644,
88214- .proc_handler = proc_dostring,
88215+ .proc_handler = proc_dostring_modpriv,
88216 },
88217 {
88218 .procname = "modules_disabled",
88219@@ -787,16 +817,20 @@ static struct ctl_table kern_table[] = {
88220 .extra1 = &zero,
88221 .extra2 = &one,
88222 },
88223+#endif
88224 {
88225 .procname = "kptr_restrict",
88226 .data = &kptr_restrict,
88227 .maxlen = sizeof(int),
88228 .mode = 0644,
88229 .proc_handler = proc_dointvec_minmax_sysadmin,
88230+#ifdef CONFIG_GRKERNSEC_HIDESYM
88231+ .extra1 = &two,
88232+#else
88233 .extra1 = &zero,
88234+#endif
88235 .extra2 = &two,
88236 },
88237-#endif
88238 {
88239 .procname = "ngroups_max",
88240 .data = &ngroups_max,
88241@@ -1039,10 +1073,17 @@ static struct ctl_table kern_table[] = {
88242 */
88243 {
88244 .procname = "perf_event_paranoid",
88245- .data = &sysctl_perf_event_paranoid,
88246- .maxlen = sizeof(sysctl_perf_event_paranoid),
88247+ .data = &sysctl_perf_event_legitimately_concerned,
88248+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
88249 .mode = 0644,
88250- .proc_handler = proc_dointvec,
88251+ /* go ahead, be a hero */
88252+ .proc_handler = proc_dointvec_minmax_sysadmin,
88253+ .extra1 = &neg_one,
88254+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88255+ .extra2 = &three,
88256+#else
88257+ .extra2 = &two,
88258+#endif
88259 },
88260 {
88261 .procname = "perf_event_mlock_kb",
88262@@ -1306,6 +1347,13 @@ static struct ctl_table vm_table[] = {
88263 .proc_handler = proc_dointvec_minmax,
88264 .extra1 = &zero,
88265 },
88266+ {
88267+ .procname = "heap_stack_gap",
88268+ .data = &sysctl_heap_stack_gap,
88269+ .maxlen = sizeof(sysctl_heap_stack_gap),
88270+ .mode = 0644,
88271+ .proc_handler = proc_doulongvec_minmax,
88272+ },
88273 #else
88274 {
88275 .procname = "nr_trim_pages",
88276@@ -1770,6 +1818,16 @@ int proc_dostring(struct ctl_table *table, int write,
88277 buffer, lenp, ppos);
88278 }
88279
88280+int proc_dostring_modpriv(struct ctl_table *table, int write,
88281+ void __user *buffer, size_t *lenp, loff_t *ppos)
88282+{
88283+ if (write && !capable(CAP_SYS_MODULE))
88284+ return -EPERM;
88285+
88286+ return _proc_do_string(table->data, table->maxlen, write,
88287+ buffer, lenp, ppos);
88288+}
88289+
88290 static size_t proc_skip_spaces(char **buf)
88291 {
88292 size_t ret;
88293@@ -1875,6 +1933,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
88294 len = strlen(tmp);
88295 if (len > *size)
88296 len = *size;
88297+ if (len > sizeof(tmp))
88298+ len = sizeof(tmp);
88299 if (copy_to_user(*buf, tmp, len))
88300 return -EFAULT;
88301 *size -= len;
88302@@ -2039,7 +2099,7 @@ int proc_dointvec(struct ctl_table *table, int write,
88303 static int proc_taint(struct ctl_table *table, int write,
88304 void __user *buffer, size_t *lenp, loff_t *ppos)
88305 {
88306- struct ctl_table t;
88307+ ctl_table_no_const t;
88308 unsigned long tmptaint = get_taint();
88309 int err;
88310
88311@@ -2067,7 +2127,6 @@ static int proc_taint(struct ctl_table *table, int write,
88312 return err;
88313 }
88314
88315-#ifdef CONFIG_PRINTK
88316 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88317 void __user *buffer, size_t *lenp, loff_t *ppos)
88318 {
88319@@ -2076,7 +2135,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88320
88321 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
88322 }
88323-#endif
88324
88325 struct do_proc_dointvec_minmax_conv_param {
88326 int *min;
88327@@ -2623,6 +2681,12 @@ int proc_dostring(struct ctl_table *table, int write,
88328 return -ENOSYS;
88329 }
88330
88331+int proc_dostring_modpriv(struct ctl_table *table, int write,
88332+ void __user *buffer, size_t *lenp, loff_t *ppos)
88333+{
88334+ return -ENOSYS;
88335+}
88336+
88337 int proc_dointvec(struct ctl_table *table, int write,
88338 void __user *buffer, size_t *lenp, loff_t *ppos)
88339 {
88340@@ -2679,5 +2743,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
88341 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
88342 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
88343 EXPORT_SYMBOL(proc_dostring);
88344+EXPORT_SYMBOL(proc_dostring_modpriv);
88345 EXPORT_SYMBOL(proc_doulongvec_minmax);
88346 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
88347diff --git a/kernel/taskstats.c b/kernel/taskstats.c
88348index 13d2f7c..c93d0b0 100644
88349--- a/kernel/taskstats.c
88350+++ b/kernel/taskstats.c
88351@@ -28,9 +28,12 @@
88352 #include <linux/fs.h>
88353 #include <linux/file.h>
88354 #include <linux/pid_namespace.h>
88355+#include <linux/grsecurity.h>
88356 #include <net/genetlink.h>
88357 #include <linux/atomic.h>
88358
88359+extern int gr_is_taskstats_denied(int pid);
88360+
88361 /*
88362 * Maximum length of a cpumask that can be specified in
88363 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
88364@@ -576,6 +579,9 @@ err:
88365
88366 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
88367 {
88368+ if (gr_is_taskstats_denied(current->pid))
88369+ return -EACCES;
88370+
88371 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
88372 return cmd_attr_register_cpumask(info);
88373 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
88374diff --git a/kernel/time.c b/kernel/time.c
88375index 7c7964c..2a0d412 100644
88376--- a/kernel/time.c
88377+++ b/kernel/time.c
88378@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
88379 return error;
88380
88381 if (tz) {
88382+ /* we log in do_settimeofday called below, so don't log twice
88383+ */
88384+ if (!tv)
88385+ gr_log_timechange();
88386+
88387 sys_tz = *tz;
88388 update_vsyscall_tz();
88389 if (firsttime) {
88390diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
88391index 88c9c65..7497ebc 100644
88392--- a/kernel/time/alarmtimer.c
88393+++ b/kernel/time/alarmtimer.c
88394@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
88395 struct platform_device *pdev;
88396 int error = 0;
88397 int i;
88398- struct k_clock alarm_clock = {
88399+ static struct k_clock alarm_clock = {
88400 .clock_getres = alarm_clock_getres,
88401 .clock_get = alarm_clock_get,
88402 .timer_create = alarm_timer_create,
88403diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
88404index 87b4f00..b7f77a7 100644
88405--- a/kernel/time/timekeeping.c
88406+++ b/kernel/time/timekeeping.c
88407@@ -15,6 +15,7 @@
88408 #include <linux/init.h>
88409 #include <linux/mm.h>
88410 #include <linux/sched.h>
88411+#include <linux/grsecurity.h>
88412 #include <linux/syscore_ops.h>
88413 #include <linux/clocksource.h>
88414 #include <linux/jiffies.h>
88415@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
88416 if (!timespec_valid_strict(tv))
88417 return -EINVAL;
88418
88419+ gr_log_timechange();
88420+
88421 raw_spin_lock_irqsave(&timekeeper_lock, flags);
88422 write_seqcount_begin(&timekeeper_seq);
88423
88424diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
88425index 61ed862..3b52c65 100644
88426--- a/kernel/time/timer_list.c
88427+++ b/kernel/time/timer_list.c
88428@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
88429
88430 static void print_name_offset(struct seq_file *m, void *sym)
88431 {
88432+#ifdef CONFIG_GRKERNSEC_HIDESYM
88433+ SEQ_printf(m, "<%p>", NULL);
88434+#else
88435 char symname[KSYM_NAME_LEN];
88436
88437 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
88438 SEQ_printf(m, "<%pK>", sym);
88439 else
88440 SEQ_printf(m, "%s", symname);
88441+#endif
88442 }
88443
88444 static void
88445@@ -119,7 +123,11 @@ next_one:
88446 static void
88447 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
88448 {
88449+#ifdef CONFIG_GRKERNSEC_HIDESYM
88450+ SEQ_printf(m, " .base: %p\n", NULL);
88451+#else
88452 SEQ_printf(m, " .base: %pK\n", base);
88453+#endif
88454 SEQ_printf(m, " .index: %d\n",
88455 base->index);
88456 SEQ_printf(m, " .resolution: %Lu nsecs\n",
88457@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
88458 {
88459 struct proc_dir_entry *pe;
88460
88461+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88462+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
88463+#else
88464 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
88465+#endif
88466 if (!pe)
88467 return -ENOMEM;
88468 return 0;
88469diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
88470index 1fb08f2..ca4bb1e 100644
88471--- a/kernel/time/timer_stats.c
88472+++ b/kernel/time/timer_stats.c
88473@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
88474 static unsigned long nr_entries;
88475 static struct entry entries[MAX_ENTRIES];
88476
88477-static atomic_t overflow_count;
88478+static atomic_unchecked_t overflow_count;
88479
88480 /*
88481 * The entries are in a hash-table, for fast lookup:
88482@@ -140,7 +140,7 @@ static void reset_entries(void)
88483 nr_entries = 0;
88484 memset(entries, 0, sizeof(entries));
88485 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
88486- atomic_set(&overflow_count, 0);
88487+ atomic_set_unchecked(&overflow_count, 0);
88488 }
88489
88490 static struct entry *alloc_entry(void)
88491@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88492 if (likely(entry))
88493 entry->count++;
88494 else
88495- atomic_inc(&overflow_count);
88496+ atomic_inc_unchecked(&overflow_count);
88497
88498 out_unlock:
88499 raw_spin_unlock_irqrestore(lock, flags);
88500@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88501
88502 static void print_name_offset(struct seq_file *m, unsigned long addr)
88503 {
88504+#ifdef CONFIG_GRKERNSEC_HIDESYM
88505+ seq_printf(m, "<%p>", NULL);
88506+#else
88507 char symname[KSYM_NAME_LEN];
88508
88509 if (lookup_symbol_name(addr, symname) < 0)
88510- seq_printf(m, "<%p>", (void *)addr);
88511+ seq_printf(m, "<%pK>", (void *)addr);
88512 else
88513 seq_printf(m, "%s", symname);
88514+#endif
88515 }
88516
88517 static int tstats_show(struct seq_file *m, void *v)
88518@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
88519
88520 seq_puts(m, "Timer Stats Version: v0.3\n");
88521 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
88522- if (atomic_read(&overflow_count))
88523- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
88524+ if (atomic_read_unchecked(&overflow_count))
88525+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
88526 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
88527
88528 for (i = 0; i < nr_entries; i++) {
88529@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
88530 {
88531 struct proc_dir_entry *pe;
88532
88533+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88534+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
88535+#else
88536 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
88537+#endif
88538 if (!pe)
88539 return -ENOMEM;
88540 return 0;
88541diff --git a/kernel/timer.c b/kernel/timer.c
88542index accfd24..e00f0c0 100644
88543--- a/kernel/timer.c
88544+++ b/kernel/timer.c
88545@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
88546 /*
88547 * This function runs timers and the timer-tq in bottom half context.
88548 */
88549-static void run_timer_softirq(struct softirq_action *h)
88550+static __latent_entropy void run_timer_softirq(void)
88551 {
88552 struct tvec_base *base = __this_cpu_read(tvec_bases);
88553
88554@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
88555 *
88556 * In all cases the return value is guaranteed to be non-negative.
88557 */
88558-signed long __sched schedule_timeout(signed long timeout)
88559+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
88560 {
88561 struct timer_list timer;
88562 unsigned long expire;
88563diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
88564index f785aef..59f1b18 100644
88565--- a/kernel/trace/blktrace.c
88566+++ b/kernel/trace/blktrace.c
88567@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
88568 struct blk_trace *bt = filp->private_data;
88569 char buf[16];
88570
88571- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
88572+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
88573
88574 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
88575 }
88576@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
88577 return 1;
88578
88579 bt = buf->chan->private_data;
88580- atomic_inc(&bt->dropped);
88581+ atomic_inc_unchecked(&bt->dropped);
88582 return 0;
88583 }
88584
88585@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
88586
88587 bt->dir = dir;
88588 bt->dev = dev;
88589- atomic_set(&bt->dropped, 0);
88590+ atomic_set_unchecked(&bt->dropped, 0);
88591 INIT_LIST_HEAD(&bt->running_list);
88592
88593 ret = -EIO;
88594diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
88595index 72a0f81..0bbfd090 100644
88596--- a/kernel/trace/ftrace.c
88597+++ b/kernel/trace/ftrace.c
88598@@ -1944,12 +1944,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
88599 if (unlikely(ftrace_disabled))
88600 return 0;
88601
88602+ ret = ftrace_arch_code_modify_prepare();
88603+ FTRACE_WARN_ON(ret);
88604+ if (ret)
88605+ return 0;
88606+
88607 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
88608+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
88609 if (ret) {
88610 ftrace_bug(ret, ip);
88611- return 0;
88612 }
88613- return 1;
88614+ return ret ? 0 : 1;
88615 }
88616
88617 /*
88618@@ -4119,8 +4124,10 @@ static int ftrace_process_locs(struct module *mod,
88619 if (!count)
88620 return 0;
88621
88622+ pax_open_kernel();
88623 sort(start, count, sizeof(*start),
88624 ftrace_cmp_ips, ftrace_swap_ips);
88625+ pax_close_kernel();
88626
88627 start_pg = ftrace_allocate_pages(count);
88628 if (!start_pg)
88629@@ -4851,8 +4858,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
88630 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
88631
88632 static int ftrace_graph_active;
88633-static struct notifier_block ftrace_suspend_notifier;
88634-
88635 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
88636 {
88637 return 0;
88638@@ -5003,6 +5008,10 @@ static struct ftrace_ops fgraph_ops __read_mostly = {
88639 FTRACE_OPS_FL_RECURSION_SAFE,
88640 };
88641
88642+static struct notifier_block ftrace_suspend_notifier = {
88643+ .notifier_call = ftrace_suspend_notifier_call
88644+};
88645+
88646 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88647 trace_func_graph_ent_t entryfunc)
88648 {
88649@@ -5016,7 +5025,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88650 goto out;
88651 }
88652
88653- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
88654 register_pm_notifier(&ftrace_suspend_notifier);
88655
88656 ftrace_graph_active++;
88657diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
88658index cc2f66f..05edd54 100644
88659--- a/kernel/trace/ring_buffer.c
88660+++ b/kernel/trace/ring_buffer.c
88661@@ -352,9 +352,9 @@ struct buffer_data_page {
88662 */
88663 struct buffer_page {
88664 struct list_head list; /* list of buffer pages */
88665- local_t write; /* index for next write */
88666+ local_unchecked_t write; /* index for next write */
88667 unsigned read; /* index for next read */
88668- local_t entries; /* entries on this page */
88669+ local_unchecked_t entries; /* entries on this page */
88670 unsigned long real_end; /* real end of data */
88671 struct buffer_data_page *page; /* Actual data page */
88672 };
88673@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
88674 unsigned long last_overrun;
88675 local_t entries_bytes;
88676 local_t entries;
88677- local_t overrun;
88678- local_t commit_overrun;
88679+ local_unchecked_t overrun;
88680+ local_unchecked_t commit_overrun;
88681 local_t dropped_events;
88682 local_t committing;
88683 local_t commits;
88684@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88685 *
88686 * We add a counter to the write field to denote this.
88687 */
88688- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
88689- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
88690+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
88691+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
88692
88693 /*
88694 * Just make sure we have seen our old_write and synchronize
88695@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88696 * cmpxchg to only update if an interrupt did not already
88697 * do it for us. If the cmpxchg fails, we don't care.
88698 */
88699- (void)local_cmpxchg(&next_page->write, old_write, val);
88700- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
88701+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
88702+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
88703
88704 /*
88705 * No need to worry about races with clearing out the commit.
88706@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
88707
88708 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
88709 {
88710- return local_read(&bpage->entries) & RB_WRITE_MASK;
88711+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
88712 }
88713
88714 static inline unsigned long rb_page_write(struct buffer_page *bpage)
88715 {
88716- return local_read(&bpage->write) & RB_WRITE_MASK;
88717+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
88718 }
88719
88720 static int
88721@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
88722 * bytes consumed in ring buffer from here.
88723 * Increment overrun to account for the lost events.
88724 */
88725- local_add(page_entries, &cpu_buffer->overrun);
88726+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
88727 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
88728 }
88729
88730@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
88731 * it is our responsibility to update
88732 * the counters.
88733 */
88734- local_add(entries, &cpu_buffer->overrun);
88735+ local_add_unchecked(entries, &cpu_buffer->overrun);
88736 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
88737
88738 /*
88739@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88740 if (tail == BUF_PAGE_SIZE)
88741 tail_page->real_end = 0;
88742
88743- local_sub(length, &tail_page->write);
88744+ local_sub_unchecked(length, &tail_page->write);
88745 return;
88746 }
88747
88748@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88749 rb_event_set_padding(event);
88750
88751 /* Set the write back to the previous setting */
88752- local_sub(length, &tail_page->write);
88753+ local_sub_unchecked(length, &tail_page->write);
88754 return;
88755 }
88756
88757@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88758
88759 /* Set write to end of buffer */
88760 length = (tail + length) - BUF_PAGE_SIZE;
88761- local_sub(length, &tail_page->write);
88762+ local_sub_unchecked(length, &tail_page->write);
88763 }
88764
88765 /*
88766@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
88767 * about it.
88768 */
88769 if (unlikely(next_page == commit_page)) {
88770- local_inc(&cpu_buffer->commit_overrun);
88771+ local_inc_unchecked(&cpu_buffer->commit_overrun);
88772 goto out_reset;
88773 }
88774
88775@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
88776 cpu_buffer->tail_page) &&
88777 (cpu_buffer->commit_page ==
88778 cpu_buffer->reader_page))) {
88779- local_inc(&cpu_buffer->commit_overrun);
88780+ local_inc_unchecked(&cpu_buffer->commit_overrun);
88781 goto out_reset;
88782 }
88783 }
88784@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
88785 length += RB_LEN_TIME_EXTEND;
88786
88787 tail_page = cpu_buffer->tail_page;
88788- write = local_add_return(length, &tail_page->write);
88789+ write = local_add_return_unchecked(length, &tail_page->write);
88790
88791 /* set write to only the index of the write */
88792 write &= RB_WRITE_MASK;
88793@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
88794 kmemcheck_annotate_bitfield(event, bitfield);
88795 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
88796
88797- local_inc(&tail_page->entries);
88798+ local_inc_unchecked(&tail_page->entries);
88799
88800 /*
88801 * If this is the first commit on the page, then update
88802@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
88803
88804 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
88805 unsigned long write_mask =
88806- local_read(&bpage->write) & ~RB_WRITE_MASK;
88807+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
88808 unsigned long event_length = rb_event_length(event);
88809 /*
88810 * This is on the tail page. It is possible that
88811@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
88812 */
88813 old_index += write_mask;
88814 new_index += write_mask;
88815- index = local_cmpxchg(&bpage->write, old_index, new_index);
88816+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
88817 if (index == old_index) {
88818 /* update counters */
88819 local_sub(event_length, &cpu_buffer->entries_bytes);
88820@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
88821
88822 /* Do the likely case first */
88823 if (likely(bpage->page == (void *)addr)) {
88824- local_dec(&bpage->entries);
88825+ local_dec_unchecked(&bpage->entries);
88826 return;
88827 }
88828
88829@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
88830 start = bpage;
88831 do {
88832 if (bpage->page == (void *)addr) {
88833- local_dec(&bpage->entries);
88834+ local_dec_unchecked(&bpage->entries);
88835 return;
88836 }
88837 rb_inc_page(cpu_buffer, &bpage);
88838@@ -3139,7 +3139,7 @@ static inline unsigned long
88839 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
88840 {
88841 return local_read(&cpu_buffer->entries) -
88842- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
88843+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
88844 }
88845
88846 /**
88847@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
88848 return 0;
88849
88850 cpu_buffer = buffer->buffers[cpu];
88851- ret = local_read(&cpu_buffer->overrun);
88852+ ret = local_read_unchecked(&cpu_buffer->overrun);
88853
88854 return ret;
88855 }
88856@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
88857 return 0;
88858
88859 cpu_buffer = buffer->buffers[cpu];
88860- ret = local_read(&cpu_buffer->commit_overrun);
88861+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
88862
88863 return ret;
88864 }
88865@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
88866 /* if you care about this being correct, lock the buffer */
88867 for_each_buffer_cpu(buffer, cpu) {
88868 cpu_buffer = buffer->buffers[cpu];
88869- overruns += local_read(&cpu_buffer->overrun);
88870+ overruns += local_read_unchecked(&cpu_buffer->overrun);
88871 }
88872
88873 return overruns;
88874@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
88875 /*
88876 * Reset the reader page to size zero.
88877 */
88878- local_set(&cpu_buffer->reader_page->write, 0);
88879- local_set(&cpu_buffer->reader_page->entries, 0);
88880+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
88881+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
88882 local_set(&cpu_buffer->reader_page->page->commit, 0);
88883 cpu_buffer->reader_page->real_end = 0;
88884
88885@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
88886 * want to compare with the last_overrun.
88887 */
88888 smp_mb();
88889- overwrite = local_read(&(cpu_buffer->overrun));
88890+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
88891
88892 /*
88893 * Here's the tricky part.
88894@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
88895
88896 cpu_buffer->head_page
88897 = list_entry(cpu_buffer->pages, struct buffer_page, list);
88898- local_set(&cpu_buffer->head_page->write, 0);
88899- local_set(&cpu_buffer->head_page->entries, 0);
88900+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
88901+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
88902 local_set(&cpu_buffer->head_page->page->commit, 0);
88903
88904 cpu_buffer->head_page->read = 0;
88905@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
88906
88907 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
88908 INIT_LIST_HEAD(&cpu_buffer->new_pages);
88909- local_set(&cpu_buffer->reader_page->write, 0);
88910- local_set(&cpu_buffer->reader_page->entries, 0);
88911+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
88912+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
88913 local_set(&cpu_buffer->reader_page->page->commit, 0);
88914 cpu_buffer->reader_page->read = 0;
88915
88916 local_set(&cpu_buffer->entries_bytes, 0);
88917- local_set(&cpu_buffer->overrun, 0);
88918- local_set(&cpu_buffer->commit_overrun, 0);
88919+ local_set_unchecked(&cpu_buffer->overrun, 0);
88920+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
88921 local_set(&cpu_buffer->dropped_events, 0);
88922 local_set(&cpu_buffer->entries, 0);
88923 local_set(&cpu_buffer->committing, 0);
88924@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
88925 rb_init_page(bpage);
88926 bpage = reader->page;
88927 reader->page = *data_page;
88928- local_set(&reader->write, 0);
88929- local_set(&reader->entries, 0);
88930+ local_set_unchecked(&reader->write, 0);
88931+ local_set_unchecked(&reader->entries, 0);
88932 reader->read = 0;
88933 *data_page = bpage;
88934
88935diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
88936index 9d20cd9..221d816 100644
88937--- a/kernel/trace/trace.c
88938+++ b/kernel/trace/trace.c
88939@@ -3346,7 +3346,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
88940 return 0;
88941 }
88942
88943-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
88944+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
88945 {
88946 /* do nothing if flag is already set */
88947 if (!!(trace_flags & mask) == !!enabled)
88948diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
88949index ea189e0..a5b48c4 100644
88950--- a/kernel/trace/trace.h
88951+++ b/kernel/trace/trace.h
88952@@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
88953 void trace_printk_init_buffers(void);
88954 void trace_printk_start_comm(void);
88955 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
88956-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
88957+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
88958
88959 /*
88960 * Normal trace_printk() and friends allocates special buffers
88961diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
88962index 26dc348..8708ca7 100644
88963--- a/kernel/trace/trace_clock.c
88964+++ b/kernel/trace/trace_clock.c
88965@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
88966 return now;
88967 }
88968
88969-static atomic64_t trace_counter;
88970+static atomic64_unchecked_t trace_counter;
88971
88972 /*
88973 * trace_clock_counter(): simply an atomic counter.
88974@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
88975 */
88976 u64 notrace trace_clock_counter(void)
88977 {
88978- return atomic64_add_return(1, &trace_counter);
88979+ return atomic64_inc_return_unchecked(&trace_counter);
88980 }
88981diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
88982index a11800a..3dafde5 100644
88983--- a/kernel/trace/trace_events.c
88984+++ b/kernel/trace/trace_events.c
88985@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
88986 return 0;
88987 }
88988
88989-struct ftrace_module_file_ops;
88990 static void __add_event_to_tracers(struct ftrace_event_call *call);
88991
88992 /* Add an additional event_call dynamically */
88993diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
88994index 0abd9b8..6a663a2 100644
88995--- a/kernel/trace/trace_mmiotrace.c
88996+++ b/kernel/trace/trace_mmiotrace.c
88997@@ -24,7 +24,7 @@ struct header_iter {
88998 static struct trace_array *mmio_trace_array;
88999 static bool overrun_detected;
89000 static unsigned long prev_overruns;
89001-static atomic_t dropped_count;
89002+static atomic_unchecked_t dropped_count;
89003
89004 static void mmio_reset_data(struct trace_array *tr)
89005 {
89006@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
89007
89008 static unsigned long count_overruns(struct trace_iterator *iter)
89009 {
89010- unsigned long cnt = atomic_xchg(&dropped_count, 0);
89011+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
89012 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
89013
89014 if (over > prev_overruns)
89015@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
89016 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
89017 sizeof(*entry), 0, pc);
89018 if (!event) {
89019- atomic_inc(&dropped_count);
89020+ atomic_inc_unchecked(&dropped_count);
89021 return;
89022 }
89023 entry = ring_buffer_event_data(event);
89024@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
89025 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
89026 sizeof(*entry), 0, pc);
89027 if (!event) {
89028- atomic_inc(&dropped_count);
89029+ atomic_inc_unchecked(&dropped_count);
89030 return;
89031 }
89032 entry = ring_buffer_event_data(event);
89033diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
89034index ed32284..884d6c3 100644
89035--- a/kernel/trace/trace_output.c
89036+++ b/kernel/trace/trace_output.c
89037@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
89038
89039 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
89040 if (!IS_ERR(p)) {
89041- p = mangle_path(s->buffer + s->len, p, "\n");
89042+ p = mangle_path(s->buffer + s->len, p, "\n\\");
89043 if (p) {
89044 s->len = p - s->buffer;
89045 return 1;
89046@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
89047 goto out;
89048 }
89049
89050+ pax_open_kernel();
89051 if (event->funcs->trace == NULL)
89052- event->funcs->trace = trace_nop_print;
89053+ *(void **)&event->funcs->trace = trace_nop_print;
89054 if (event->funcs->raw == NULL)
89055- event->funcs->raw = trace_nop_print;
89056+ *(void **)&event->funcs->raw = trace_nop_print;
89057 if (event->funcs->hex == NULL)
89058- event->funcs->hex = trace_nop_print;
89059+ *(void **)&event->funcs->hex = trace_nop_print;
89060 if (event->funcs->binary == NULL)
89061- event->funcs->binary = trace_nop_print;
89062+ *(void **)&event->funcs->binary = trace_nop_print;
89063+ pax_close_kernel();
89064
89065 key = event->type & (EVENT_HASHSIZE - 1);
89066
89067diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
89068index b20428c..4845a10 100644
89069--- a/kernel/trace/trace_stack.c
89070+++ b/kernel/trace/trace_stack.c
89071@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
89072 return;
89073
89074 /* we do not handle interrupt stacks yet */
89075- if (!object_is_on_stack(stack))
89076+ if (!object_starts_on_stack(stack))
89077 return;
89078
89079 local_irq_save(flags);
89080diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
89081index 240fb62..583473e 100644
89082--- a/kernel/user_namespace.c
89083+++ b/kernel/user_namespace.c
89084@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
89085 !kgid_has_mapping(parent_ns, group))
89086 return -EPERM;
89087
89088+#ifdef CONFIG_GRKERNSEC
89089+ /*
89090+ * This doesn't really inspire confidence:
89091+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
89092+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
89093+ * Increases kernel attack surface in areas developers
89094+ * previously cared little about ("low importance due
89095+ * to requiring "root" capability")
89096+ * To be removed when this code receives *proper* review
89097+ */
89098+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
89099+ !capable(CAP_SETGID))
89100+ return -EPERM;
89101+#endif
89102+
89103 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
89104 if (!ns)
89105 return -ENOMEM;
89106@@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
89107 if (atomic_read(&current->mm->mm_users) > 1)
89108 return -EINVAL;
89109
89110- if (current->fs->users != 1)
89111+ if (atomic_read(&current->fs->users) != 1)
89112 return -EINVAL;
89113
89114 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
89115diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
89116index 4f69f9a..7c6f8f8 100644
89117--- a/kernel/utsname_sysctl.c
89118+++ b/kernel/utsname_sysctl.c
89119@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
89120 static int proc_do_uts_string(ctl_table *table, int write,
89121 void __user *buffer, size_t *lenp, loff_t *ppos)
89122 {
89123- struct ctl_table uts_table;
89124+ ctl_table_no_const uts_table;
89125 int r;
89126 memcpy(&uts_table, table, sizeof(uts_table));
89127 uts_table.data = get_uts(table, write);
89128diff --git a/kernel/watchdog.c b/kernel/watchdog.c
89129index 4431610..4265616 100644
89130--- a/kernel/watchdog.c
89131+++ b/kernel/watchdog.c
89132@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
89133 static void watchdog_nmi_disable(unsigned int cpu) { return; }
89134 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
89135
89136-static struct smp_hotplug_thread watchdog_threads = {
89137+static struct smp_hotplug_thread watchdog_threads __read_only = {
89138 .store = &softlockup_watchdog,
89139 .thread_should_run = watchdog_should_run,
89140 .thread_fn = watchdog,
89141diff --git a/kernel/workqueue.c b/kernel/workqueue.c
89142index b010eac..e4bda78 100644
89143--- a/kernel/workqueue.c
89144+++ b/kernel/workqueue.c
89145@@ -4671,7 +4671,7 @@ static void rebind_workers(struct worker_pool *pool)
89146 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
89147 worker_flags |= WORKER_REBOUND;
89148 worker_flags &= ~WORKER_UNBOUND;
89149- ACCESS_ONCE(worker->flags) = worker_flags;
89150+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
89151 }
89152
89153 spin_unlock_irq(&pool->lock);
89154diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
89155index db25707..8b16430 100644
89156--- a/lib/Kconfig.debug
89157+++ b/lib/Kconfig.debug
89158@@ -845,7 +845,7 @@ config DEBUG_MUTEXES
89159
89160 config DEBUG_WW_MUTEX_SLOWPATH
89161 bool "Wait/wound mutex debugging: Slowpath testing"
89162- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89163+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89164 select DEBUG_LOCK_ALLOC
89165 select DEBUG_SPINLOCK
89166 select DEBUG_MUTEXES
89167@@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
89168
89169 config DEBUG_LOCK_ALLOC
89170 bool "Lock debugging: detect incorrect freeing of live locks"
89171- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89172+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89173 select DEBUG_SPINLOCK
89174 select DEBUG_MUTEXES
89175 select LOCKDEP
89176@@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
89177
89178 config PROVE_LOCKING
89179 bool "Lock debugging: prove locking correctness"
89180- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89181+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89182 select LOCKDEP
89183 select DEBUG_SPINLOCK
89184 select DEBUG_MUTEXES
89185@@ -923,7 +923,7 @@ config LOCKDEP
89186
89187 config LOCK_STAT
89188 bool "Lock usage statistics"
89189- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89190+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89191 select LOCKDEP
89192 select DEBUG_SPINLOCK
89193 select DEBUG_MUTEXES
89194@@ -1385,6 +1385,7 @@ config LATENCYTOP
89195 depends on DEBUG_KERNEL
89196 depends on STACKTRACE_SUPPORT
89197 depends on PROC_FS
89198+ depends on !GRKERNSEC_HIDESYM
89199 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
89200 select KALLSYMS
89201 select KALLSYMS_ALL
89202@@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89203 config DEBUG_STRICT_USER_COPY_CHECKS
89204 bool "Strict user copy size checks"
89205 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89206- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
89207+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
89208 help
89209 Enabling this option turns a certain set of sanity checks for user
89210 copy operations into compile time failures.
89211@@ -1520,7 +1521,7 @@ endmenu # runtime tests
89212
89213 config PROVIDE_OHCI1394_DMA_INIT
89214 bool "Remote debugging over FireWire early on boot"
89215- depends on PCI && X86
89216+ depends on PCI && X86 && !GRKERNSEC
89217 help
89218 If you want to debug problems which hang or crash the kernel early
89219 on boot and the crashing machine has a FireWire port, you can use
89220@@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
89221
89222 config FIREWIRE_OHCI_REMOTE_DMA
89223 bool "Remote debugging over FireWire with firewire-ohci"
89224- depends on FIREWIRE_OHCI
89225+ depends on FIREWIRE_OHCI && !GRKERNSEC
89226 help
89227 This option lets you use the FireWire bus for remote debugging
89228 with help of the firewire-ohci driver. It enables unfiltered
89229diff --git a/lib/Makefile b/lib/Makefile
89230index a459c31..3320e82 100644
89231--- a/lib/Makefile
89232+++ b/lib/Makefile
89233@@ -49,7 +49,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
89234 obj-$(CONFIG_BTREE) += btree.o
89235 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
89236 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
89237-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
89238+obj-y += list_debug.o
89239 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
89240
89241 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
89242diff --git a/lib/bitmap.c b/lib/bitmap.c
89243index 06f7e4f..f3cf2b0 100644
89244--- a/lib/bitmap.c
89245+++ b/lib/bitmap.c
89246@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
89247 {
89248 int c, old_c, totaldigits, ndigits, nchunks, nbits;
89249 u32 chunk;
89250- const char __user __force *ubuf = (const char __user __force *)buf;
89251+ const char __user *ubuf = (const char __force_user *)buf;
89252
89253 bitmap_zero(maskp, nmaskbits);
89254
89255@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
89256 {
89257 if (!access_ok(VERIFY_READ, ubuf, ulen))
89258 return -EFAULT;
89259- return __bitmap_parse((const char __force *)ubuf,
89260+ return __bitmap_parse((const char __force_kernel *)ubuf,
89261 ulen, 1, maskp, nmaskbits);
89262
89263 }
89264@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
89265 {
89266 unsigned a, b;
89267 int c, old_c, totaldigits;
89268- const char __user __force *ubuf = (const char __user __force *)buf;
89269+ const char __user *ubuf = (const char __force_user *)buf;
89270 int exp_digit, in_range;
89271
89272 totaldigits = c = 0;
89273@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
89274 {
89275 if (!access_ok(VERIFY_READ, ubuf, ulen))
89276 return -EFAULT;
89277- return __bitmap_parselist((const char __force *)ubuf,
89278+ return __bitmap_parselist((const char __force_kernel *)ubuf,
89279 ulen, 1, maskp, nmaskbits);
89280 }
89281 EXPORT_SYMBOL(bitmap_parselist_user);
89282diff --git a/lib/bug.c b/lib/bug.c
89283index 1686034..a9c00c8 100644
89284--- a/lib/bug.c
89285+++ b/lib/bug.c
89286@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
89287 return BUG_TRAP_TYPE_NONE;
89288
89289 bug = find_bug(bugaddr);
89290+ if (!bug)
89291+ return BUG_TRAP_TYPE_NONE;
89292
89293 file = NULL;
89294 line = 0;
89295diff --git a/lib/debugobjects.c b/lib/debugobjects.c
89296index e0731c3..ad66444 100644
89297--- a/lib/debugobjects.c
89298+++ b/lib/debugobjects.c
89299@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
89300 if (limit > 4)
89301 return;
89302
89303- is_on_stack = object_is_on_stack(addr);
89304+ is_on_stack = object_starts_on_stack(addr);
89305 if (is_on_stack == onstack)
89306 return;
89307
89308diff --git a/lib/devres.c b/lib/devres.c
89309index 8235331..5881053 100644
89310--- a/lib/devres.c
89311+++ b/lib/devres.c
89312@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
89313 void devm_iounmap(struct device *dev, void __iomem *addr)
89314 {
89315 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
89316- (void *)addr));
89317+ (void __force *)addr));
89318 iounmap(addr);
89319 }
89320 EXPORT_SYMBOL(devm_iounmap);
89321@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
89322 {
89323 ioport_unmap(addr);
89324 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
89325- devm_ioport_map_match, (void *)addr));
89326+ devm_ioport_map_match, (void __force *)addr));
89327 }
89328 EXPORT_SYMBOL(devm_ioport_unmap);
89329 #endif /* CONFIG_HAS_IOPORT */
89330diff --git a/lib/div64.c b/lib/div64.c
89331index 4382ad7..08aa558 100644
89332--- a/lib/div64.c
89333+++ b/lib/div64.c
89334@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
89335 EXPORT_SYMBOL(__div64_32);
89336
89337 #ifndef div_s64_rem
89338-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89339+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89340 {
89341 u64 quotient;
89342
89343@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
89344 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
89345 */
89346 #ifndef div64_u64
89347-u64 div64_u64(u64 dividend, u64 divisor)
89348+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
89349 {
89350 u32 high = divisor >> 32;
89351 u64 quot;
89352diff --git a/lib/dma-debug.c b/lib/dma-debug.c
89353index d87a17a..ac0d79a 100644
89354--- a/lib/dma-debug.c
89355+++ b/lib/dma-debug.c
89356@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
89357
89358 void dma_debug_add_bus(struct bus_type *bus)
89359 {
89360- struct notifier_block *nb;
89361+ notifier_block_no_const *nb;
89362
89363 if (global_disable)
89364 return;
89365@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
89366
89367 static void check_for_stack(struct device *dev, void *addr)
89368 {
89369- if (object_is_on_stack(addr))
89370+ if (object_starts_on_stack(addr))
89371 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
89372 "stack [addr=%p]\n", addr);
89373 }
89374diff --git a/lib/inflate.c b/lib/inflate.c
89375index 013a761..c28f3fc 100644
89376--- a/lib/inflate.c
89377+++ b/lib/inflate.c
89378@@ -269,7 +269,7 @@ static void free(void *where)
89379 malloc_ptr = free_mem_ptr;
89380 }
89381 #else
89382-#define malloc(a) kmalloc(a, GFP_KERNEL)
89383+#define malloc(a) kmalloc((a), GFP_KERNEL)
89384 #define free(a) kfree(a)
89385 #endif
89386
89387diff --git a/lib/ioremap.c b/lib/ioremap.c
89388index 0c9216c..863bd89 100644
89389--- a/lib/ioremap.c
89390+++ b/lib/ioremap.c
89391@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
89392 unsigned long next;
89393
89394 phys_addr -= addr;
89395- pmd = pmd_alloc(&init_mm, pud, addr);
89396+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
89397 if (!pmd)
89398 return -ENOMEM;
89399 do {
89400@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
89401 unsigned long next;
89402
89403 phys_addr -= addr;
89404- pud = pud_alloc(&init_mm, pgd, addr);
89405+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
89406 if (!pud)
89407 return -ENOMEM;
89408 do {
89409diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
89410index bd2bea9..6b3c95e 100644
89411--- a/lib/is_single_threaded.c
89412+++ b/lib/is_single_threaded.c
89413@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
89414 struct task_struct *p, *t;
89415 bool ret;
89416
89417+ if (!mm)
89418+ return true;
89419+
89420 if (atomic_read(&task->signal->live) != 1)
89421 return false;
89422
89423diff --git a/lib/kobject.c b/lib/kobject.c
89424index 5b4b888..c2950f7 100644
89425--- a/lib/kobject.c
89426+++ b/lib/kobject.c
89427@@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
89428
89429
89430 static DEFINE_SPINLOCK(kobj_ns_type_lock);
89431-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
89432+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
89433
89434-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89435+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89436 {
89437 enum kobj_ns_type type = ops->type;
89438 int error;
89439diff --git a/lib/list_debug.c b/lib/list_debug.c
89440index c24c2f7..f0296f4 100644
89441--- a/lib/list_debug.c
89442+++ b/lib/list_debug.c
89443@@ -11,7 +11,9 @@
89444 #include <linux/bug.h>
89445 #include <linux/kernel.h>
89446 #include <linux/rculist.h>
89447+#include <linux/mm.h>
89448
89449+#ifdef CONFIG_DEBUG_LIST
89450 /*
89451 * Insert a new entry between two known consecutive entries.
89452 *
89453@@ -19,21 +21,40 @@
89454 * the prev/next entries already!
89455 */
89456
89457+static bool __list_add_debug(struct list_head *new,
89458+ struct list_head *prev,
89459+ struct list_head *next)
89460+{
89461+ if (unlikely(next->prev != prev)) {
89462+ printk(KERN_ERR "list_add corruption. next->prev should be "
89463+ "prev (%p), but was %p. (next=%p).\n",
89464+ prev, next->prev, next);
89465+ BUG();
89466+ return false;
89467+ }
89468+ if (unlikely(prev->next != next)) {
89469+ printk(KERN_ERR "list_add corruption. prev->next should be "
89470+ "next (%p), but was %p. (prev=%p).\n",
89471+ next, prev->next, prev);
89472+ BUG();
89473+ return false;
89474+ }
89475+ if (unlikely(new == prev || new == next)) {
89476+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
89477+ new, prev, next);
89478+ BUG();
89479+ return false;
89480+ }
89481+ return true;
89482+}
89483+
89484 void __list_add(struct list_head *new,
89485- struct list_head *prev,
89486- struct list_head *next)
89487+ struct list_head *prev,
89488+ struct list_head *next)
89489 {
89490- WARN(next->prev != prev,
89491- "list_add corruption. next->prev should be "
89492- "prev (%p), but was %p. (next=%p).\n",
89493- prev, next->prev, next);
89494- WARN(prev->next != next,
89495- "list_add corruption. prev->next should be "
89496- "next (%p), but was %p. (prev=%p).\n",
89497- next, prev->next, prev);
89498- WARN(new == prev || new == next,
89499- "list_add double add: new=%p, prev=%p, next=%p.\n",
89500- new, prev, next);
89501+ if (!__list_add_debug(new, prev, next))
89502+ return;
89503+
89504 next->prev = new;
89505 new->next = next;
89506 new->prev = prev;
89507@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
89508 }
89509 EXPORT_SYMBOL(__list_add);
89510
89511-void __list_del_entry(struct list_head *entry)
89512+static bool __list_del_entry_debug(struct list_head *entry)
89513 {
89514 struct list_head *prev, *next;
89515
89516 prev = entry->prev;
89517 next = entry->next;
89518
89519- if (WARN(next == LIST_POISON1,
89520- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89521- entry, LIST_POISON1) ||
89522- WARN(prev == LIST_POISON2,
89523- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89524- entry, LIST_POISON2) ||
89525- WARN(prev->next != entry,
89526- "list_del corruption. prev->next should be %p, "
89527- "but was %p\n", entry, prev->next) ||
89528- WARN(next->prev != entry,
89529- "list_del corruption. next->prev should be %p, "
89530- "but was %p\n", entry, next->prev))
89531+ if (unlikely(next == LIST_POISON1)) {
89532+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89533+ entry, LIST_POISON1);
89534+ BUG();
89535+ return false;
89536+ }
89537+ if (unlikely(prev == LIST_POISON2)) {
89538+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89539+ entry, LIST_POISON2);
89540+ BUG();
89541+ return false;
89542+ }
89543+ if (unlikely(entry->prev->next != entry)) {
89544+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
89545+ "but was %p\n", entry, prev->next);
89546+ BUG();
89547+ return false;
89548+ }
89549+ if (unlikely(entry->next->prev != entry)) {
89550+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
89551+ "but was %p\n", entry, next->prev);
89552+ BUG();
89553+ return false;
89554+ }
89555+ return true;
89556+}
89557+
89558+void __list_del_entry(struct list_head *entry)
89559+{
89560+ if (!__list_del_entry_debug(entry))
89561 return;
89562
89563- __list_del(prev, next);
89564+ __list_del(entry->prev, entry->next);
89565 }
89566 EXPORT_SYMBOL(__list_del_entry);
89567
89568@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
89569 void __list_add_rcu(struct list_head *new,
89570 struct list_head *prev, struct list_head *next)
89571 {
89572- WARN(next->prev != prev,
89573- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
89574- prev, next->prev, next);
89575- WARN(prev->next != next,
89576- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
89577- next, prev->next, prev);
89578+ if (!__list_add_debug(new, prev, next))
89579+ return;
89580+
89581 new->next = next;
89582 new->prev = prev;
89583 rcu_assign_pointer(list_next_rcu(prev), new);
89584 next->prev = new;
89585 }
89586 EXPORT_SYMBOL(__list_add_rcu);
89587+#endif
89588+
89589+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
89590+{
89591+#ifdef CONFIG_DEBUG_LIST
89592+ if (!__list_add_debug(new, prev, next))
89593+ return;
89594+#endif
89595+
89596+ pax_open_kernel();
89597+ next->prev = new;
89598+ new->next = next;
89599+ new->prev = prev;
89600+ prev->next = new;
89601+ pax_close_kernel();
89602+}
89603+EXPORT_SYMBOL(__pax_list_add);
89604+
89605+void pax_list_del(struct list_head *entry)
89606+{
89607+#ifdef CONFIG_DEBUG_LIST
89608+ if (!__list_del_entry_debug(entry))
89609+ return;
89610+#endif
89611+
89612+ pax_open_kernel();
89613+ __list_del(entry->prev, entry->next);
89614+ entry->next = LIST_POISON1;
89615+ entry->prev = LIST_POISON2;
89616+ pax_close_kernel();
89617+}
89618+EXPORT_SYMBOL(pax_list_del);
89619+
89620+void pax_list_del_init(struct list_head *entry)
89621+{
89622+ pax_open_kernel();
89623+ __list_del(entry->prev, entry->next);
89624+ INIT_LIST_HEAD(entry);
89625+ pax_close_kernel();
89626+}
89627+EXPORT_SYMBOL(pax_list_del_init);
89628+
89629+void __pax_list_add_rcu(struct list_head *new,
89630+ struct list_head *prev, struct list_head *next)
89631+{
89632+#ifdef CONFIG_DEBUG_LIST
89633+ if (!__list_add_debug(new, prev, next))
89634+ return;
89635+#endif
89636+
89637+ pax_open_kernel();
89638+ new->next = next;
89639+ new->prev = prev;
89640+ rcu_assign_pointer(list_next_rcu(prev), new);
89641+ next->prev = new;
89642+ pax_close_kernel();
89643+}
89644+EXPORT_SYMBOL(__pax_list_add_rcu);
89645+
89646+void pax_list_del_rcu(struct list_head *entry)
89647+{
89648+#ifdef CONFIG_DEBUG_LIST
89649+ if (!__list_del_entry_debug(entry))
89650+ return;
89651+#endif
89652+
89653+ pax_open_kernel();
89654+ __list_del(entry->prev, entry->next);
89655+ entry->next = LIST_POISON1;
89656+ entry->prev = LIST_POISON2;
89657+ pax_close_kernel();
89658+}
89659+EXPORT_SYMBOL(pax_list_del_rcu);
89660diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
89661index 1a53d49..ace934c 100644
89662--- a/lib/percpu-refcount.c
89663+++ b/lib/percpu-refcount.c
89664@@ -29,7 +29,7 @@
89665 * can't hit 0 before we've added up all the percpu refs.
89666 */
89667
89668-#define PCPU_COUNT_BIAS (1U << 31)
89669+#define PCPU_COUNT_BIAS (1U << 30)
89670
89671 /**
89672 * percpu_ref_init - initialize a percpu refcount
89673diff --git a/lib/radix-tree.c b/lib/radix-tree.c
89674index 7811ed3..f80ca19 100644
89675--- a/lib/radix-tree.c
89676+++ b/lib/radix-tree.c
89677@@ -93,7 +93,7 @@ struct radix_tree_preload {
89678 int nr;
89679 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
89680 };
89681-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
89682+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
89683
89684 static inline void *ptr_to_indirect(void *ptr)
89685 {
89686diff --git a/lib/rbtree.c b/lib/rbtree.c
89687index 65f4eff..2cfa167 100644
89688--- a/lib/rbtree.c
89689+++ b/lib/rbtree.c
89690@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
89691 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
89692
89693 static const struct rb_augment_callbacks dummy_callbacks = {
89694- dummy_propagate, dummy_copy, dummy_rotate
89695+ .propagate = dummy_propagate,
89696+ .copy = dummy_copy,
89697+ .rotate = dummy_rotate
89698 };
89699
89700 void rb_insert_color(struct rb_node *node, struct rb_root *root)
89701diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
89702index bb2b201..46abaf9 100644
89703--- a/lib/strncpy_from_user.c
89704+++ b/lib/strncpy_from_user.c
89705@@ -21,7 +21,7 @@
89706 */
89707 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
89708 {
89709- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89710+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89711 long res = 0;
89712
89713 /*
89714diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
89715index a28df52..3d55877 100644
89716--- a/lib/strnlen_user.c
89717+++ b/lib/strnlen_user.c
89718@@ -26,7 +26,7 @@
89719 */
89720 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
89721 {
89722- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89723+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89724 long align, res = 0;
89725 unsigned long c;
89726
89727diff --git a/lib/swiotlb.c b/lib/swiotlb.c
89728index e4399fa..5e8b214 100644
89729--- a/lib/swiotlb.c
89730+++ b/lib/swiotlb.c
89731@@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
89732
89733 void
89734 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
89735- dma_addr_t dev_addr)
89736+ dma_addr_t dev_addr, struct dma_attrs *attrs)
89737 {
89738 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
89739
89740diff --git a/lib/usercopy.c b/lib/usercopy.c
89741index 4f5b1dd..7cab418 100644
89742--- a/lib/usercopy.c
89743+++ b/lib/usercopy.c
89744@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
89745 WARN(1, "Buffer overflow detected!\n");
89746 }
89747 EXPORT_SYMBOL(copy_from_user_overflow);
89748+
89749+void copy_to_user_overflow(void)
89750+{
89751+ WARN(1, "Buffer overflow detected!\n");
89752+}
89753+EXPORT_SYMBOL(copy_to_user_overflow);
89754diff --git a/lib/vsprintf.c b/lib/vsprintf.c
89755index 10909c5..653e1b8 100644
89756--- a/lib/vsprintf.c
89757+++ b/lib/vsprintf.c
89758@@ -16,6 +16,9 @@
89759 * - scnprintf and vscnprintf
89760 */
89761
89762+#ifdef CONFIG_GRKERNSEC_HIDESYM
89763+#define __INCLUDED_BY_HIDESYM 1
89764+#endif
89765 #include <stdarg.h>
89766 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
89767 #include <linux/types.h>
89768@@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
89769 return number(buf, end, *(const netdev_features_t *)addr, spec);
89770 }
89771
89772+#ifdef CONFIG_GRKERNSEC_HIDESYM
89773+int kptr_restrict __read_mostly = 2;
89774+#else
89775 int kptr_restrict __read_mostly;
89776+#endif
89777
89778 /*
89779 * Show a '%p' thing. A kernel extension is that the '%p' is followed
89780@@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
89781 * - 'f' For simple symbolic function names without offset
89782 * - 'S' For symbolic direct pointers with offset
89783 * - 's' For symbolic direct pointers without offset
89784+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
89785 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
89786 * - 'B' For backtraced symbolic direct pointers with offset
89787 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
89788@@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89789
89790 if (!ptr && *fmt != 'K') {
89791 /*
89792- * Print (null) with the same width as a pointer so it makes
89793+ * Print (nil) with the same width as a pointer so it makes
89794 * tabular output look nice.
89795 */
89796 if (spec.field_width == -1)
89797 spec.field_width = default_width;
89798- return string(buf, end, "(null)", spec);
89799+ return string(buf, end, "(nil)", spec);
89800 }
89801
89802 switch (*fmt) {
89803@@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89804 /* Fallthrough */
89805 case 'S':
89806 case 's':
89807+#ifdef CONFIG_GRKERNSEC_HIDESYM
89808+ break;
89809+#else
89810+ return symbol_string(buf, end, ptr, spec, fmt);
89811+#endif
89812+ case 'A':
89813 case 'B':
89814 return symbol_string(buf, end, ptr, spec, fmt);
89815 case 'R':
89816@@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89817 va_end(va);
89818 return buf;
89819 }
89820+ case 'P':
89821+ break;
89822 case 'K':
89823 /*
89824 * %pK cannot be used in IRQ context because its test
89825@@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89826 ((const struct file *)ptr)->f_path.dentry,
89827 spec, fmt);
89828 }
89829+
89830+#ifdef CONFIG_GRKERNSEC_HIDESYM
89831+ /* 'P' = approved pointers to copy to userland,
89832+ as in the /proc/kallsyms case, as we make it display nothing
89833+ for non-root users, and the real contents for root users
89834+ Also ignore 'K' pointers, since we force their NULLing for non-root users
89835+ above
89836+ */
89837+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
89838+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
89839+ dump_stack();
89840+ ptr = NULL;
89841+ }
89842+#endif
89843+
89844 spec.flags |= SMALL;
89845 if (spec.field_width == -1) {
89846 spec.field_width = default_width;
89847@@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
89848 typeof(type) value; \
89849 if (sizeof(type) == 8) { \
89850 args = PTR_ALIGN(args, sizeof(u32)); \
89851- *(u32 *)&value = *(u32 *)args; \
89852- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
89853+ *(u32 *)&value = *(const u32 *)args; \
89854+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
89855 } else { \
89856 args = PTR_ALIGN(args, sizeof(type)); \
89857- value = *(typeof(type) *)args; \
89858+ value = *(const typeof(type) *)args; \
89859 } \
89860 args += sizeof(type); \
89861 value; \
89862@@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
89863 case FORMAT_TYPE_STR: {
89864 const char *str_arg = args;
89865 args += strlen(str_arg) + 1;
89866- str = string(str, end, (char *)str_arg, spec);
89867+ str = string(str, end, str_arg, spec);
89868 break;
89869 }
89870
89871diff --git a/localversion-grsec b/localversion-grsec
89872new file mode 100644
89873index 0000000..7cd6065
89874--- /dev/null
89875+++ b/localversion-grsec
89876@@ -0,0 +1 @@
89877+-grsec
89878diff --git a/mm/Kconfig b/mm/Kconfig
89879index 723bbe0..ea624b1 100644
89880--- a/mm/Kconfig
89881+++ b/mm/Kconfig
89882@@ -326,10 +326,11 @@ config KSM
89883 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
89884
89885 config DEFAULT_MMAP_MIN_ADDR
89886- int "Low address space to protect from user allocation"
89887+ int "Low address space to protect from user allocation"
89888 depends on MMU
89889- default 4096
89890- help
89891+ default 32768 if ALPHA || ARM || PARISC || SPARC32
89892+ default 65536
89893+ help
89894 This is the portion of low virtual memory which should be protected
89895 from userspace allocation. Keeping a user from writing to low pages
89896 can help reduce the impact of kernel NULL pointer bugs.
89897@@ -360,7 +361,7 @@ config MEMORY_FAILURE
89898
89899 config HWPOISON_INJECT
89900 tristate "HWPoison pages injector"
89901- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
89902+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
89903 select PROC_PAGE_MONITOR
89904
89905 config NOMMU_INITIAL_TRIM_EXCESS
89906diff --git a/mm/backing-dev.c b/mm/backing-dev.c
89907index ce682f7..1fb54f9 100644
89908--- a/mm/backing-dev.c
89909+++ b/mm/backing-dev.c
89910@@ -12,7 +12,7 @@
89911 #include <linux/device.h>
89912 #include <trace/events/writeback.h>
89913
89914-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
89915+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
89916
89917 struct backing_dev_info default_backing_dev_info = {
89918 .name = "default",
89919@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
89920 return err;
89921
89922 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
89923- atomic_long_inc_return(&bdi_seq));
89924+ atomic_long_inc_return_unchecked(&bdi_seq));
89925 if (err) {
89926 bdi_destroy(bdi);
89927 return err;
89928diff --git a/mm/filemap.c b/mm/filemap.c
89929index b7749a9..50d1123 100644
89930--- a/mm/filemap.c
89931+++ b/mm/filemap.c
89932@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
89933 struct address_space *mapping = file->f_mapping;
89934
89935 if (!mapping->a_ops->readpage)
89936- return -ENOEXEC;
89937+ return -ENODEV;
89938 file_accessed(file);
89939 vma->vm_ops = &generic_file_vm_ops;
89940 return 0;
89941@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
89942
89943 while (bytes) {
89944 char __user *buf = iov->iov_base + base;
89945- int copy = min(bytes, iov->iov_len - base);
89946+ size_t copy = min(bytes, iov->iov_len - base);
89947
89948 base = 0;
89949 left = __copy_from_user_inatomic(vaddr, buf, copy);
89950@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
89951 BUG_ON(!in_atomic());
89952 kaddr = kmap_atomic(page);
89953 if (likely(i->nr_segs == 1)) {
89954- int left;
89955+ size_t left;
89956 char __user *buf = i->iov->iov_base + i->iov_offset;
89957 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
89958 copied = bytes - left;
89959@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
89960
89961 kaddr = kmap(page);
89962 if (likely(i->nr_segs == 1)) {
89963- int left;
89964+ size_t left;
89965 char __user *buf = i->iov->iov_base + i->iov_offset;
89966 left = __copy_from_user(kaddr + offset, buf, bytes);
89967 copied = bytes - left;
89968@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
89969 * zero-length segments (without overruning the iovec).
89970 */
89971 while (bytes || unlikely(i->count && !iov->iov_len)) {
89972- int copy;
89973+ size_t copy;
89974
89975 copy = min(bytes, iov->iov_len - base);
89976 BUG_ON(!i->count || i->count < copy);
89977@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
89978 *pos = i_size_read(inode);
89979
89980 if (limit != RLIM_INFINITY) {
89981+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
89982 if (*pos >= limit) {
89983 send_sig(SIGXFSZ, current, 0);
89984 return -EFBIG;
89985diff --git a/mm/fremap.c b/mm/fremap.c
89986index bbc4d66..117b798 100644
89987--- a/mm/fremap.c
89988+++ b/mm/fremap.c
89989@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
89990 retry:
89991 vma = find_vma(mm, start);
89992
89993+#ifdef CONFIG_PAX_SEGMEXEC
89994+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
89995+ goto out;
89996+#endif
89997+
89998 /*
89999 * Make sure the vma is shared, that it supports prefaulting,
90000 * and that the remapped range is valid and fully within
90001diff --git a/mm/highmem.c b/mm/highmem.c
90002index b32b70c..e512eb0 100644
90003--- a/mm/highmem.c
90004+++ b/mm/highmem.c
90005@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
90006 * So no dangers, even with speculative execution.
90007 */
90008 page = pte_page(pkmap_page_table[i]);
90009+ pax_open_kernel();
90010 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
90011-
90012+ pax_close_kernel();
90013 set_page_address(page, NULL);
90014 need_flush = 1;
90015 }
90016@@ -198,9 +199,11 @@ start:
90017 }
90018 }
90019 vaddr = PKMAP_ADDR(last_pkmap_nr);
90020+
90021+ pax_open_kernel();
90022 set_pte_at(&init_mm, vaddr,
90023 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
90024-
90025+ pax_close_kernel();
90026 pkmap_count[last_pkmap_nr] = 1;
90027 set_page_address(page, (void *)vaddr);
90028
90029diff --git a/mm/hugetlb.c b/mm/hugetlb.c
90030index dee6cf4..52b94f7 100644
90031--- a/mm/hugetlb.c
90032+++ b/mm/hugetlb.c
90033@@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
90034 struct hstate *h = &default_hstate;
90035 unsigned long tmp;
90036 int ret;
90037+ ctl_table_no_const hugetlb_table;
90038
90039 tmp = h->max_huge_pages;
90040
90041 if (write && h->order >= MAX_ORDER)
90042 return -EINVAL;
90043
90044- table->data = &tmp;
90045- table->maxlen = sizeof(unsigned long);
90046- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90047+ hugetlb_table = *table;
90048+ hugetlb_table.data = &tmp;
90049+ hugetlb_table.maxlen = sizeof(unsigned long);
90050+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90051 if (ret)
90052 goto out;
90053
90054@@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
90055 struct hstate *h = &default_hstate;
90056 unsigned long tmp;
90057 int ret;
90058+ ctl_table_no_const hugetlb_table;
90059
90060 tmp = h->nr_overcommit_huge_pages;
90061
90062 if (write && h->order >= MAX_ORDER)
90063 return -EINVAL;
90064
90065- table->data = &tmp;
90066- table->maxlen = sizeof(unsigned long);
90067- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90068+ hugetlb_table = *table;
90069+ hugetlb_table.data = &tmp;
90070+ hugetlb_table.maxlen = sizeof(unsigned long);
90071+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90072 if (ret)
90073 goto out;
90074
90075@@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
90076 return 1;
90077 }
90078
90079+#ifdef CONFIG_PAX_SEGMEXEC
90080+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
90081+{
90082+ struct mm_struct *mm = vma->vm_mm;
90083+ struct vm_area_struct *vma_m;
90084+ unsigned long address_m;
90085+ pte_t *ptep_m;
90086+
90087+ vma_m = pax_find_mirror_vma(vma);
90088+ if (!vma_m)
90089+ return;
90090+
90091+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90092+ address_m = address + SEGMEXEC_TASK_SIZE;
90093+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
90094+ get_page(page_m);
90095+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
90096+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
90097+}
90098+#endif
90099+
90100 /*
90101 * Hugetlb_cow() should be called with page lock of the original hugepage held.
90102 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
90103@@ -2712,6 +2737,11 @@ retry_avoidcopy:
90104 make_huge_pte(vma, new_page, 1));
90105 page_remove_rmap(old_page);
90106 hugepage_add_new_anon_rmap(new_page, vma, address);
90107+
90108+#ifdef CONFIG_PAX_SEGMEXEC
90109+ pax_mirror_huge_pte(vma, address, new_page);
90110+#endif
90111+
90112 /* Make the old page be freed below */
90113 new_page = old_page;
90114 }
90115@@ -2876,6 +2906,10 @@ retry:
90116 && (vma->vm_flags & VM_SHARED)));
90117 set_huge_pte_at(mm, address, ptep, new_pte);
90118
90119+#ifdef CONFIG_PAX_SEGMEXEC
90120+ pax_mirror_huge_pte(vma, address, page);
90121+#endif
90122+
90123 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
90124 /* Optimization, do the COW without a second fault */
90125 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
90126@@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90127 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
90128 struct hstate *h = hstate_vma(vma);
90129
90130+#ifdef CONFIG_PAX_SEGMEXEC
90131+ struct vm_area_struct *vma_m;
90132+#endif
90133+
90134 address &= huge_page_mask(h);
90135
90136 ptep = huge_pte_offset(mm, address);
90137@@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90138 VM_FAULT_SET_HINDEX(hstate_index(h));
90139 }
90140
90141+#ifdef CONFIG_PAX_SEGMEXEC
90142+ vma_m = pax_find_mirror_vma(vma);
90143+ if (vma_m) {
90144+ unsigned long address_m;
90145+
90146+ if (vma->vm_start > vma_m->vm_start) {
90147+ address_m = address;
90148+ address -= SEGMEXEC_TASK_SIZE;
90149+ vma = vma_m;
90150+ h = hstate_vma(vma);
90151+ } else
90152+ address_m = address + SEGMEXEC_TASK_SIZE;
90153+
90154+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
90155+ return VM_FAULT_OOM;
90156+ address_m &= HPAGE_MASK;
90157+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
90158+ }
90159+#endif
90160+
90161 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
90162 if (!ptep)
90163 return VM_FAULT_OOM;
90164diff --git a/mm/internal.h b/mm/internal.h
90165index 684f7aa..9eb9edc 100644
90166--- a/mm/internal.h
90167+++ b/mm/internal.h
90168@@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
90169 * in mm/page_alloc.c
90170 */
90171 extern void __free_pages_bootmem(struct page *page, unsigned int order);
90172+extern void free_compound_page(struct page *page);
90173 extern void prep_compound_page(struct page *page, unsigned long order);
90174 #ifdef CONFIG_MEMORY_FAILURE
90175 extern bool is_free_buddy_page(struct page *page);
90176@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
90177
90178 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
90179 unsigned long, unsigned long,
90180- unsigned long, unsigned long);
90181+ unsigned long, unsigned long) __intentional_overflow(-1);
90182
90183 extern void set_pageblock_order(void);
90184 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
90185diff --git a/mm/kmemleak.c b/mm/kmemleak.c
90186index 31f01c5..7015178 100644
90187--- a/mm/kmemleak.c
90188+++ b/mm/kmemleak.c
90189@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
90190
90191 for (i = 0; i < object->trace_len; i++) {
90192 void *ptr = (void *)object->trace[i];
90193- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
90194+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
90195 }
90196 }
90197
90198@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
90199 return -ENOMEM;
90200 }
90201
90202- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
90203+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
90204 &kmemleak_fops);
90205 if (!dentry)
90206 pr_warning("Failed to create the debugfs kmemleak file\n");
90207diff --git a/mm/maccess.c b/mm/maccess.c
90208index d53adf9..03a24bf 100644
90209--- a/mm/maccess.c
90210+++ b/mm/maccess.c
90211@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
90212 set_fs(KERNEL_DS);
90213 pagefault_disable();
90214 ret = __copy_from_user_inatomic(dst,
90215- (__force const void __user *)src, size);
90216+ (const void __force_user *)src, size);
90217 pagefault_enable();
90218 set_fs(old_fs);
90219
90220@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
90221
90222 set_fs(KERNEL_DS);
90223 pagefault_disable();
90224- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
90225+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
90226 pagefault_enable();
90227 set_fs(old_fs);
90228
90229diff --git a/mm/madvise.c b/mm/madvise.c
90230index 539eeb9..e24a987 100644
90231--- a/mm/madvise.c
90232+++ b/mm/madvise.c
90233@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
90234 pgoff_t pgoff;
90235 unsigned long new_flags = vma->vm_flags;
90236
90237+#ifdef CONFIG_PAX_SEGMEXEC
90238+ struct vm_area_struct *vma_m;
90239+#endif
90240+
90241 switch (behavior) {
90242 case MADV_NORMAL:
90243 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
90244@@ -126,6 +130,13 @@ success:
90245 /*
90246 * vm_flags is protected by the mmap_sem held in write mode.
90247 */
90248+
90249+#ifdef CONFIG_PAX_SEGMEXEC
90250+ vma_m = pax_find_mirror_vma(vma);
90251+ if (vma_m)
90252+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
90253+#endif
90254+
90255 vma->vm_flags = new_flags;
90256
90257 out:
90258@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90259 struct vm_area_struct **prev,
90260 unsigned long start, unsigned long end)
90261 {
90262+
90263+#ifdef CONFIG_PAX_SEGMEXEC
90264+ struct vm_area_struct *vma_m;
90265+#endif
90266+
90267 *prev = vma;
90268 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
90269 return -EINVAL;
90270@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90271 zap_page_range(vma, start, end - start, &details);
90272 } else
90273 zap_page_range(vma, start, end - start, NULL);
90274+
90275+#ifdef CONFIG_PAX_SEGMEXEC
90276+ vma_m = pax_find_mirror_vma(vma);
90277+ if (vma_m) {
90278+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
90279+ struct zap_details details = {
90280+ .nonlinear_vma = vma_m,
90281+ .last_index = ULONG_MAX,
90282+ };
90283+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
90284+ } else
90285+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
90286+ }
90287+#endif
90288+
90289 return 0;
90290 }
90291
90292@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
90293 if (end < start)
90294 return error;
90295
90296+#ifdef CONFIG_PAX_SEGMEXEC
90297+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90298+ if (end > SEGMEXEC_TASK_SIZE)
90299+ return error;
90300+ } else
90301+#endif
90302+
90303+ if (end > TASK_SIZE)
90304+ return error;
90305+
90306 error = 0;
90307 if (end == start)
90308 return error;
90309diff --git a/mm/memory-failure.c b/mm/memory-failure.c
90310index fabe550..f31b51c 100644
90311--- a/mm/memory-failure.c
90312+++ b/mm/memory-failure.c
90313@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
90314
90315 int sysctl_memory_failure_recovery __read_mostly = 1;
90316
90317-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90318+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90319
90320 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
90321
90322@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
90323 pfn, t->comm, t->pid);
90324 si.si_signo = SIGBUS;
90325 si.si_errno = 0;
90326- si.si_addr = (void *)addr;
90327+ si.si_addr = (void __user *)addr;
90328 #ifdef __ARCH_SI_TRAPNO
90329 si.si_trapno = trapno;
90330 #endif
90331@@ -762,7 +762,7 @@ static struct page_state {
90332 unsigned long res;
90333 char *msg;
90334 int (*action)(struct page *p, unsigned long pfn);
90335-} error_states[] = {
90336+} __do_const error_states[] = {
90337 { reserved, reserved, "reserved kernel", me_kernel },
90338 /*
90339 * free pages are specially detected outside this table:
90340@@ -1063,7 +1063,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90341 nr_pages = 1 << compound_order(hpage);
90342 else /* normal page or thp */
90343 nr_pages = 1;
90344- atomic_long_add(nr_pages, &num_poisoned_pages);
90345+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
90346
90347 /*
90348 * We need/can do nothing about count=0 pages.
90349@@ -1093,7 +1093,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90350 if (!PageHWPoison(hpage)
90351 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
90352 || (p != hpage && TestSetPageHWPoison(hpage))) {
90353- atomic_long_sub(nr_pages, &num_poisoned_pages);
90354+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90355 return 0;
90356 }
90357 set_page_hwpoison_huge_page(hpage);
90358@@ -1162,7 +1162,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90359 }
90360 if (hwpoison_filter(p)) {
90361 if (TestClearPageHWPoison(p))
90362- atomic_long_sub(nr_pages, &num_poisoned_pages);
90363+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90364 unlock_page(hpage);
90365 put_page(hpage);
90366 return 0;
90367@@ -1380,7 +1380,7 @@ int unpoison_memory(unsigned long pfn)
90368 return 0;
90369 }
90370 if (TestClearPageHWPoison(p))
90371- atomic_long_dec(&num_poisoned_pages);
90372+ atomic_long_dec_unchecked(&num_poisoned_pages);
90373 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
90374 return 0;
90375 }
90376@@ -1394,7 +1394,7 @@ int unpoison_memory(unsigned long pfn)
90377 */
90378 if (TestClearPageHWPoison(page)) {
90379 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
90380- atomic_long_sub(nr_pages, &num_poisoned_pages);
90381+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90382 freeit = 1;
90383 if (PageHuge(page))
90384 clear_page_hwpoison_huge_page(page);
90385@@ -1519,11 +1519,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
90386 if (PageHuge(page)) {
90387 set_page_hwpoison_huge_page(hpage);
90388 dequeue_hwpoisoned_huge_page(hpage);
90389- atomic_long_add(1 << compound_order(hpage),
90390+ atomic_long_add_unchecked(1 << compound_order(hpage),
90391 &num_poisoned_pages);
90392 } else {
90393 SetPageHWPoison(page);
90394- atomic_long_inc(&num_poisoned_pages);
90395+ atomic_long_inc_unchecked(&num_poisoned_pages);
90396 }
90397 }
90398 return ret;
90399@@ -1562,7 +1562,7 @@ static int __soft_offline_page(struct page *page, int flags)
90400 put_page(page);
90401 pr_info("soft_offline: %#lx: invalidated\n", pfn);
90402 SetPageHWPoison(page);
90403- atomic_long_inc(&num_poisoned_pages);
90404+ atomic_long_inc_unchecked(&num_poisoned_pages);
90405 return 0;
90406 }
90407
90408@@ -1607,7 +1607,7 @@ static int __soft_offline_page(struct page *page, int flags)
90409 if (!is_free_buddy_page(page))
90410 pr_info("soft offline: %#lx: page leaked\n",
90411 pfn);
90412- atomic_long_inc(&num_poisoned_pages);
90413+ atomic_long_inc_unchecked(&num_poisoned_pages);
90414 }
90415 } else {
90416 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
90417@@ -1681,11 +1681,11 @@ int soft_offline_page(struct page *page, int flags)
90418 if (PageHuge(page)) {
90419 set_page_hwpoison_huge_page(hpage);
90420 dequeue_hwpoisoned_huge_page(hpage);
90421- atomic_long_add(1 << compound_order(hpage),
90422+ atomic_long_add_unchecked(1 << compound_order(hpage),
90423 &num_poisoned_pages);
90424 } else {
90425 SetPageHWPoison(page);
90426- atomic_long_inc(&num_poisoned_pages);
90427+ atomic_long_inc_unchecked(&num_poisoned_pages);
90428 }
90429 }
90430 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
90431diff --git a/mm/memory.c b/mm/memory.c
90432index 6768ce9..4c41d69 100644
90433--- a/mm/memory.c
90434+++ b/mm/memory.c
90435@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90436 free_pte_range(tlb, pmd, addr);
90437 } while (pmd++, addr = next, addr != end);
90438
90439+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
90440 start &= PUD_MASK;
90441 if (start < floor)
90442 return;
90443@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90444 pmd = pmd_offset(pud, start);
90445 pud_clear(pud);
90446 pmd_free_tlb(tlb, pmd, start);
90447+#endif
90448+
90449 }
90450
90451 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90452@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90453 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
90454 } while (pud++, addr = next, addr != end);
90455
90456+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
90457 start &= PGDIR_MASK;
90458 if (start < floor)
90459 return;
90460@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90461 pud = pud_offset(pgd, start);
90462 pgd_clear(pgd);
90463 pud_free_tlb(tlb, pud, start);
90464+#endif
90465+
90466 }
90467
90468 /*
90469@@ -1635,12 +1641,6 @@ no_page_table:
90470 return page;
90471 }
90472
90473-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
90474-{
90475- return stack_guard_page_start(vma, addr) ||
90476- stack_guard_page_end(vma, addr+PAGE_SIZE);
90477-}
90478-
90479 /**
90480 * __get_user_pages() - pin user pages in memory
90481 * @tsk: task_struct of target task
90482@@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90483
90484 i = 0;
90485
90486- do {
90487+ while (nr_pages) {
90488 struct vm_area_struct *vma;
90489
90490- vma = find_extend_vma(mm, start);
90491+ vma = find_vma(mm, start);
90492 if (!vma && in_gate_area(mm, start)) {
90493 unsigned long pg = start & PAGE_MASK;
90494 pgd_t *pgd;
90495@@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90496 goto next_page;
90497 }
90498
90499- if (!vma ||
90500+ if (!vma || start < vma->vm_start ||
90501 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
90502 !(vm_flags & vma->vm_flags))
90503 return i ? : -EFAULT;
90504@@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90505 int ret;
90506 unsigned int fault_flags = 0;
90507
90508- /* For mlock, just skip the stack guard page. */
90509- if (foll_flags & FOLL_MLOCK) {
90510- if (stack_guard_page(vma, start))
90511- goto next_page;
90512- }
90513 if (foll_flags & FOLL_WRITE)
90514 fault_flags |= FAULT_FLAG_WRITE;
90515 if (nonblocking)
90516@@ -1892,7 +1887,7 @@ next_page:
90517 start += page_increm * PAGE_SIZE;
90518 nr_pages -= page_increm;
90519 } while (nr_pages && start < vma->vm_end);
90520- } while (nr_pages);
90521+ }
90522 return i;
90523 }
90524 EXPORT_SYMBOL(__get_user_pages);
90525@@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
90526 page_add_file_rmap(page);
90527 set_pte_at(mm, addr, pte, mk_pte(page, prot));
90528
90529+#ifdef CONFIG_PAX_SEGMEXEC
90530+ pax_mirror_file_pte(vma, addr, page, ptl);
90531+#endif
90532+
90533 retval = 0;
90534 pte_unmap_unlock(pte, ptl);
90535 return retval;
90536@@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
90537 if (!page_count(page))
90538 return -EINVAL;
90539 if (!(vma->vm_flags & VM_MIXEDMAP)) {
90540+
90541+#ifdef CONFIG_PAX_SEGMEXEC
90542+ struct vm_area_struct *vma_m;
90543+#endif
90544+
90545 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
90546 BUG_ON(vma->vm_flags & VM_PFNMAP);
90547 vma->vm_flags |= VM_MIXEDMAP;
90548+
90549+#ifdef CONFIG_PAX_SEGMEXEC
90550+ vma_m = pax_find_mirror_vma(vma);
90551+ if (vma_m)
90552+ vma_m->vm_flags |= VM_MIXEDMAP;
90553+#endif
90554+
90555 }
90556 return insert_page(vma, addr, page, vma->vm_page_prot);
90557 }
90558@@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
90559 unsigned long pfn)
90560 {
90561 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
90562+ BUG_ON(vma->vm_mirror);
90563
90564 if (addr < vma->vm_start || addr >= vma->vm_end)
90565 return -EFAULT;
90566@@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
90567
90568 BUG_ON(pud_huge(*pud));
90569
90570- pmd = pmd_alloc(mm, pud, addr);
90571+ pmd = (mm == &init_mm) ?
90572+ pmd_alloc_kernel(mm, pud, addr) :
90573+ pmd_alloc(mm, pud, addr);
90574 if (!pmd)
90575 return -ENOMEM;
90576 do {
90577@@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
90578 unsigned long next;
90579 int err;
90580
90581- pud = pud_alloc(mm, pgd, addr);
90582+ pud = (mm == &init_mm) ?
90583+ pud_alloc_kernel(mm, pgd, addr) :
90584+ pud_alloc(mm, pgd, addr);
90585 if (!pud)
90586 return -ENOMEM;
90587 do {
90588@@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
90589 copy_user_highpage(dst, src, va, vma);
90590 }
90591
90592+#ifdef CONFIG_PAX_SEGMEXEC
90593+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
90594+{
90595+ struct mm_struct *mm = vma->vm_mm;
90596+ spinlock_t *ptl;
90597+ pte_t *pte, entry;
90598+
90599+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
90600+ entry = *pte;
90601+ if (!pte_present(entry)) {
90602+ if (!pte_none(entry)) {
90603+ BUG_ON(pte_file(entry));
90604+ free_swap_and_cache(pte_to_swp_entry(entry));
90605+ pte_clear_not_present_full(mm, address, pte, 0);
90606+ }
90607+ } else {
90608+ struct page *page;
90609+
90610+ flush_cache_page(vma, address, pte_pfn(entry));
90611+ entry = ptep_clear_flush(vma, address, pte);
90612+ BUG_ON(pte_dirty(entry));
90613+ page = vm_normal_page(vma, address, entry);
90614+ if (page) {
90615+ update_hiwater_rss(mm);
90616+ if (PageAnon(page))
90617+ dec_mm_counter_fast(mm, MM_ANONPAGES);
90618+ else
90619+ dec_mm_counter_fast(mm, MM_FILEPAGES);
90620+ page_remove_rmap(page);
90621+ page_cache_release(page);
90622+ }
90623+ }
90624+ pte_unmap_unlock(pte, ptl);
90625+}
90626+
90627+/* PaX: if vma is mirrored, synchronize the mirror's PTE
90628+ *
90629+ * the ptl of the lower mapped page is held on entry and is not released on exit
90630+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
90631+ */
90632+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90633+{
90634+ struct mm_struct *mm = vma->vm_mm;
90635+ unsigned long address_m;
90636+ spinlock_t *ptl_m;
90637+ struct vm_area_struct *vma_m;
90638+ pmd_t *pmd_m;
90639+ pte_t *pte_m, entry_m;
90640+
90641+ BUG_ON(!page_m || !PageAnon(page_m));
90642+
90643+ vma_m = pax_find_mirror_vma(vma);
90644+ if (!vma_m)
90645+ return;
90646+
90647+ BUG_ON(!PageLocked(page_m));
90648+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90649+ address_m = address + SEGMEXEC_TASK_SIZE;
90650+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90651+ pte_m = pte_offset_map(pmd_m, address_m);
90652+ ptl_m = pte_lockptr(mm, pmd_m);
90653+ if (ptl != ptl_m) {
90654+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90655+ if (!pte_none(*pte_m))
90656+ goto out;
90657+ }
90658+
90659+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90660+ page_cache_get(page_m);
90661+ page_add_anon_rmap(page_m, vma_m, address_m);
90662+ inc_mm_counter_fast(mm, MM_ANONPAGES);
90663+ set_pte_at(mm, address_m, pte_m, entry_m);
90664+ update_mmu_cache(vma_m, address_m, pte_m);
90665+out:
90666+ if (ptl != ptl_m)
90667+ spin_unlock(ptl_m);
90668+ pte_unmap(pte_m);
90669+ unlock_page(page_m);
90670+}
90671+
90672+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90673+{
90674+ struct mm_struct *mm = vma->vm_mm;
90675+ unsigned long address_m;
90676+ spinlock_t *ptl_m;
90677+ struct vm_area_struct *vma_m;
90678+ pmd_t *pmd_m;
90679+ pte_t *pte_m, entry_m;
90680+
90681+ BUG_ON(!page_m || PageAnon(page_m));
90682+
90683+ vma_m = pax_find_mirror_vma(vma);
90684+ if (!vma_m)
90685+ return;
90686+
90687+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90688+ address_m = address + SEGMEXEC_TASK_SIZE;
90689+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90690+ pte_m = pte_offset_map(pmd_m, address_m);
90691+ ptl_m = pte_lockptr(mm, pmd_m);
90692+ if (ptl != ptl_m) {
90693+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90694+ if (!pte_none(*pte_m))
90695+ goto out;
90696+ }
90697+
90698+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90699+ page_cache_get(page_m);
90700+ page_add_file_rmap(page_m);
90701+ inc_mm_counter_fast(mm, MM_FILEPAGES);
90702+ set_pte_at(mm, address_m, pte_m, entry_m);
90703+ update_mmu_cache(vma_m, address_m, pte_m);
90704+out:
90705+ if (ptl != ptl_m)
90706+ spin_unlock(ptl_m);
90707+ pte_unmap(pte_m);
90708+}
90709+
90710+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
90711+{
90712+ struct mm_struct *mm = vma->vm_mm;
90713+ unsigned long address_m;
90714+ spinlock_t *ptl_m;
90715+ struct vm_area_struct *vma_m;
90716+ pmd_t *pmd_m;
90717+ pte_t *pte_m, entry_m;
90718+
90719+ vma_m = pax_find_mirror_vma(vma);
90720+ if (!vma_m)
90721+ return;
90722+
90723+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90724+ address_m = address + SEGMEXEC_TASK_SIZE;
90725+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90726+ pte_m = pte_offset_map(pmd_m, address_m);
90727+ ptl_m = pte_lockptr(mm, pmd_m);
90728+ if (ptl != ptl_m) {
90729+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90730+ if (!pte_none(*pte_m))
90731+ goto out;
90732+ }
90733+
90734+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
90735+ set_pte_at(mm, address_m, pte_m, entry_m);
90736+out:
90737+ if (ptl != ptl_m)
90738+ spin_unlock(ptl_m);
90739+ pte_unmap(pte_m);
90740+}
90741+
90742+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
90743+{
90744+ struct page *page_m;
90745+ pte_t entry;
90746+
90747+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
90748+ goto out;
90749+
90750+ entry = *pte;
90751+ page_m = vm_normal_page(vma, address, entry);
90752+ if (!page_m)
90753+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
90754+ else if (PageAnon(page_m)) {
90755+ if (pax_find_mirror_vma(vma)) {
90756+ pte_unmap_unlock(pte, ptl);
90757+ lock_page(page_m);
90758+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
90759+ if (pte_same(entry, *pte))
90760+ pax_mirror_anon_pte(vma, address, page_m, ptl);
90761+ else
90762+ unlock_page(page_m);
90763+ }
90764+ } else
90765+ pax_mirror_file_pte(vma, address, page_m, ptl);
90766+
90767+out:
90768+ pte_unmap_unlock(pte, ptl);
90769+}
90770+#endif
90771+
90772 /*
90773 * This routine handles present pages, when users try to write
90774 * to a shared page. It is done by copying the page to a new address
90775@@ -2807,6 +3003,12 @@ gotten:
90776 */
90777 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
90778 if (likely(pte_same(*page_table, orig_pte))) {
90779+
90780+#ifdef CONFIG_PAX_SEGMEXEC
90781+ if (pax_find_mirror_vma(vma))
90782+ BUG_ON(!trylock_page(new_page));
90783+#endif
90784+
90785 if (old_page) {
90786 if (!PageAnon(old_page)) {
90787 dec_mm_counter_fast(mm, MM_FILEPAGES);
90788@@ -2858,6 +3060,10 @@ gotten:
90789 page_remove_rmap(old_page);
90790 }
90791
90792+#ifdef CONFIG_PAX_SEGMEXEC
90793+ pax_mirror_anon_pte(vma, address, new_page, ptl);
90794+#endif
90795+
90796 /* Free the old page.. */
90797 new_page = old_page;
90798 ret |= VM_FAULT_WRITE;
90799@@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
90800 swap_free(entry);
90801 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
90802 try_to_free_swap(page);
90803+
90804+#ifdef CONFIG_PAX_SEGMEXEC
90805+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
90806+#endif
90807+
90808 unlock_page(page);
90809 if (page != swapcache) {
90810 /*
90811@@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
90812
90813 /* No need to invalidate - it was non-present before */
90814 update_mmu_cache(vma, address, page_table);
90815+
90816+#ifdef CONFIG_PAX_SEGMEXEC
90817+ pax_mirror_anon_pte(vma, address, page, ptl);
90818+#endif
90819+
90820 unlock:
90821 pte_unmap_unlock(page_table, ptl);
90822 out:
90823@@ -3177,40 +3393,6 @@ out_release:
90824 }
90825
90826 /*
90827- * This is like a special single-page "expand_{down|up}wards()",
90828- * except we must first make sure that 'address{-|+}PAGE_SIZE'
90829- * doesn't hit another vma.
90830- */
90831-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
90832-{
90833- address &= PAGE_MASK;
90834- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
90835- struct vm_area_struct *prev = vma->vm_prev;
90836-
90837- /*
90838- * Is there a mapping abutting this one below?
90839- *
90840- * That's only ok if it's the same stack mapping
90841- * that has gotten split..
90842- */
90843- if (prev && prev->vm_end == address)
90844- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
90845-
90846- expand_downwards(vma, address - PAGE_SIZE);
90847- }
90848- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
90849- struct vm_area_struct *next = vma->vm_next;
90850-
90851- /* As VM_GROWSDOWN but s/below/above/ */
90852- if (next && next->vm_start == address + PAGE_SIZE)
90853- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
90854-
90855- expand_upwards(vma, address + PAGE_SIZE);
90856- }
90857- return 0;
90858-}
90859-
90860-/*
90861 * We enter with non-exclusive mmap_sem (to exclude vma changes,
90862 * but allow concurrent faults), and pte mapped but not yet locked.
90863 * We return with mmap_sem still held, but pte unmapped and unlocked.
90864@@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
90865 unsigned long address, pte_t *page_table, pmd_t *pmd,
90866 unsigned int flags)
90867 {
90868- struct page *page;
90869+ struct page *page = NULL;
90870 spinlock_t *ptl;
90871 pte_t entry;
90872
90873- pte_unmap(page_table);
90874-
90875- /* Check if we need to add a guard page to the stack */
90876- if (check_stack_guard_page(vma, address) < 0)
90877- return VM_FAULT_SIGBUS;
90878-
90879- /* Use the zero-page for reads */
90880 if (!(flags & FAULT_FLAG_WRITE)) {
90881 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
90882 vma->vm_page_prot));
90883- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
90884+ ptl = pte_lockptr(mm, pmd);
90885+ spin_lock(ptl);
90886 if (!pte_none(*page_table))
90887 goto unlock;
90888 goto setpte;
90889 }
90890
90891 /* Allocate our own private page. */
90892+ pte_unmap(page_table);
90893+
90894 if (unlikely(anon_vma_prepare(vma)))
90895 goto oom;
90896 page = alloc_zeroed_user_highpage_movable(vma, address);
90897@@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
90898 if (!pte_none(*page_table))
90899 goto release;
90900
90901+#ifdef CONFIG_PAX_SEGMEXEC
90902+ if (pax_find_mirror_vma(vma))
90903+ BUG_ON(!trylock_page(page));
90904+#endif
90905+
90906 inc_mm_counter_fast(mm, MM_ANONPAGES);
90907 page_add_new_anon_rmap(page, vma, address);
90908 setpte:
90909@@ -3270,6 +3453,12 @@ setpte:
90910
90911 /* No need to invalidate - it was non-present before */
90912 update_mmu_cache(vma, address, page_table);
90913+
90914+#ifdef CONFIG_PAX_SEGMEXEC
90915+ if (page)
90916+ pax_mirror_anon_pte(vma, address, page, ptl);
90917+#endif
90918+
90919 unlock:
90920 pte_unmap_unlock(page_table, ptl);
90921 return 0;
90922@@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90923 */
90924 /* Only go through if we didn't race with anybody else... */
90925 if (likely(pte_same(*page_table, orig_pte))) {
90926+
90927+#ifdef CONFIG_PAX_SEGMEXEC
90928+ if (anon && pax_find_mirror_vma(vma))
90929+ BUG_ON(!trylock_page(page));
90930+#endif
90931+
90932 flush_icache_page(vma, page);
90933 entry = mk_pte(page, vma->vm_page_prot);
90934 if (flags & FAULT_FLAG_WRITE)
90935@@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90936
90937 /* no need to invalidate: a not-present page won't be cached */
90938 update_mmu_cache(vma, address, page_table);
90939+
90940+#ifdef CONFIG_PAX_SEGMEXEC
90941+ if (anon)
90942+ pax_mirror_anon_pte(vma, address, page, ptl);
90943+ else
90944+ pax_mirror_file_pte(vma, address, page, ptl);
90945+#endif
90946+
90947 } else {
90948 if (cow_page)
90949 mem_cgroup_uncharge_page(cow_page);
90950@@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
90951 if (flags & FAULT_FLAG_WRITE)
90952 flush_tlb_fix_spurious_fault(vma, address);
90953 }
90954+
90955+#ifdef CONFIG_PAX_SEGMEXEC
90956+ pax_mirror_pte(vma, address, pte, pmd, ptl);
90957+ return 0;
90958+#endif
90959+
90960 unlock:
90961 pte_unmap_unlock(pte, ptl);
90962 return 0;
90963@@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90964 pmd_t *pmd;
90965 pte_t *pte;
90966
90967+#ifdef CONFIG_PAX_SEGMEXEC
90968+ struct vm_area_struct *vma_m;
90969+#endif
90970+
90971 if (unlikely(is_vm_hugetlb_page(vma)))
90972 return hugetlb_fault(mm, vma, address, flags);
90973
90974+#ifdef CONFIG_PAX_SEGMEXEC
90975+ vma_m = pax_find_mirror_vma(vma);
90976+ if (vma_m) {
90977+ unsigned long address_m;
90978+ pgd_t *pgd_m;
90979+ pud_t *pud_m;
90980+ pmd_t *pmd_m;
90981+
90982+ if (vma->vm_start > vma_m->vm_start) {
90983+ address_m = address;
90984+ address -= SEGMEXEC_TASK_SIZE;
90985+ vma = vma_m;
90986+ } else
90987+ address_m = address + SEGMEXEC_TASK_SIZE;
90988+
90989+ pgd_m = pgd_offset(mm, address_m);
90990+ pud_m = pud_alloc(mm, pgd_m, address_m);
90991+ if (!pud_m)
90992+ return VM_FAULT_OOM;
90993+ pmd_m = pmd_alloc(mm, pud_m, address_m);
90994+ if (!pmd_m)
90995+ return VM_FAULT_OOM;
90996+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
90997+ return VM_FAULT_OOM;
90998+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
90999+ }
91000+#endif
91001+
91002 retry:
91003 pgd = pgd_offset(mm, address);
91004 pud = pud_alloc(mm, pgd, address);
91005@@ -3838,6 +4079,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91006 spin_unlock(&mm->page_table_lock);
91007 return 0;
91008 }
91009+
91010+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91011+{
91012+ pud_t *new = pud_alloc_one(mm, address);
91013+ if (!new)
91014+ return -ENOMEM;
91015+
91016+ smp_wmb(); /* See comment in __pte_alloc */
91017+
91018+ spin_lock(&mm->page_table_lock);
91019+ if (pgd_present(*pgd)) /* Another has populated it */
91020+ pud_free(mm, new);
91021+ else
91022+ pgd_populate_kernel(mm, pgd, new);
91023+ spin_unlock(&mm->page_table_lock);
91024+ return 0;
91025+}
91026 #endif /* __PAGETABLE_PUD_FOLDED */
91027
91028 #ifndef __PAGETABLE_PMD_FOLDED
91029@@ -3868,6 +4126,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
91030 spin_unlock(&mm->page_table_lock);
91031 return 0;
91032 }
91033+
91034+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
91035+{
91036+ pmd_t *new = pmd_alloc_one(mm, address);
91037+ if (!new)
91038+ return -ENOMEM;
91039+
91040+ smp_wmb(); /* See comment in __pte_alloc */
91041+
91042+ spin_lock(&mm->page_table_lock);
91043+#ifndef __ARCH_HAS_4LEVEL_HACK
91044+ if (pud_present(*pud)) /* Another has populated it */
91045+ pmd_free(mm, new);
91046+ else
91047+ pud_populate_kernel(mm, pud, new);
91048+#else
91049+ if (pgd_present(*pud)) /* Another has populated it */
91050+ pmd_free(mm, new);
91051+ else
91052+ pgd_populate_kernel(mm, pud, new);
91053+#endif /* __ARCH_HAS_4LEVEL_HACK */
91054+ spin_unlock(&mm->page_table_lock);
91055+ return 0;
91056+}
91057 #endif /* __PAGETABLE_PMD_FOLDED */
91058
91059 #if !defined(__HAVE_ARCH_GATE_AREA)
91060@@ -3881,7 +4163,7 @@ static int __init gate_vma_init(void)
91061 gate_vma.vm_start = FIXADDR_USER_START;
91062 gate_vma.vm_end = FIXADDR_USER_END;
91063 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
91064- gate_vma.vm_page_prot = __P101;
91065+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
91066
91067 return 0;
91068 }
91069@@ -4015,8 +4297,8 @@ out:
91070 return ret;
91071 }
91072
91073-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91074- void *buf, int len, int write)
91075+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91076+ void *buf, size_t len, int write)
91077 {
91078 resource_size_t phys_addr;
91079 unsigned long prot = 0;
91080@@ -4042,8 +4324,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
91081 * Access another process' address space as given in mm. If non-NULL, use the
91082 * given task for page fault accounting.
91083 */
91084-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91085- unsigned long addr, void *buf, int len, int write)
91086+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91087+ unsigned long addr, void *buf, size_t len, int write)
91088 {
91089 struct vm_area_struct *vma;
91090 void *old_buf = buf;
91091@@ -4051,7 +4333,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91092 down_read(&mm->mmap_sem);
91093 /* ignore errors, just check how much was successfully transferred */
91094 while (len) {
91095- int bytes, ret, offset;
91096+ ssize_t bytes, ret, offset;
91097 void *maddr;
91098 struct page *page = NULL;
91099
91100@@ -4110,8 +4392,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91101 *
91102 * The caller must hold a reference on @mm.
91103 */
91104-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91105- void *buf, int len, int write)
91106+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
91107+ void *buf, size_t len, int write)
91108 {
91109 return __access_remote_vm(NULL, mm, addr, buf, len, write);
91110 }
91111@@ -4121,11 +4403,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91112 * Source/target buffer must be kernel space,
91113 * Do not walk the page table directly, use get_user_pages
91114 */
91115-int access_process_vm(struct task_struct *tsk, unsigned long addr,
91116- void *buf, int len, int write)
91117+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
91118+ void *buf, size_t len, int write)
91119 {
91120 struct mm_struct *mm;
91121- int ret;
91122+ ssize_t ret;
91123
91124 mm = get_task_mm(tsk);
91125 if (!mm)
91126diff --git a/mm/mempolicy.c b/mm/mempolicy.c
91127index 0cd2c4d..9558c83 100644
91128--- a/mm/mempolicy.c
91129+++ b/mm/mempolicy.c
91130@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91131 unsigned long vmstart;
91132 unsigned long vmend;
91133
91134+#ifdef CONFIG_PAX_SEGMEXEC
91135+ struct vm_area_struct *vma_m;
91136+#endif
91137+
91138 vma = find_vma(mm, start);
91139 if (!vma || vma->vm_start > start)
91140 return -EFAULT;
91141@@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91142 err = vma_replace_policy(vma, new_pol);
91143 if (err)
91144 goto out;
91145+
91146+#ifdef CONFIG_PAX_SEGMEXEC
91147+ vma_m = pax_find_mirror_vma(vma);
91148+ if (vma_m) {
91149+ err = vma_replace_policy(vma_m, new_pol);
91150+ if (err)
91151+ goto out;
91152+ }
91153+#endif
91154+
91155 }
91156
91157 out:
91158@@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
91159
91160 if (end < start)
91161 return -EINVAL;
91162+
91163+#ifdef CONFIG_PAX_SEGMEXEC
91164+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
91165+ if (end > SEGMEXEC_TASK_SIZE)
91166+ return -EINVAL;
91167+ } else
91168+#endif
91169+
91170+ if (end > TASK_SIZE)
91171+ return -EINVAL;
91172+
91173 if (end == start)
91174 return 0;
91175
91176@@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91177 */
91178 tcred = __task_cred(task);
91179 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91180- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91181- !capable(CAP_SYS_NICE)) {
91182+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91183 rcu_read_unlock();
91184 err = -EPERM;
91185 goto out_put;
91186@@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91187 goto out;
91188 }
91189
91190+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
91191+ if (mm != current->mm &&
91192+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
91193+ mmput(mm);
91194+ err = -EPERM;
91195+ goto out;
91196+ }
91197+#endif
91198+
91199 err = do_migrate_pages(mm, old, new,
91200 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
91201
91202diff --git a/mm/migrate.c b/mm/migrate.c
91203index 9194375..75c81e2 100644
91204--- a/mm/migrate.c
91205+++ b/mm/migrate.c
91206@@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
91207 */
91208 tcred = __task_cred(task);
91209 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91210- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91211- !capable(CAP_SYS_NICE)) {
91212+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91213 rcu_read_unlock();
91214 err = -EPERM;
91215 goto out;
91216diff --git a/mm/mlock.c b/mm/mlock.c
91217index 192e6ee..b044449 100644
91218--- a/mm/mlock.c
91219+++ b/mm/mlock.c
91220@@ -14,6 +14,7 @@
91221 #include <linux/pagevec.h>
91222 #include <linux/mempolicy.h>
91223 #include <linux/syscalls.h>
91224+#include <linux/security.h>
91225 #include <linux/sched.h>
91226 #include <linux/export.h>
91227 #include <linux/rmap.h>
91228@@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
91229 {
91230 unsigned long nstart, end, tmp;
91231 struct vm_area_struct * vma, * prev;
91232- int error;
91233+ int error = 0;
91234
91235 VM_BUG_ON(start & ~PAGE_MASK);
91236 VM_BUG_ON(len != PAGE_ALIGN(len));
91237@@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
91238 return -EINVAL;
91239 if (end == start)
91240 return 0;
91241+ if (end > TASK_SIZE)
91242+ return -EINVAL;
91243+
91244 vma = find_vma(current->mm, start);
91245 if (!vma || vma->vm_start > start)
91246 return -ENOMEM;
91247@@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
91248 for (nstart = start ; ; ) {
91249 vm_flags_t newflags;
91250
91251+#ifdef CONFIG_PAX_SEGMEXEC
91252+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91253+ break;
91254+#endif
91255+
91256 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
91257
91258 newflags = vma->vm_flags & ~VM_LOCKED;
91259@@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
91260 lock_limit >>= PAGE_SHIFT;
91261
91262 /* check against resource limits */
91263+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
91264 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
91265 error = do_mlock(start, len, 1);
91266 up_write(&current->mm->mmap_sem);
91267@@ -754,6 +764,11 @@ static int do_mlockall(int flags)
91268 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
91269 vm_flags_t newflags;
91270
91271+#ifdef CONFIG_PAX_SEGMEXEC
91272+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91273+ break;
91274+#endif
91275+
91276 newflags = vma->vm_flags & ~VM_LOCKED;
91277 if (flags & MCL_CURRENT)
91278 newflags |= VM_LOCKED;
91279@@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
91280 lock_limit >>= PAGE_SHIFT;
91281
91282 ret = -ENOMEM;
91283+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
91284 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
91285 capable(CAP_IPC_LOCK))
91286 ret = do_mlockall(flags);
91287diff --git a/mm/mmap.c b/mm/mmap.c
91288index 834b2d7..650d1b9 100644
91289--- a/mm/mmap.c
91290+++ b/mm/mmap.c
91291@@ -36,6 +36,7 @@
91292 #include <linux/sched/sysctl.h>
91293 #include <linux/notifier.h>
91294 #include <linux/memory.h>
91295+#include <linux/random.h>
91296
91297 #include <asm/uaccess.h>
91298 #include <asm/cacheflush.h>
91299@@ -52,6 +53,16 @@
91300 #define arch_rebalance_pgtables(addr, len) (addr)
91301 #endif
91302
91303+static inline void verify_mm_writelocked(struct mm_struct *mm)
91304+{
91305+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
91306+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
91307+ up_read(&mm->mmap_sem);
91308+ BUG();
91309+ }
91310+#endif
91311+}
91312+
91313 static void unmap_region(struct mm_struct *mm,
91314 struct vm_area_struct *vma, struct vm_area_struct *prev,
91315 unsigned long start, unsigned long end);
91316@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
91317 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
91318 *
91319 */
91320-pgprot_t protection_map[16] = {
91321+pgprot_t protection_map[16] __read_only = {
91322 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
91323 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
91324 };
91325
91326-pgprot_t vm_get_page_prot(unsigned long vm_flags)
91327+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
91328 {
91329- return __pgprot(pgprot_val(protection_map[vm_flags &
91330+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
91331 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
91332 pgprot_val(arch_vm_get_page_prot(vm_flags)));
91333+
91334+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91335+ if (!(__supported_pte_mask & _PAGE_NX) &&
91336+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
91337+ (vm_flags & (VM_READ | VM_WRITE)))
91338+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
91339+#endif
91340+
91341+ return prot;
91342 }
91343 EXPORT_SYMBOL(vm_get_page_prot);
91344
91345@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
91346 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
91347 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91348 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
91349+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
91350 /*
91351 * Make sure vm_committed_as in one cacheline and not cacheline shared with
91352 * other variables. It can be updated by several CPUs frequently.
91353@@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
91354 struct vm_area_struct *next = vma->vm_next;
91355
91356 might_sleep();
91357+ BUG_ON(vma->vm_mirror);
91358 if (vma->vm_ops && vma->vm_ops->close)
91359 vma->vm_ops->close(vma);
91360 if (vma->vm_file)
91361@@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
91362 * not page aligned -Ram Gupta
91363 */
91364 rlim = rlimit(RLIMIT_DATA);
91365+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
91366 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
91367 (mm->end_data - mm->start_data) > rlim)
91368 goto out;
91369@@ -893,7 +916,15 @@ again: remove_next = 1 + (end > next->vm_end);
91370 static inline int is_mergeable_vma(struct vm_area_struct *vma,
91371 struct file *file, unsigned long vm_flags)
91372 {
91373- if (vma->vm_flags ^ vm_flags)
91374+ /*
91375+ * VM_SOFTDIRTY should not prevent from VMA merging, if we
91376+ * match the flags but dirty bit -- the caller should mark
91377+ * merged VMA as dirty. If dirty bit won't be excluded from
91378+ * comparison, we increase pressue on the memory system forcing
91379+ * the kernel to generate new VMAs when old one could be
91380+ * extended instead.
91381+ */
91382+ if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY)
91383 return 0;
91384 if (vma->vm_file != file)
91385 return 0;
91386@@ -931,6 +962,12 @@ static int
91387 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
91388 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91389 {
91390+
91391+#ifdef CONFIG_PAX_SEGMEXEC
91392+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
91393+ return 0;
91394+#endif
91395+
91396 if (is_mergeable_vma(vma, file, vm_flags) &&
91397 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91398 if (vma->vm_pgoff == vm_pgoff)
91399@@ -950,6 +987,12 @@ static int
91400 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91401 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91402 {
91403+
91404+#ifdef CONFIG_PAX_SEGMEXEC
91405+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
91406+ return 0;
91407+#endif
91408+
91409 if (is_mergeable_vma(vma, file, vm_flags) &&
91410 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91411 pgoff_t vm_pglen;
91412@@ -992,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91413 struct vm_area_struct *vma_merge(struct mm_struct *mm,
91414 struct vm_area_struct *prev, unsigned long addr,
91415 unsigned long end, unsigned long vm_flags,
91416- struct anon_vma *anon_vma, struct file *file,
91417+ struct anon_vma *anon_vma, struct file *file,
91418 pgoff_t pgoff, struct mempolicy *policy)
91419 {
91420 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
91421 struct vm_area_struct *area, *next;
91422 int err;
91423
91424+#ifdef CONFIG_PAX_SEGMEXEC
91425+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
91426+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
91427+
91428+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
91429+#endif
91430+
91431 /*
91432 * We later require that vma->vm_flags == vm_flags,
91433 * so this tests vma->vm_flags & VM_SPECIAL, too.
91434@@ -1014,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91435 if (next && next->vm_end == end) /* cases 6, 7, 8 */
91436 next = next->vm_next;
91437
91438+#ifdef CONFIG_PAX_SEGMEXEC
91439+ if (prev)
91440+ prev_m = pax_find_mirror_vma(prev);
91441+ if (area)
91442+ area_m = pax_find_mirror_vma(area);
91443+ if (next)
91444+ next_m = pax_find_mirror_vma(next);
91445+#endif
91446+
91447 /*
91448 * Can it merge with the predecessor?
91449 */
91450@@ -1033,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91451 /* cases 1, 6 */
91452 err = vma_adjust(prev, prev->vm_start,
91453 next->vm_end, prev->vm_pgoff, NULL);
91454- } else /* cases 2, 5, 7 */
91455+
91456+#ifdef CONFIG_PAX_SEGMEXEC
91457+ if (!err && prev_m)
91458+ err = vma_adjust(prev_m, prev_m->vm_start,
91459+ next_m->vm_end, prev_m->vm_pgoff, NULL);
91460+#endif
91461+
91462+ } else { /* cases 2, 5, 7 */
91463 err = vma_adjust(prev, prev->vm_start,
91464 end, prev->vm_pgoff, NULL);
91465+
91466+#ifdef CONFIG_PAX_SEGMEXEC
91467+ if (!err && prev_m)
91468+ err = vma_adjust(prev_m, prev_m->vm_start,
91469+ end_m, prev_m->vm_pgoff, NULL);
91470+#endif
91471+
91472+ }
91473 if (err)
91474 return NULL;
91475 khugepaged_enter_vma_merge(prev);
91476@@ -1049,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91477 mpol_equal(policy, vma_policy(next)) &&
91478 can_vma_merge_before(next, vm_flags,
91479 anon_vma, file, pgoff+pglen)) {
91480- if (prev && addr < prev->vm_end) /* case 4 */
91481+ if (prev && addr < prev->vm_end) { /* case 4 */
91482 err = vma_adjust(prev, prev->vm_start,
91483 addr, prev->vm_pgoff, NULL);
91484- else /* cases 3, 8 */
91485+
91486+#ifdef CONFIG_PAX_SEGMEXEC
91487+ if (!err && prev_m)
91488+ err = vma_adjust(prev_m, prev_m->vm_start,
91489+ addr_m, prev_m->vm_pgoff, NULL);
91490+#endif
91491+
91492+ } else { /* cases 3, 8 */
91493 err = vma_adjust(area, addr, next->vm_end,
91494 next->vm_pgoff - pglen, NULL);
91495+
91496+#ifdef CONFIG_PAX_SEGMEXEC
91497+ if (!err && area_m)
91498+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
91499+ next_m->vm_pgoff - pglen, NULL);
91500+#endif
91501+
91502+ }
91503 if (err)
91504 return NULL;
91505 khugepaged_enter_vma_merge(area);
91506@@ -1082,7 +1171,7 @@ static int anon_vma_compatible(struct vm_area_struct *a, struct vm_area_struct *
91507 return a->vm_end == b->vm_start &&
91508 mpol_equal(vma_policy(a), vma_policy(b)) &&
91509 a->vm_file == b->vm_file &&
91510- !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC)) &&
91511+ !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC|VM_SOFTDIRTY)) &&
91512 b->vm_pgoff == a->vm_pgoff + ((b->vm_start - a->vm_start) >> PAGE_SHIFT);
91513 }
91514
91515@@ -1163,8 +1252,10 @@ none:
91516 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91517 struct file *file, long pages)
91518 {
91519- const unsigned long stack_flags
91520- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
91521+
91522+#ifdef CONFIG_PAX_RANDMMAP
91523+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91524+#endif
91525
91526 mm->total_vm += pages;
91527
91528@@ -1172,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91529 mm->shared_vm += pages;
91530 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
91531 mm->exec_vm += pages;
91532- } else if (flags & stack_flags)
91533+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
91534 mm->stack_vm += pages;
91535 }
91536 #endif /* CONFIG_PROC_FS */
91537@@ -1210,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91538 * (the exception is when the underlying filesystem is noexec
91539 * mounted, in which case we dont add PROT_EXEC.)
91540 */
91541- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
91542+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
91543 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
91544 prot |= PROT_EXEC;
91545
91546@@ -1236,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91547 /* Obtain the address to map to. we verify (or select) it and ensure
91548 * that it represents a valid section of the address space.
91549 */
91550- addr = get_unmapped_area(file, addr, len, pgoff, flags);
91551+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
91552 if (addr & ~PAGE_MASK)
91553 return addr;
91554
91555@@ -1247,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91556 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
91557 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
91558
91559+#ifdef CONFIG_PAX_MPROTECT
91560+ if (mm->pax_flags & MF_PAX_MPROTECT) {
91561+
91562+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
91563+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
91564+ mm->binfmt->handle_mmap)
91565+ mm->binfmt->handle_mmap(file);
91566+#endif
91567+
91568+#ifndef CONFIG_PAX_MPROTECT_COMPAT
91569+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
91570+ gr_log_rwxmmap(file);
91571+
91572+#ifdef CONFIG_PAX_EMUPLT
91573+ vm_flags &= ~VM_EXEC;
91574+#else
91575+ return -EPERM;
91576+#endif
91577+
91578+ }
91579+
91580+ if (!(vm_flags & VM_EXEC))
91581+ vm_flags &= ~VM_MAYEXEC;
91582+#else
91583+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
91584+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
91585+#endif
91586+ else
91587+ vm_flags &= ~VM_MAYWRITE;
91588+ }
91589+#endif
91590+
91591+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91592+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
91593+ vm_flags &= ~VM_PAGEEXEC;
91594+#endif
91595+
91596 if (flags & MAP_LOCKED)
91597 if (!can_do_mlock())
91598 return -EPERM;
91599@@ -1258,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91600 locked += mm->locked_vm;
91601 lock_limit = rlimit(RLIMIT_MEMLOCK);
91602 lock_limit >>= PAGE_SHIFT;
91603+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
91604 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
91605 return -EAGAIN;
91606 }
91607@@ -1342,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91608 vm_flags |= VM_NORESERVE;
91609 }
91610
91611+ if (!gr_acl_handle_mmap(file, prot))
91612+ return -EACCES;
91613+
91614 addr = mmap_region(file, addr, len, vm_flags, pgoff);
91615 if (!IS_ERR_VALUE(addr) &&
91616 ((vm_flags & VM_LOCKED) ||
91617@@ -1435,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
91618 vm_flags_t vm_flags = vma->vm_flags;
91619
91620 /* If it was private or non-writable, the write bit is already clear */
91621- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
91622+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
91623 return 0;
91624
91625 /* The backer wishes to know when pages are first written to? */
91626@@ -1481,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91627 struct rb_node **rb_link, *rb_parent;
91628 unsigned long charged = 0;
91629
91630+#ifdef CONFIG_PAX_SEGMEXEC
91631+ struct vm_area_struct *vma_m = NULL;
91632+#endif
91633+
91634+ /*
91635+ * mm->mmap_sem is required to protect against another thread
91636+ * changing the mappings in case we sleep.
91637+ */
91638+ verify_mm_writelocked(mm);
91639+
91640 /* Check against address space limit. */
91641+
91642+#ifdef CONFIG_PAX_RANDMMAP
91643+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91644+#endif
91645+
91646 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
91647 unsigned long nr_pages;
91648
91649@@ -1500,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91650
91651 /* Clear old maps */
91652 error = -ENOMEM;
91653-munmap_back:
91654 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
91655 if (do_munmap(mm, addr, len))
91656 return -ENOMEM;
91657- goto munmap_back;
91658+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
91659 }
91660
91661 /*
91662@@ -1535,6 +1681,16 @@ munmap_back:
91663 goto unacct_error;
91664 }
91665
91666+#ifdef CONFIG_PAX_SEGMEXEC
91667+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
91668+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
91669+ if (!vma_m) {
91670+ error = -ENOMEM;
91671+ goto free_vma;
91672+ }
91673+ }
91674+#endif
91675+
91676 vma->vm_mm = mm;
91677 vma->vm_start = addr;
91678 vma->vm_end = addr + len;
91679@@ -1554,6 +1710,13 @@ munmap_back:
91680 if (error)
91681 goto unmap_and_free_vma;
91682
91683+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91684+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
91685+ vma->vm_flags |= VM_PAGEEXEC;
91686+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
91687+ }
91688+#endif
91689+
91690 /* Can addr have changed??
91691 *
91692 * Answer: Yes, several device drivers can do it in their
91693@@ -1587,6 +1750,12 @@ munmap_back:
91694 }
91695
91696 vma_link(mm, vma, prev, rb_link, rb_parent);
91697+
91698+#ifdef CONFIG_PAX_SEGMEXEC
91699+ if (vma_m)
91700+ BUG_ON(pax_mirror_vma(vma_m, vma));
91701+#endif
91702+
91703 /* Once vma denies write, undo our temporary denial count */
91704 if (vm_flags & VM_DENYWRITE)
91705 allow_write_access(file);
91706@@ -1595,6 +1764,7 @@ out:
91707 perf_event_mmap(vma);
91708
91709 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
91710+ track_exec_limit(mm, addr, addr + len, vm_flags);
91711 if (vm_flags & VM_LOCKED) {
91712 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
91713 vma == get_gate_vma(current->mm)))
91714@@ -1627,6 +1797,12 @@ unmap_and_free_vma:
91715 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
91716 charged = 0;
91717 free_vma:
91718+
91719+#ifdef CONFIG_PAX_SEGMEXEC
91720+ if (vma_m)
91721+ kmem_cache_free(vm_area_cachep, vma_m);
91722+#endif
91723+
91724 kmem_cache_free(vm_area_cachep, vma);
91725 unacct_error:
91726 if (charged)
91727@@ -1634,7 +1810,63 @@ unacct_error:
91728 return error;
91729 }
91730
91731-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91732+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
91733+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
91734+{
91735+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
91736+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
91737+
91738+ return 0;
91739+}
91740+#endif
91741+
91742+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
91743+{
91744+ if (!vma) {
91745+#ifdef CONFIG_STACK_GROWSUP
91746+ if (addr > sysctl_heap_stack_gap)
91747+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
91748+ else
91749+ vma = find_vma(current->mm, 0);
91750+ if (vma && (vma->vm_flags & VM_GROWSUP))
91751+ return false;
91752+#endif
91753+ return true;
91754+ }
91755+
91756+ if (addr + len > vma->vm_start)
91757+ return false;
91758+
91759+ if (vma->vm_flags & VM_GROWSDOWN)
91760+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
91761+#ifdef CONFIG_STACK_GROWSUP
91762+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
91763+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
91764+#endif
91765+ else if (offset)
91766+ return offset <= vma->vm_start - addr - len;
91767+
91768+ return true;
91769+}
91770+
91771+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
91772+{
91773+ if (vma->vm_start < len)
91774+ return -ENOMEM;
91775+
91776+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
91777+ if (offset <= vma->vm_start - len)
91778+ return vma->vm_start - len - offset;
91779+ else
91780+ return -ENOMEM;
91781+ }
91782+
91783+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
91784+ return vma->vm_start - len - sysctl_heap_stack_gap;
91785+ return -ENOMEM;
91786+}
91787+
91788+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
91789 {
91790 /*
91791 * We implement the search by looking for an rbtree node that
91792@@ -1682,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91793 }
91794 }
91795
91796- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
91797+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
91798 check_current:
91799 /* Check if current node has a suitable gap */
91800 if (gap_start > high_limit)
91801 return -ENOMEM;
91802+
91803+ if (gap_end - gap_start > info->threadstack_offset)
91804+ gap_start += info->threadstack_offset;
91805+ else
91806+ gap_start = gap_end;
91807+
91808+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
91809+ if (gap_end - gap_start > sysctl_heap_stack_gap)
91810+ gap_start += sysctl_heap_stack_gap;
91811+ else
91812+ gap_start = gap_end;
91813+ }
91814+ if (vma->vm_flags & VM_GROWSDOWN) {
91815+ if (gap_end - gap_start > sysctl_heap_stack_gap)
91816+ gap_end -= sysctl_heap_stack_gap;
91817+ else
91818+ gap_end = gap_start;
91819+ }
91820 if (gap_end >= low_limit && gap_end - gap_start >= length)
91821 goto found;
91822
91823@@ -1736,7 +1986,7 @@ found:
91824 return gap_start;
91825 }
91826
91827-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
91828+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
91829 {
91830 struct mm_struct *mm = current->mm;
91831 struct vm_area_struct *vma;
91832@@ -1790,6 +2040,24 @@ check_current:
91833 gap_end = vma->vm_start;
91834 if (gap_end < low_limit)
91835 return -ENOMEM;
91836+
91837+ if (gap_end - gap_start > info->threadstack_offset)
91838+ gap_end -= info->threadstack_offset;
91839+ else
91840+ gap_end = gap_start;
91841+
91842+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
91843+ if (gap_end - gap_start > sysctl_heap_stack_gap)
91844+ gap_start += sysctl_heap_stack_gap;
91845+ else
91846+ gap_start = gap_end;
91847+ }
91848+ if (vma->vm_flags & VM_GROWSDOWN) {
91849+ if (gap_end - gap_start > sysctl_heap_stack_gap)
91850+ gap_end -= sysctl_heap_stack_gap;
91851+ else
91852+ gap_end = gap_start;
91853+ }
91854 if (gap_start <= high_limit && gap_end - gap_start >= length)
91855 goto found;
91856
91857@@ -1853,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91858 struct mm_struct *mm = current->mm;
91859 struct vm_area_struct *vma;
91860 struct vm_unmapped_area_info info;
91861+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
91862
91863 if (len > TASK_SIZE - mmap_min_addr)
91864 return -ENOMEM;
91865@@ -1860,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91866 if (flags & MAP_FIXED)
91867 return addr;
91868
91869+#ifdef CONFIG_PAX_RANDMMAP
91870+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
91871+#endif
91872+
91873 if (addr) {
91874 addr = PAGE_ALIGN(addr);
91875 vma = find_vma(mm, addr);
91876 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
91877- (!vma || addr + len <= vma->vm_start))
91878+ check_heap_stack_gap(vma, addr, len, offset))
91879 return addr;
91880 }
91881
91882@@ -1873,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91883 info.low_limit = mm->mmap_base;
91884 info.high_limit = TASK_SIZE;
91885 info.align_mask = 0;
91886+ info.threadstack_offset = offset;
91887 return vm_unmapped_area(&info);
91888 }
91889 #endif
91890@@ -1891,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
91891 struct mm_struct *mm = current->mm;
91892 unsigned long addr = addr0;
91893 struct vm_unmapped_area_info info;
91894+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
91895
91896 /* requested length too big for entire address space */
91897 if (len > TASK_SIZE - mmap_min_addr)
91898@@ -1899,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
91899 if (flags & MAP_FIXED)
91900 return addr;
91901
91902+#ifdef CONFIG_PAX_RANDMMAP
91903+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
91904+#endif
91905+
91906 /* requesting a specific address */
91907 if (addr) {
91908 addr = PAGE_ALIGN(addr);
91909 vma = find_vma(mm, addr);
91910 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
91911- (!vma || addr + len <= vma->vm_start))
91912+ check_heap_stack_gap(vma, addr, len, offset))
91913 return addr;
91914 }
91915
91916@@ -1913,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
91917 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
91918 info.high_limit = mm->mmap_base;
91919 info.align_mask = 0;
91920+ info.threadstack_offset = offset;
91921 addr = vm_unmapped_area(&info);
91922
91923 /*
91924@@ -1925,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
91925 VM_BUG_ON(addr != -ENOMEM);
91926 info.flags = 0;
91927 info.low_limit = TASK_UNMAPPED_BASE;
91928+
91929+#ifdef CONFIG_PAX_RANDMMAP
91930+ if (mm->pax_flags & MF_PAX_RANDMMAP)
91931+ info.low_limit += mm->delta_mmap;
91932+#endif
91933+
91934 info.high_limit = TASK_SIZE;
91935 addr = vm_unmapped_area(&info);
91936 }
91937@@ -2026,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
91938 return vma;
91939 }
91940
91941+#ifdef CONFIG_PAX_SEGMEXEC
91942+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
91943+{
91944+ struct vm_area_struct *vma_m;
91945+
91946+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
91947+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
91948+ BUG_ON(vma->vm_mirror);
91949+ return NULL;
91950+ }
91951+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
91952+ vma_m = vma->vm_mirror;
91953+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
91954+ BUG_ON(vma->vm_file != vma_m->vm_file);
91955+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
91956+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
91957+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
91958+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
91959+ return vma_m;
91960+}
91961+#endif
91962+
91963 /*
91964 * Verify that the stack growth is acceptable and
91965 * update accounting. This is shared with both the
91966@@ -2042,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
91967 return -ENOMEM;
91968
91969 /* Stack limit test */
91970+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
91971 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
91972 return -ENOMEM;
91973
91974@@ -2052,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
91975 locked = mm->locked_vm + grow;
91976 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
91977 limit >>= PAGE_SHIFT;
91978+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
91979 if (locked > limit && !capable(CAP_IPC_LOCK))
91980 return -ENOMEM;
91981 }
91982@@ -2081,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
91983 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
91984 * vma is the last one with address > vma->vm_end. Have to extend vma.
91985 */
91986+#ifndef CONFIG_IA64
91987+static
91988+#endif
91989 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
91990 {
91991 int error;
91992+ bool locknext;
91993
91994 if (!(vma->vm_flags & VM_GROWSUP))
91995 return -EFAULT;
91996
91997+ /* Also guard against wrapping around to address 0. */
91998+ if (address < PAGE_ALIGN(address+1))
91999+ address = PAGE_ALIGN(address+1);
92000+ else
92001+ return -ENOMEM;
92002+
92003 /*
92004 * We must make sure the anon_vma is allocated
92005 * so that the anon_vma locking is not a noop.
92006 */
92007 if (unlikely(anon_vma_prepare(vma)))
92008 return -ENOMEM;
92009+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
92010+ if (locknext && anon_vma_prepare(vma->vm_next))
92011+ return -ENOMEM;
92012 vma_lock_anon_vma(vma);
92013+ if (locknext)
92014+ vma_lock_anon_vma(vma->vm_next);
92015
92016 /*
92017 * vma->vm_start/vm_end cannot change under us because the caller
92018 * is required to hold the mmap_sem in read mode. We need the
92019- * anon_vma lock to serialize against concurrent expand_stacks.
92020- * Also guard against wrapping around to address 0.
92021+ * anon_vma locks to serialize against concurrent expand_stacks
92022+ * and expand_upwards.
92023 */
92024- if (address < PAGE_ALIGN(address+4))
92025- address = PAGE_ALIGN(address+4);
92026- else {
92027- vma_unlock_anon_vma(vma);
92028- return -ENOMEM;
92029- }
92030 error = 0;
92031
92032 /* Somebody else might have raced and expanded it already */
92033- if (address > vma->vm_end) {
92034+ 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)
92035+ error = -ENOMEM;
92036+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
92037 unsigned long size, grow;
92038
92039 size = address - vma->vm_start;
92040@@ -2146,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92041 }
92042 }
92043 }
92044+ if (locknext)
92045+ vma_unlock_anon_vma(vma->vm_next);
92046 vma_unlock_anon_vma(vma);
92047 khugepaged_enter_vma_merge(vma);
92048 validate_mm(vma->vm_mm);
92049@@ -2160,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
92050 unsigned long address)
92051 {
92052 int error;
92053+ bool lockprev = false;
92054+ struct vm_area_struct *prev;
92055
92056 /*
92057 * We must make sure the anon_vma is allocated
92058@@ -2173,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
92059 if (error)
92060 return error;
92061
92062+ prev = vma->vm_prev;
92063+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
92064+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
92065+#endif
92066+ if (lockprev && anon_vma_prepare(prev))
92067+ return -ENOMEM;
92068+ if (lockprev)
92069+ vma_lock_anon_vma(prev);
92070+
92071 vma_lock_anon_vma(vma);
92072
92073 /*
92074@@ -2182,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
92075 */
92076
92077 /* Somebody else might have raced and expanded it already */
92078- if (address < vma->vm_start) {
92079+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
92080+ error = -ENOMEM;
92081+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
92082 unsigned long size, grow;
92083
92084+#ifdef CONFIG_PAX_SEGMEXEC
92085+ struct vm_area_struct *vma_m;
92086+
92087+ vma_m = pax_find_mirror_vma(vma);
92088+#endif
92089+
92090 size = vma->vm_end - address;
92091 grow = (vma->vm_start - address) >> PAGE_SHIFT;
92092
92093@@ -2209,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
92094 vma->vm_pgoff -= grow;
92095 anon_vma_interval_tree_post_update_vma(vma);
92096 vma_gap_update(vma);
92097+
92098+#ifdef CONFIG_PAX_SEGMEXEC
92099+ if (vma_m) {
92100+ anon_vma_interval_tree_pre_update_vma(vma_m);
92101+ vma_m->vm_start -= grow << PAGE_SHIFT;
92102+ vma_m->vm_pgoff -= grow;
92103+ anon_vma_interval_tree_post_update_vma(vma_m);
92104+ vma_gap_update(vma_m);
92105+ }
92106+#endif
92107+
92108 spin_unlock(&vma->vm_mm->page_table_lock);
92109
92110+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
92111 perf_event_mmap(vma);
92112 }
92113 }
92114 }
92115 vma_unlock_anon_vma(vma);
92116+ if (lockprev)
92117+ vma_unlock_anon_vma(prev);
92118 khugepaged_enter_vma_merge(vma);
92119 validate_mm(vma->vm_mm);
92120 return error;
92121@@ -2313,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
92122 do {
92123 long nrpages = vma_pages(vma);
92124
92125+#ifdef CONFIG_PAX_SEGMEXEC
92126+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
92127+ vma = remove_vma(vma);
92128+ continue;
92129+ }
92130+#endif
92131+
92132 if (vma->vm_flags & VM_ACCOUNT)
92133 nr_accounted += nrpages;
92134 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
92135@@ -2357,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
92136 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
92137 vma->vm_prev = NULL;
92138 do {
92139+
92140+#ifdef CONFIG_PAX_SEGMEXEC
92141+ if (vma->vm_mirror) {
92142+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
92143+ vma->vm_mirror->vm_mirror = NULL;
92144+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
92145+ vma->vm_mirror = NULL;
92146+ }
92147+#endif
92148+
92149 vma_rb_erase(vma, &mm->mm_rb);
92150 mm->map_count--;
92151 tail_vma = vma;
92152@@ -2382,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92153 struct vm_area_struct *new;
92154 int err = -ENOMEM;
92155
92156+#ifdef CONFIG_PAX_SEGMEXEC
92157+ struct vm_area_struct *vma_m, *new_m = NULL;
92158+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
92159+#endif
92160+
92161 if (is_vm_hugetlb_page(vma) && (addr &
92162 ~(huge_page_mask(hstate_vma(vma)))))
92163 return -EINVAL;
92164
92165+#ifdef CONFIG_PAX_SEGMEXEC
92166+ vma_m = pax_find_mirror_vma(vma);
92167+#endif
92168+
92169 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92170 if (!new)
92171 goto out_err;
92172
92173+#ifdef CONFIG_PAX_SEGMEXEC
92174+ if (vma_m) {
92175+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92176+ if (!new_m) {
92177+ kmem_cache_free(vm_area_cachep, new);
92178+ goto out_err;
92179+ }
92180+ }
92181+#endif
92182+
92183 /* most fields are the same, copy all, and then fixup */
92184 *new = *vma;
92185
92186@@ -2402,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92187 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
92188 }
92189
92190+#ifdef CONFIG_PAX_SEGMEXEC
92191+ if (vma_m) {
92192+ *new_m = *vma_m;
92193+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
92194+ new_m->vm_mirror = new;
92195+ new->vm_mirror = new_m;
92196+
92197+ if (new_below)
92198+ new_m->vm_end = addr_m;
92199+ else {
92200+ new_m->vm_start = addr_m;
92201+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
92202+ }
92203+ }
92204+#endif
92205+
92206 err = vma_dup_policy(vma, new);
92207 if (err)
92208 goto out_free_vma;
92209@@ -2421,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92210 else
92211 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
92212
92213+#ifdef CONFIG_PAX_SEGMEXEC
92214+ if (!err && vma_m) {
92215+ struct mempolicy *pol = vma_policy(new);
92216+
92217+ if (anon_vma_clone(new_m, vma_m))
92218+ goto out_free_mpol;
92219+
92220+ mpol_get(pol);
92221+ set_vma_policy(new_m, pol);
92222+
92223+ if (new_m->vm_file)
92224+ get_file(new_m->vm_file);
92225+
92226+ if (new_m->vm_ops && new_m->vm_ops->open)
92227+ new_m->vm_ops->open(new_m);
92228+
92229+ if (new_below)
92230+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
92231+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
92232+ else
92233+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
92234+
92235+ if (err) {
92236+ if (new_m->vm_ops && new_m->vm_ops->close)
92237+ new_m->vm_ops->close(new_m);
92238+ if (new_m->vm_file)
92239+ fput(new_m->vm_file);
92240+ mpol_put(pol);
92241+ }
92242+ }
92243+#endif
92244+
92245 /* Success. */
92246 if (!err)
92247 return 0;
92248@@ -2430,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92249 new->vm_ops->close(new);
92250 if (new->vm_file)
92251 fput(new->vm_file);
92252- unlink_anon_vmas(new);
92253 out_free_mpol:
92254 mpol_put(vma_policy(new));
92255 out_free_vma:
92256+
92257+#ifdef CONFIG_PAX_SEGMEXEC
92258+ if (new_m) {
92259+ unlink_anon_vmas(new_m);
92260+ kmem_cache_free(vm_area_cachep, new_m);
92261+ }
92262+#endif
92263+
92264+ unlink_anon_vmas(new);
92265 kmem_cache_free(vm_area_cachep, new);
92266 out_err:
92267 return err;
92268@@ -2446,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92269 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92270 unsigned long addr, int new_below)
92271 {
92272+
92273+#ifdef CONFIG_PAX_SEGMEXEC
92274+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92275+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
92276+ if (mm->map_count >= sysctl_max_map_count-1)
92277+ return -ENOMEM;
92278+ } else
92279+#endif
92280+
92281 if (mm->map_count >= sysctl_max_map_count)
92282 return -ENOMEM;
92283
92284@@ -2457,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92285 * work. This now handles partial unmappings.
92286 * Jeremy Fitzhardinge <jeremy@goop.org>
92287 */
92288+#ifdef CONFIG_PAX_SEGMEXEC
92289 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92290 {
92291+ int ret = __do_munmap(mm, start, len);
92292+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
92293+ return ret;
92294+
92295+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
92296+}
92297+
92298+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92299+#else
92300+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92301+#endif
92302+{
92303 unsigned long end;
92304 struct vm_area_struct *vma, *prev, *last;
92305
92306+ /*
92307+ * mm->mmap_sem is required to protect against another thread
92308+ * changing the mappings in case we sleep.
92309+ */
92310+ verify_mm_writelocked(mm);
92311+
92312 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
92313 return -EINVAL;
92314
92315@@ -2536,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92316 /* Fix up all other VM information */
92317 remove_vma_list(mm, vma);
92318
92319+ track_exec_limit(mm, start, end, 0UL);
92320+
92321 return 0;
92322 }
92323
92324@@ -2544,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
92325 int ret;
92326 struct mm_struct *mm = current->mm;
92327
92328+
92329+#ifdef CONFIG_PAX_SEGMEXEC
92330+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
92331+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
92332+ return -EINVAL;
92333+#endif
92334+
92335 down_write(&mm->mmap_sem);
92336 ret = do_munmap(mm, start, len);
92337 up_write(&mm->mmap_sem);
92338@@ -2557,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
92339 return vm_munmap(addr, len);
92340 }
92341
92342-static inline void verify_mm_writelocked(struct mm_struct *mm)
92343-{
92344-#ifdef CONFIG_DEBUG_VM
92345- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92346- WARN_ON(1);
92347- up_read(&mm->mmap_sem);
92348- }
92349-#endif
92350-}
92351-
92352 /*
92353 * this is really a simplified "do_mmap". it only handles
92354 * anonymous maps. eventually we may be able to do some
92355@@ -2580,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92356 struct rb_node ** rb_link, * rb_parent;
92357 pgoff_t pgoff = addr >> PAGE_SHIFT;
92358 int error;
92359+ unsigned long charged;
92360
92361 len = PAGE_ALIGN(len);
92362 if (!len)
92363@@ -2587,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92364
92365 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
92366
92367+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
92368+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
92369+ flags &= ~VM_EXEC;
92370+
92371+#ifdef CONFIG_PAX_MPROTECT
92372+ if (mm->pax_flags & MF_PAX_MPROTECT)
92373+ flags &= ~VM_MAYEXEC;
92374+#endif
92375+
92376+ }
92377+#endif
92378+
92379 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
92380 if (error & ~PAGE_MASK)
92381 return error;
92382
92383+ charged = len >> PAGE_SHIFT;
92384+
92385 /*
92386 * mlock MCL_FUTURE?
92387 */
92388 if (mm->def_flags & VM_LOCKED) {
92389 unsigned long locked, lock_limit;
92390- locked = len >> PAGE_SHIFT;
92391+ locked = charged;
92392 locked += mm->locked_vm;
92393 lock_limit = rlimit(RLIMIT_MEMLOCK);
92394 lock_limit >>= PAGE_SHIFT;
92395@@ -2613,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92396 /*
92397 * Clear old maps. this also does some error checking for us
92398 */
92399- munmap_back:
92400 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92401 if (do_munmap(mm, addr, len))
92402 return -ENOMEM;
92403- goto munmap_back;
92404+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92405 }
92406
92407 /* Check against address space limits *after* clearing old maps... */
92408- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
92409+ if (!may_expand_vm(mm, charged))
92410 return -ENOMEM;
92411
92412 if (mm->map_count > sysctl_max_map_count)
92413 return -ENOMEM;
92414
92415- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
92416+ if (security_vm_enough_memory_mm(mm, charged))
92417 return -ENOMEM;
92418
92419 /* Can we just expand an old private anonymous mapping? */
92420@@ -2641,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92421 */
92422 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92423 if (!vma) {
92424- vm_unacct_memory(len >> PAGE_SHIFT);
92425+ vm_unacct_memory(charged);
92426 return -ENOMEM;
92427 }
92428
92429@@ -2655,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92430 vma_link(mm, vma, prev, rb_link, rb_parent);
92431 out:
92432 perf_event_mmap(vma);
92433- mm->total_vm += len >> PAGE_SHIFT;
92434+ mm->total_vm += charged;
92435 if (flags & VM_LOCKED)
92436- mm->locked_vm += (len >> PAGE_SHIFT);
92437+ mm->locked_vm += charged;
92438 vma->vm_flags |= VM_SOFTDIRTY;
92439+ track_exec_limit(mm, addr, addr + len, flags);
92440 return addr;
92441 }
92442
92443@@ -2720,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
92444 while (vma) {
92445 if (vma->vm_flags & VM_ACCOUNT)
92446 nr_accounted += vma_pages(vma);
92447+ vma->vm_mirror = NULL;
92448 vma = remove_vma(vma);
92449 }
92450 vm_unacct_memory(nr_accounted);
92451@@ -2737,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92452 struct vm_area_struct *prev;
92453 struct rb_node **rb_link, *rb_parent;
92454
92455+#ifdef CONFIG_PAX_SEGMEXEC
92456+ struct vm_area_struct *vma_m = NULL;
92457+#endif
92458+
92459+ if (security_mmap_addr(vma->vm_start))
92460+ return -EPERM;
92461+
92462 /*
92463 * The vm_pgoff of a purely anonymous vma should be irrelevant
92464 * until its first write fault, when page's anon_vma and index
92465@@ -2760,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92466 security_vm_enough_memory_mm(mm, vma_pages(vma)))
92467 return -ENOMEM;
92468
92469+#ifdef CONFIG_PAX_SEGMEXEC
92470+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
92471+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92472+ if (!vma_m)
92473+ return -ENOMEM;
92474+ }
92475+#endif
92476+
92477 vma_link(mm, vma, prev, rb_link, rb_parent);
92478+
92479+#ifdef CONFIG_PAX_SEGMEXEC
92480+ if (vma_m)
92481+ BUG_ON(pax_mirror_vma(vma_m, vma));
92482+#endif
92483+
92484 return 0;
92485 }
92486
92487@@ -2779,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92488 struct rb_node **rb_link, *rb_parent;
92489 bool faulted_in_anon_vma = true;
92490
92491+ BUG_ON(vma->vm_mirror);
92492+
92493 /*
92494 * If anonymous vma has not yet been faulted, update new pgoff
92495 * to match new location, to increase its chance of merging.
92496@@ -2843,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92497 return NULL;
92498 }
92499
92500+#ifdef CONFIG_PAX_SEGMEXEC
92501+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
92502+{
92503+ struct vm_area_struct *prev_m;
92504+ struct rb_node **rb_link_m, *rb_parent_m;
92505+ struct mempolicy *pol_m;
92506+
92507+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
92508+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
92509+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
92510+ *vma_m = *vma;
92511+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
92512+ if (anon_vma_clone(vma_m, vma))
92513+ return -ENOMEM;
92514+ pol_m = vma_policy(vma_m);
92515+ mpol_get(pol_m);
92516+ set_vma_policy(vma_m, pol_m);
92517+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
92518+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
92519+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
92520+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
92521+ if (vma_m->vm_file)
92522+ get_file(vma_m->vm_file);
92523+ if (vma_m->vm_ops && vma_m->vm_ops->open)
92524+ vma_m->vm_ops->open(vma_m);
92525+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
92526+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
92527+ vma_m->vm_mirror = vma;
92528+ vma->vm_mirror = vma_m;
92529+ return 0;
92530+}
92531+#endif
92532+
92533 /*
92534 * Return true if the calling process may expand its vm space by the passed
92535 * number of pages
92536@@ -2854,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
92537
92538 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
92539
92540+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
92541 if (cur + npages > lim)
92542 return 0;
92543 return 1;
92544@@ -2924,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
92545 vma->vm_start = addr;
92546 vma->vm_end = addr + len;
92547
92548+#ifdef CONFIG_PAX_MPROTECT
92549+ if (mm->pax_flags & MF_PAX_MPROTECT) {
92550+#ifndef CONFIG_PAX_MPROTECT_COMPAT
92551+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
92552+ return -EPERM;
92553+ if (!(vm_flags & VM_EXEC))
92554+ vm_flags &= ~VM_MAYEXEC;
92555+#else
92556+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92557+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92558+#endif
92559+ else
92560+ vm_flags &= ~VM_MAYWRITE;
92561+ }
92562+#endif
92563+
92564 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
92565 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92566
92567diff --git a/mm/mprotect.c b/mm/mprotect.c
92568index bb53a65..249c052 100644
92569--- a/mm/mprotect.c
92570+++ b/mm/mprotect.c
92571@@ -23,10 +23,18 @@
92572 #include <linux/mmu_notifier.h>
92573 #include <linux/migrate.h>
92574 #include <linux/perf_event.h>
92575+#include <linux/sched/sysctl.h>
92576+
92577+#ifdef CONFIG_PAX_MPROTECT
92578+#include <linux/elf.h>
92579+#include <linux/binfmts.h>
92580+#endif
92581+
92582 #include <asm/uaccess.h>
92583 #include <asm/pgtable.h>
92584 #include <asm/cacheflush.h>
92585 #include <asm/tlbflush.h>
92586+#include <asm/mmu_context.h>
92587
92588 #ifndef pgprot_modify
92589 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
92590@@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
92591 return pages;
92592 }
92593
92594+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92595+/* called while holding the mmap semaphor for writing except stack expansion */
92596+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
92597+{
92598+ unsigned long oldlimit, newlimit = 0UL;
92599+
92600+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
92601+ return;
92602+
92603+ spin_lock(&mm->page_table_lock);
92604+ oldlimit = mm->context.user_cs_limit;
92605+ if ((prot & VM_EXEC) && oldlimit < end)
92606+ /* USER_CS limit moved up */
92607+ newlimit = end;
92608+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
92609+ /* USER_CS limit moved down */
92610+ newlimit = start;
92611+
92612+ if (newlimit) {
92613+ mm->context.user_cs_limit = newlimit;
92614+
92615+#ifdef CONFIG_SMP
92616+ wmb();
92617+ cpus_clear(mm->context.cpu_user_cs_mask);
92618+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
92619+#endif
92620+
92621+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
92622+ }
92623+ spin_unlock(&mm->page_table_lock);
92624+ if (newlimit == end) {
92625+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
92626+
92627+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
92628+ if (is_vm_hugetlb_page(vma))
92629+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
92630+ else
92631+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
92632+ }
92633+}
92634+#endif
92635+
92636 int
92637 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92638 unsigned long start, unsigned long end, unsigned long newflags)
92639@@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92640 int error;
92641 int dirty_accountable = 0;
92642
92643+#ifdef CONFIG_PAX_SEGMEXEC
92644+ struct vm_area_struct *vma_m = NULL;
92645+ unsigned long start_m, end_m;
92646+
92647+ start_m = start + SEGMEXEC_TASK_SIZE;
92648+ end_m = end + SEGMEXEC_TASK_SIZE;
92649+#endif
92650+
92651 if (newflags == oldflags) {
92652 *pprev = vma;
92653 return 0;
92654 }
92655
92656+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
92657+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
92658+
92659+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
92660+ return -ENOMEM;
92661+
92662+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
92663+ return -ENOMEM;
92664+ }
92665+
92666 /*
92667 * If we make a private mapping writable we increase our commit;
92668 * but (without finer accounting) cannot reduce our commit if we
92669@@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92670 }
92671 }
92672
92673+#ifdef CONFIG_PAX_SEGMEXEC
92674+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
92675+ if (start != vma->vm_start) {
92676+ error = split_vma(mm, vma, start, 1);
92677+ if (error)
92678+ goto fail;
92679+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
92680+ *pprev = (*pprev)->vm_next;
92681+ }
92682+
92683+ if (end != vma->vm_end) {
92684+ error = split_vma(mm, vma, end, 0);
92685+ if (error)
92686+ goto fail;
92687+ }
92688+
92689+ if (pax_find_mirror_vma(vma)) {
92690+ error = __do_munmap(mm, start_m, end_m - start_m);
92691+ if (error)
92692+ goto fail;
92693+ } else {
92694+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92695+ if (!vma_m) {
92696+ error = -ENOMEM;
92697+ goto fail;
92698+ }
92699+ vma->vm_flags = newflags;
92700+ error = pax_mirror_vma(vma_m, vma);
92701+ if (error) {
92702+ vma->vm_flags = oldflags;
92703+ goto fail;
92704+ }
92705+ }
92706+ }
92707+#endif
92708+
92709 /*
92710 * First try to merge with previous and/or next vma.
92711 */
92712@@ -285,9 +389,21 @@ success:
92713 * vm_flags and vm_page_prot are protected by the mmap_sem
92714 * held in write mode.
92715 */
92716+
92717+#ifdef CONFIG_PAX_SEGMEXEC
92718+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
92719+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
92720+#endif
92721+
92722 vma->vm_flags = newflags;
92723+
92724+#ifdef CONFIG_PAX_MPROTECT
92725+ if (mm->binfmt && mm->binfmt->handle_mprotect)
92726+ mm->binfmt->handle_mprotect(vma, newflags);
92727+#endif
92728+
92729 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
92730- vm_get_page_prot(newflags));
92731+ vm_get_page_prot(vma->vm_flags));
92732
92733 if (vma_wants_writenotify(vma)) {
92734 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
92735@@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92736 end = start + len;
92737 if (end <= start)
92738 return -ENOMEM;
92739+
92740+#ifdef CONFIG_PAX_SEGMEXEC
92741+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92742+ if (end > SEGMEXEC_TASK_SIZE)
92743+ return -EINVAL;
92744+ } else
92745+#endif
92746+
92747+ if (end > TASK_SIZE)
92748+ return -EINVAL;
92749+
92750 if (!arch_validate_prot(prot))
92751 return -EINVAL;
92752
92753@@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92754 /*
92755 * Does the application expect PROT_READ to imply PROT_EXEC:
92756 */
92757- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92758+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92759 prot |= PROT_EXEC;
92760
92761 vm_flags = calc_vm_prot_bits(prot);
92762@@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92763 if (start > vma->vm_start)
92764 prev = vma;
92765
92766+#ifdef CONFIG_PAX_MPROTECT
92767+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
92768+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
92769+#endif
92770+
92771 for (nstart = start ; ; ) {
92772 unsigned long newflags;
92773
92774@@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92775
92776 /* newflags >> 4 shift VM_MAY% in place of VM_% */
92777 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
92778+ if (prot & (PROT_WRITE | PROT_EXEC))
92779+ gr_log_rwxmprotect(vma);
92780+
92781+ error = -EACCES;
92782+ goto out;
92783+ }
92784+
92785+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
92786 error = -EACCES;
92787 goto out;
92788 }
92789@@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92790 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
92791 if (error)
92792 goto out;
92793+
92794+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
92795+
92796 nstart = tmp;
92797
92798 if (nstart < prev->vm_end)
92799diff --git a/mm/mremap.c b/mm/mremap.c
92800index 0843feb..4f5b2e6 100644
92801--- a/mm/mremap.c
92802+++ b/mm/mremap.c
92803@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
92804 continue;
92805 pte = ptep_get_and_clear(mm, old_addr, old_pte);
92806 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
92807+
92808+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92809+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
92810+ pte = pte_exprotect(pte);
92811+#endif
92812+
92813 pte = move_soft_dirty_pte(pte);
92814 set_pte_at(mm, new_addr, new_pte, pte);
92815 }
92816@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
92817 if (is_vm_hugetlb_page(vma))
92818 goto Einval;
92819
92820+#ifdef CONFIG_PAX_SEGMEXEC
92821+ if (pax_find_mirror_vma(vma))
92822+ goto Einval;
92823+#endif
92824+
92825 /* We can't remap across vm area boundaries */
92826 if (old_len > vma->vm_end - addr)
92827 goto Efault;
92828@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
92829 unsigned long ret = -EINVAL;
92830 unsigned long charged = 0;
92831 unsigned long map_flags;
92832+ unsigned long pax_task_size = TASK_SIZE;
92833
92834 if (new_addr & ~PAGE_MASK)
92835 goto out;
92836
92837- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
92838+#ifdef CONFIG_PAX_SEGMEXEC
92839+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
92840+ pax_task_size = SEGMEXEC_TASK_SIZE;
92841+#endif
92842+
92843+ pax_task_size -= PAGE_SIZE;
92844+
92845+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
92846 goto out;
92847
92848 /* Check if the location we're moving into overlaps the
92849 * old location at all, and fail if it does.
92850 */
92851- if ((new_addr <= addr) && (new_addr+new_len) > addr)
92852- goto out;
92853-
92854- if ((addr <= new_addr) && (addr+old_len) > new_addr)
92855+ if (addr + old_len > new_addr && new_addr + new_len > addr)
92856 goto out;
92857
92858 ret = do_munmap(mm, new_addr, new_len);
92859@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92860 unsigned long ret = -EINVAL;
92861 unsigned long charged = 0;
92862 bool locked = false;
92863+ unsigned long pax_task_size = TASK_SIZE;
92864
92865 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
92866 return ret;
92867@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92868 if (!new_len)
92869 return ret;
92870
92871+#ifdef CONFIG_PAX_SEGMEXEC
92872+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
92873+ pax_task_size = SEGMEXEC_TASK_SIZE;
92874+#endif
92875+
92876+ pax_task_size -= PAGE_SIZE;
92877+
92878+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
92879+ old_len > pax_task_size || addr > pax_task_size-old_len)
92880+ return ret;
92881+
92882 down_write(&current->mm->mmap_sem);
92883
92884 if (flags & MREMAP_FIXED) {
92885@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92886 new_addr = addr;
92887 }
92888 ret = addr;
92889+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
92890 goto out;
92891 }
92892 }
92893@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92894 goto out;
92895 }
92896
92897+ map_flags = vma->vm_flags;
92898 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
92899+ if (!(ret & ~PAGE_MASK)) {
92900+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
92901+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
92902+ }
92903 }
92904 out:
92905 if (ret & ~PAGE_MASK)
92906diff --git a/mm/nommu.c b/mm/nommu.c
92907index fec093a..8162f74 100644
92908--- a/mm/nommu.c
92909+++ b/mm/nommu.c
92910@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
92911 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
92912 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92913 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92914-int heap_stack_gap = 0;
92915
92916 atomic_long_t mmap_pages_allocated;
92917
92918@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
92919 EXPORT_SYMBOL(find_vma);
92920
92921 /*
92922- * find a VMA
92923- * - we don't extend stack VMAs under NOMMU conditions
92924- */
92925-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
92926-{
92927- return find_vma(mm, addr);
92928-}
92929-
92930-/*
92931 * expand a stack to a given address
92932 * - not supported under NOMMU conditions
92933 */
92934@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92935
92936 /* most fields are the same, copy all, and then fixup */
92937 *new = *vma;
92938+ INIT_LIST_HEAD(&new->anon_vma_chain);
92939 *region = *vma->vm_region;
92940 new->vm_region = region;
92941
92942@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
92943 }
92944 EXPORT_SYMBOL(generic_file_remap_pages);
92945
92946-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92947- unsigned long addr, void *buf, int len, int write)
92948+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92949+ unsigned long addr, void *buf, size_t len, int write)
92950 {
92951 struct vm_area_struct *vma;
92952
92953@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92954 *
92955 * The caller must hold a reference on @mm.
92956 */
92957-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92958- void *buf, int len, int write)
92959+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92960+ void *buf, size_t len, int write)
92961 {
92962 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92963 }
92964@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92965 * Access another process' address space.
92966 * - source/target buffer must be kernel space
92967 */
92968-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
92969+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
92970 {
92971 struct mm_struct *mm;
92972
92973diff --git a/mm/page-writeback.c b/mm/page-writeback.c
92974index 6380758..4064aec 100644
92975--- a/mm/page-writeback.c
92976+++ b/mm/page-writeback.c
92977@@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
92978 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
92979 * - the bdi dirty thresh drops quickly due to change of JBOD workload
92980 */
92981-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
92982+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
92983 unsigned long thresh,
92984 unsigned long bg_thresh,
92985 unsigned long dirty,
92986diff --git a/mm/page_alloc.c b/mm/page_alloc.c
92987index 5248fe0..0f693aa 100644
92988--- a/mm/page_alloc.c
92989+++ b/mm/page_alloc.c
92990@@ -61,6 +61,7 @@
92991 #include <linux/page-debug-flags.h>
92992 #include <linux/hugetlb.h>
92993 #include <linux/sched/rt.h>
92994+#include <linux/random.h>
92995
92996 #include <asm/sections.h>
92997 #include <asm/tlbflush.h>
92998@@ -354,7 +355,7 @@ out:
92999 * This usage means that zero-order pages may not be compound.
93000 */
93001
93002-static void free_compound_page(struct page *page)
93003+void free_compound_page(struct page *page)
93004 {
93005 __free_pages_ok(page, compound_order(page));
93006 }
93007@@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93008 int i;
93009 int bad = 0;
93010
93011+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93012+ unsigned long index = 1UL << order;
93013+#endif
93014+
93015 trace_mm_page_free(page, order);
93016 kmemcheck_free_shadow(page, order);
93017
93018@@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93019 debug_check_no_obj_freed(page_address(page),
93020 PAGE_SIZE << order);
93021 }
93022+
93023+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93024+ for (; index; --index)
93025+ sanitize_highpage(page + index - 1);
93026+#endif
93027+
93028 arch_free_page(page, order);
93029 kernel_map_pages(page, 1 << order, 0);
93030
93031@@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
93032 local_irq_restore(flags);
93033 }
93034
93035+#ifdef CONFIG_PAX_LATENT_ENTROPY
93036+bool __meminitdata extra_latent_entropy;
93037+
93038+static int __init setup_pax_extra_latent_entropy(char *str)
93039+{
93040+ extra_latent_entropy = true;
93041+ return 0;
93042+}
93043+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
93044+
93045+volatile u64 latent_entropy __latent_entropy;
93046+EXPORT_SYMBOL(latent_entropy);
93047+#endif
93048+
93049 void __init __free_pages_bootmem(struct page *page, unsigned int order)
93050 {
93051 unsigned int nr_pages = 1 << order;
93052@@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
93053 __ClearPageReserved(p);
93054 set_page_count(p, 0);
93055
93056+#ifdef CONFIG_PAX_LATENT_ENTROPY
93057+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
93058+ u64 hash = 0;
93059+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
93060+ const u64 *data = lowmem_page_address(page);
93061+
93062+ for (index = 0; index < end; index++)
93063+ hash ^= hash + data[index];
93064+ latent_entropy ^= hash;
93065+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
93066+ }
93067+#endif
93068+
93069 page_zone(page)->managed_pages += nr_pages;
93070 set_page_refcounted(page);
93071 __free_pages(page, order);
93072@@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
93073 arch_alloc_page(page, order);
93074 kernel_map_pages(page, 1 << order, 1);
93075
93076+#ifndef CONFIG_PAX_MEMORY_SANITIZE
93077 if (gfp_flags & __GFP_ZERO)
93078 prep_zero_page(page, order, gfp_flags);
93079+#endif
93080
93081 if (order && (gfp_flags & __GFP_COMP))
93082 prep_compound_page(page, order);
93083diff --git a/mm/page_io.c b/mm/page_io.c
93084index 8c79a47..a689e0d 100644
93085--- a/mm/page_io.c
93086+++ b/mm/page_io.c
93087@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
93088 struct file *swap_file = sis->swap_file;
93089 struct address_space *mapping = swap_file->f_mapping;
93090 struct iovec iov = {
93091- .iov_base = kmap(page),
93092+ .iov_base = (void __force_user *)kmap(page),
93093 .iov_len = PAGE_SIZE,
93094 };
93095
93096diff --git a/mm/percpu.c b/mm/percpu.c
93097index 0d10def..6dc822d 100644
93098--- a/mm/percpu.c
93099+++ b/mm/percpu.c
93100@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
93101 static unsigned int pcpu_high_unit_cpu __read_mostly;
93102
93103 /* the address of the first chunk which starts with the kernel static area */
93104-void *pcpu_base_addr __read_mostly;
93105+void *pcpu_base_addr __read_only;
93106 EXPORT_SYMBOL_GPL(pcpu_base_addr);
93107
93108 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
93109diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
93110index fd26d04..0cea1b0 100644
93111--- a/mm/process_vm_access.c
93112+++ b/mm/process_vm_access.c
93113@@ -13,6 +13,7 @@
93114 #include <linux/uio.h>
93115 #include <linux/sched.h>
93116 #include <linux/highmem.h>
93117+#include <linux/security.h>
93118 #include <linux/ptrace.h>
93119 #include <linux/slab.h>
93120 #include <linux/syscalls.h>
93121@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93122 size_t iov_l_curr_offset = 0;
93123 ssize_t iov_len;
93124
93125+ return -ENOSYS; // PaX: until properly audited
93126+
93127 /*
93128 * Work out how many pages of struct pages we're going to need
93129 * when eventually calling get_user_pages
93130 */
93131 for (i = 0; i < riovcnt; i++) {
93132 iov_len = rvec[i].iov_len;
93133- if (iov_len > 0) {
93134- nr_pages_iov = ((unsigned long)rvec[i].iov_base
93135- + iov_len)
93136- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
93137- / PAGE_SIZE + 1;
93138- nr_pages = max(nr_pages, nr_pages_iov);
93139- }
93140+ if (iov_len <= 0)
93141+ continue;
93142+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
93143+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
93144+ nr_pages = max(nr_pages, nr_pages_iov);
93145 }
93146
93147 if (nr_pages == 0)
93148@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93149 goto free_proc_pages;
93150 }
93151
93152+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
93153+ rc = -EPERM;
93154+ goto put_task_struct;
93155+ }
93156+
93157 mm = mm_access(task, PTRACE_MODE_ATTACH);
93158 if (!mm || IS_ERR(mm)) {
93159 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
93160diff --git a/mm/rmap.c b/mm/rmap.c
93161index 068522d..f539f21 100644
93162--- a/mm/rmap.c
93163+++ b/mm/rmap.c
93164@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93165 struct anon_vma *anon_vma = vma->anon_vma;
93166 struct anon_vma_chain *avc;
93167
93168+#ifdef CONFIG_PAX_SEGMEXEC
93169+ struct anon_vma_chain *avc_m = NULL;
93170+#endif
93171+
93172 might_sleep();
93173 if (unlikely(!anon_vma)) {
93174 struct mm_struct *mm = vma->vm_mm;
93175@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93176 if (!avc)
93177 goto out_enomem;
93178
93179+#ifdef CONFIG_PAX_SEGMEXEC
93180+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
93181+ if (!avc_m)
93182+ goto out_enomem_free_avc;
93183+#endif
93184+
93185 anon_vma = find_mergeable_anon_vma(vma);
93186 allocated = NULL;
93187 if (!anon_vma) {
93188@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93189 /* page_table_lock to protect against threads */
93190 spin_lock(&mm->page_table_lock);
93191 if (likely(!vma->anon_vma)) {
93192+
93193+#ifdef CONFIG_PAX_SEGMEXEC
93194+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
93195+
93196+ if (vma_m) {
93197+ BUG_ON(vma_m->anon_vma);
93198+ vma_m->anon_vma = anon_vma;
93199+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
93200+ avc_m = NULL;
93201+ }
93202+#endif
93203+
93204 vma->anon_vma = anon_vma;
93205 anon_vma_chain_link(vma, avc, anon_vma);
93206 allocated = NULL;
93207@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93208
93209 if (unlikely(allocated))
93210 put_anon_vma(allocated);
93211+
93212+#ifdef CONFIG_PAX_SEGMEXEC
93213+ if (unlikely(avc_m))
93214+ anon_vma_chain_free(avc_m);
93215+#endif
93216+
93217 if (unlikely(avc))
93218 anon_vma_chain_free(avc);
93219 }
93220 return 0;
93221
93222 out_enomem_free_avc:
93223+
93224+#ifdef CONFIG_PAX_SEGMEXEC
93225+ if (avc_m)
93226+ anon_vma_chain_free(avc_m);
93227+#endif
93228+
93229 anon_vma_chain_free(avc);
93230 out_enomem:
93231 return -ENOMEM;
93232@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
93233 * Attach the anon_vmas from src to dst.
93234 * Returns 0 on success, -ENOMEM on failure.
93235 */
93236-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93237+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
93238 {
93239 struct anon_vma_chain *avc, *pavc;
93240 struct anon_vma *root = NULL;
93241@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93242 * the corresponding VMA in the parent process is attached to.
93243 * Returns 0 on success, non-zero on failure.
93244 */
93245-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
93246+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
93247 {
93248 struct anon_vma_chain *avc;
93249 struct anon_vma *anon_vma;
93250@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
93251 void __init anon_vma_init(void)
93252 {
93253 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
93254- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
93255- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
93256+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
93257+ anon_vma_ctor);
93258+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
93259+ SLAB_PANIC|SLAB_NO_SANITIZE);
93260 }
93261
93262 /*
93263diff --git a/mm/shmem.c b/mm/shmem.c
93264index 902a148..58f9d59 100644
93265--- a/mm/shmem.c
93266+++ b/mm/shmem.c
93267@@ -33,7 +33,7 @@
93268 #include <linux/swap.h>
93269 #include <linux/aio.h>
93270
93271-static struct vfsmount *shm_mnt;
93272+struct vfsmount *shm_mnt;
93273
93274 #ifdef CONFIG_SHMEM
93275 /*
93276@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
93277 #define BOGO_DIRENT_SIZE 20
93278
93279 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
93280-#define SHORT_SYMLINK_LEN 128
93281+#define SHORT_SYMLINK_LEN 64
93282
93283 /*
93284 * shmem_fallocate and shmem_writepage communicate via inode->i_private
93285@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
93286 static int shmem_xattr_validate(const char *name)
93287 {
93288 struct { const char *prefix; size_t len; } arr[] = {
93289+
93290+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93291+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
93292+#endif
93293+
93294 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
93295 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
93296 };
93297@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
93298 if (err)
93299 return err;
93300
93301+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93302+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
93303+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
93304+ return -EOPNOTSUPP;
93305+ if (size > 8)
93306+ return -EINVAL;
93307+ }
93308+#endif
93309+
93310 return simple_xattr_set(&info->xattrs, name, value, size, flags);
93311 }
93312
93313@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
93314 int err = -ENOMEM;
93315
93316 /* Round up to L1_CACHE_BYTES to resist false sharing */
93317- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
93318- L1_CACHE_BYTES), GFP_KERNEL);
93319+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
93320 if (!sbinfo)
93321 return -ENOMEM;
93322
93323diff --git a/mm/slab.c b/mm/slab.c
93324index eb043bf..d82f5a8 100644
93325--- a/mm/slab.c
93326+++ b/mm/slab.c
93327@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93328 if ((x)->max_freeable < i) \
93329 (x)->max_freeable = i; \
93330 } while (0)
93331-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
93332-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
93333-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
93334-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
93335+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
93336+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
93337+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
93338+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
93339+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
93340+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
93341 #else
93342 #define STATS_INC_ACTIVE(x) do { } while (0)
93343 #define STATS_DEC_ACTIVE(x) do { } while (0)
93344@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93345 #define STATS_INC_ALLOCMISS(x) do { } while (0)
93346 #define STATS_INC_FREEHIT(x) do { } while (0)
93347 #define STATS_INC_FREEMISS(x) do { } while (0)
93348+#define STATS_INC_SANITIZED(x) do { } while (0)
93349+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
93350 #endif
93351
93352 #if DEBUG
93353@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
93354 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
93355 */
93356 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
93357- const struct page *page, void *obj)
93358+ const struct page *page, const void *obj)
93359 {
93360 u32 offset = (obj - page->s_mem);
93361 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
93362@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
93363 */
93364
93365 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
93366- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
93367+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93368
93369 if (INDEX_AC != INDEX_NODE)
93370 kmalloc_caches[INDEX_NODE] =
93371 create_kmalloc_cache("kmalloc-node",
93372- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
93373+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93374
93375 slab_early_init = 0;
93376
93377@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
93378 struct array_cache *ac = cpu_cache_get(cachep);
93379
93380 check_irq_off();
93381+
93382+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93383+ if (pax_sanitize_slab) {
93384+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
93385+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
93386+
93387+ if (cachep->ctor)
93388+ cachep->ctor(objp);
93389+
93390+ STATS_INC_SANITIZED(cachep);
93391+ } else
93392+ STATS_INC_NOT_SANITIZED(cachep);
93393+ }
93394+#endif
93395+
93396 kmemleak_free_recursive(objp, cachep->flags);
93397 objp = cache_free_debugcheck(cachep, objp, caller);
93398
93399@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
93400
93401 if (unlikely(ZERO_OR_NULL_PTR(objp)))
93402 return;
93403+ VM_BUG_ON(!virt_addr_valid(objp));
93404 local_irq_save(flags);
93405 kfree_debugcheck(objp);
93406 c = virt_to_cache(objp);
93407@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
93408 }
93409 /* cpu stats */
93410 {
93411- unsigned long allochit = atomic_read(&cachep->allochit);
93412- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
93413- unsigned long freehit = atomic_read(&cachep->freehit);
93414- unsigned long freemiss = atomic_read(&cachep->freemiss);
93415+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
93416+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
93417+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
93418+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
93419
93420 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
93421 allochit, allocmiss, freehit, freemiss);
93422 }
93423+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93424+ {
93425+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
93426+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
93427+
93428+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
93429+ }
93430+#endif
93431 #endif
93432 }
93433
93434@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
93435 static int __init slab_proc_init(void)
93436 {
93437 #ifdef CONFIG_DEBUG_SLAB_LEAK
93438- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
93439+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
93440 #endif
93441 return 0;
93442 }
93443 module_init(slab_proc_init);
93444 #endif
93445
93446+bool is_usercopy_object(const void *ptr)
93447+{
93448+ struct page *page;
93449+ struct kmem_cache *cachep;
93450+
93451+ if (ZERO_OR_NULL_PTR(ptr))
93452+ return false;
93453+
93454+ if (!slab_is_available())
93455+ return false;
93456+
93457+ if (!virt_addr_valid(ptr))
93458+ return false;
93459+
93460+ page = virt_to_head_page(ptr);
93461+
93462+ if (!PageSlab(page))
93463+ return false;
93464+
93465+ cachep = page->slab_cache;
93466+ return cachep->flags & SLAB_USERCOPY;
93467+}
93468+
93469+#ifdef CONFIG_PAX_USERCOPY
93470+const char *check_heap_object(const void *ptr, unsigned long n)
93471+{
93472+ struct page *page;
93473+ struct kmem_cache *cachep;
93474+ unsigned int objnr;
93475+ unsigned long offset;
93476+
93477+ if (ZERO_OR_NULL_PTR(ptr))
93478+ return "<null>";
93479+
93480+ if (!virt_addr_valid(ptr))
93481+ return NULL;
93482+
93483+ page = virt_to_head_page(ptr);
93484+
93485+ if (!PageSlab(page))
93486+ return NULL;
93487+
93488+ cachep = page->slab_cache;
93489+ if (!(cachep->flags & SLAB_USERCOPY))
93490+ return cachep->name;
93491+
93492+ objnr = obj_to_index(cachep, page, ptr);
93493+ BUG_ON(objnr >= cachep->num);
93494+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
93495+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
93496+ return NULL;
93497+
93498+ return cachep->name;
93499+}
93500+#endif
93501+
93502 /**
93503 * ksize - get the actual amount of memory allocated for a given object
93504 * @objp: Pointer to the object
93505diff --git a/mm/slab.h b/mm/slab.h
93506index 0859c42..2f7b737 100644
93507--- a/mm/slab.h
93508+++ b/mm/slab.h
93509@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
93510 /* The slab cache that manages slab cache information */
93511 extern struct kmem_cache *kmem_cache;
93512
93513+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93514+#ifdef CONFIG_X86_64
93515+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
93516+#else
93517+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
93518+#endif
93519+extern bool pax_sanitize_slab;
93520+#endif
93521+
93522 unsigned long calculate_alignment(unsigned long flags,
93523 unsigned long align, unsigned long size);
93524
93525@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
93526
93527 /* Legal flag mask for kmem_cache_create(), for various configurations */
93528 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
93529- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
93530+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
93531+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
93532
93533 #if defined(CONFIG_DEBUG_SLAB)
93534 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
93535@@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
93536 return s;
93537
93538 page = virt_to_head_page(x);
93539+
93540+ BUG_ON(!PageSlab(page));
93541+
93542 cachep = page->slab_cache;
93543 if (slab_equal_or_root(cachep, s))
93544 return cachep;
93545diff --git a/mm/slab_common.c b/mm/slab_common.c
93546index 0b7bb39..334c328 100644
93547--- a/mm/slab_common.c
93548+++ b/mm/slab_common.c
93549@@ -23,11 +23,22 @@
93550
93551 #include "slab.h"
93552
93553-enum slab_state slab_state;
93554+enum slab_state slab_state __read_only;
93555 LIST_HEAD(slab_caches);
93556 DEFINE_MUTEX(slab_mutex);
93557 struct kmem_cache *kmem_cache;
93558
93559+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93560+bool pax_sanitize_slab __read_only = true;
93561+static int __init pax_sanitize_slab_setup(char *str)
93562+{
93563+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
93564+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
93565+ return 1;
93566+}
93567+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
93568+#endif
93569+
93570 #ifdef CONFIG_DEBUG_VM
93571 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
93572 size_t size)
93573@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
93574
93575 err = __kmem_cache_create(s, flags);
93576 if (!err) {
93577- s->refcount = 1;
93578+ atomic_set(&s->refcount, 1);
93579 list_add(&s->list, &slab_caches);
93580 memcg_cache_list_add(memcg, s);
93581 } else {
93582@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
93583
93584 get_online_cpus();
93585 mutex_lock(&slab_mutex);
93586- s->refcount--;
93587- if (!s->refcount) {
93588+ if (atomic_dec_and_test(&s->refcount)) {
93589 list_del(&s->list);
93590
93591 if (!__kmem_cache_shutdown(s)) {
93592@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
93593 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
93594 name, size, err);
93595
93596- s->refcount = -1; /* Exempt from merging for now */
93597+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
93598 }
93599
93600 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93601@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93602
93603 create_boot_cache(s, name, size, flags);
93604 list_add(&s->list, &slab_caches);
93605- s->refcount = 1;
93606+ atomic_set(&s->refcount, 1);
93607 return s;
93608 }
93609
93610@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
93611 EXPORT_SYMBOL(kmalloc_dma_caches);
93612 #endif
93613
93614+#ifdef CONFIG_PAX_USERCOPY_SLABS
93615+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
93616+EXPORT_SYMBOL(kmalloc_usercopy_caches);
93617+#endif
93618+
93619 /*
93620 * Conversion table for small slabs sizes / 8 to the index in the
93621 * kmalloc array. This is necessary for slabs < 192 since we have non power
93622@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
93623 return kmalloc_dma_caches[index];
93624
93625 #endif
93626+
93627+#ifdef CONFIG_PAX_USERCOPY_SLABS
93628+ if (unlikely((flags & GFP_USERCOPY)))
93629+ return kmalloc_usercopy_caches[index];
93630+
93631+#endif
93632+
93633 return kmalloc_caches[index];
93634 }
93635
93636@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
93637 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
93638 if (!kmalloc_caches[i]) {
93639 kmalloc_caches[i] = create_kmalloc_cache(NULL,
93640- 1 << i, flags);
93641+ 1 << i, SLAB_USERCOPY | flags);
93642 }
93643
93644 /*
93645@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
93646 * earlier power of two caches
93647 */
93648 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
93649- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
93650+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
93651
93652 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
93653- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
93654+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
93655 }
93656
93657 /* Kmalloc array is now usable */
93658@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
93659 }
93660 }
93661 #endif
93662+
93663+#ifdef CONFIG_PAX_USERCOPY_SLABS
93664+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
93665+ struct kmem_cache *s = kmalloc_caches[i];
93666+
93667+ if (s) {
93668+ int size = kmalloc_size(i);
93669+ char *n = kasprintf(GFP_NOWAIT,
93670+ "usercopy-kmalloc-%d", size);
93671+
93672+ BUG_ON(!n);
93673+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
93674+ size, SLAB_USERCOPY | flags);
93675+ }
93676+ }
93677+#endif
93678+
93679 }
93680 #endif /* !CONFIG_SLOB */
93681
93682@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
93683 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
93684 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
93685 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
93686+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93687+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
93688+#endif
93689 #endif
93690 seq_putc(m, '\n');
93691 }
93692diff --git a/mm/slob.c b/mm/slob.c
93693index 4bf8809..98a6914 100644
93694--- a/mm/slob.c
93695+++ b/mm/slob.c
93696@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
93697 /*
93698 * Return the size of a slob block.
93699 */
93700-static slobidx_t slob_units(slob_t *s)
93701+static slobidx_t slob_units(const slob_t *s)
93702 {
93703 if (s->units > 0)
93704 return s->units;
93705@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
93706 /*
93707 * Return the next free slob block pointer after this one.
93708 */
93709-static slob_t *slob_next(slob_t *s)
93710+static slob_t *slob_next(const slob_t *s)
93711 {
93712 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
93713 slobidx_t next;
93714@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
93715 /*
93716 * Returns true if s is the last free block in its page.
93717 */
93718-static int slob_last(slob_t *s)
93719+static int slob_last(const slob_t *s)
93720 {
93721 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
93722 }
93723
93724-static void *slob_new_pages(gfp_t gfp, int order, int node)
93725+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
93726 {
93727- void *page;
93728+ struct page *page;
93729
93730 #ifdef CONFIG_NUMA
93731 if (node != NUMA_NO_NODE)
93732@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
93733 if (!page)
93734 return NULL;
93735
93736- return page_address(page);
93737+ __SetPageSlab(page);
93738+ return page;
93739 }
93740
93741-static void slob_free_pages(void *b, int order)
93742+static void slob_free_pages(struct page *sp, int order)
93743 {
93744 if (current->reclaim_state)
93745 current->reclaim_state->reclaimed_slab += 1 << order;
93746- free_pages((unsigned long)b, order);
93747+ __ClearPageSlab(sp);
93748+ page_mapcount_reset(sp);
93749+ sp->private = 0;
93750+ __free_pages(sp, order);
93751 }
93752
93753 /*
93754@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
93755
93756 /* Not enough space: must allocate a new page */
93757 if (!b) {
93758- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
93759- if (!b)
93760+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
93761+ if (!sp)
93762 return NULL;
93763- sp = virt_to_page(b);
93764- __SetPageSlab(sp);
93765+ b = page_address(sp);
93766
93767 spin_lock_irqsave(&slob_lock, flags);
93768 sp->units = SLOB_UNITS(PAGE_SIZE);
93769 sp->freelist = b;
93770+ sp->private = 0;
93771 INIT_LIST_HEAD(&sp->list);
93772 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
93773 set_slob_page_free(sp, slob_list);
93774@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
93775 if (slob_page_free(sp))
93776 clear_slob_page_free(sp);
93777 spin_unlock_irqrestore(&slob_lock, flags);
93778- __ClearPageSlab(sp);
93779- page_mapcount_reset(sp);
93780- slob_free_pages(b, 0);
93781+ slob_free_pages(sp, 0);
93782 return;
93783 }
93784
93785+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93786+ if (pax_sanitize_slab)
93787+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
93788+#endif
93789+
93790 if (!slob_page_free(sp)) {
93791 /* This slob page is about to become partially free. Easy! */
93792 sp->units = units;
93793@@ -424,11 +431,10 @@ out:
93794 */
93795
93796 static __always_inline void *
93797-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93798+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
93799 {
93800- unsigned int *m;
93801- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93802- void *ret;
93803+ slob_t *m;
93804+ void *ret = NULL;
93805
93806 gfp &= gfp_allowed_mask;
93807
93808@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93809
93810 if (!m)
93811 return NULL;
93812- *m = size;
93813+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
93814+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
93815+ m[0].units = size;
93816+ m[1].units = align;
93817 ret = (void *)m + align;
93818
93819 trace_kmalloc_node(caller, ret,
93820 size, size + align, gfp, node);
93821 } else {
93822 unsigned int order = get_order(size);
93823+ struct page *page;
93824
93825 if (likely(order))
93826 gfp |= __GFP_COMP;
93827- ret = slob_new_pages(gfp, order, node);
93828+ page = slob_new_pages(gfp, order, node);
93829+ if (page) {
93830+ ret = page_address(page);
93831+ page->private = size;
93832+ }
93833
93834 trace_kmalloc_node(caller, ret,
93835 size, PAGE_SIZE << order, gfp, node);
93836 }
93837
93838- kmemleak_alloc(ret, size, 1, gfp);
93839+ return ret;
93840+}
93841+
93842+static __always_inline void *
93843+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93844+{
93845+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93846+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
93847+
93848+ if (!ZERO_OR_NULL_PTR(ret))
93849+ kmemleak_alloc(ret, size, 1, gfp);
93850 return ret;
93851 }
93852
93853@@ -493,34 +517,112 @@ void kfree(const void *block)
93854 return;
93855 kmemleak_free(block);
93856
93857+ VM_BUG_ON(!virt_addr_valid(block));
93858 sp = virt_to_page(block);
93859- if (PageSlab(sp)) {
93860+ VM_BUG_ON(!PageSlab(sp));
93861+ if (!sp->private) {
93862 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93863- unsigned int *m = (unsigned int *)(block - align);
93864- slob_free(m, *m + align);
93865- } else
93866+ slob_t *m = (slob_t *)(block - align);
93867+ slob_free(m, m[0].units + align);
93868+ } else {
93869+ __ClearPageSlab(sp);
93870+ page_mapcount_reset(sp);
93871+ sp->private = 0;
93872 __free_pages(sp, compound_order(sp));
93873+ }
93874 }
93875 EXPORT_SYMBOL(kfree);
93876
93877+bool is_usercopy_object(const void *ptr)
93878+{
93879+ if (!slab_is_available())
93880+ return false;
93881+
93882+ // PAX: TODO
93883+
93884+ return false;
93885+}
93886+
93887+#ifdef CONFIG_PAX_USERCOPY
93888+const char *check_heap_object(const void *ptr, unsigned long n)
93889+{
93890+ struct page *page;
93891+ const slob_t *free;
93892+ const void *base;
93893+ unsigned long flags;
93894+
93895+ if (ZERO_OR_NULL_PTR(ptr))
93896+ return "<null>";
93897+
93898+ if (!virt_addr_valid(ptr))
93899+ return NULL;
93900+
93901+ page = virt_to_head_page(ptr);
93902+ if (!PageSlab(page))
93903+ return NULL;
93904+
93905+ if (page->private) {
93906+ base = page;
93907+ if (base <= ptr && n <= page->private - (ptr - base))
93908+ return NULL;
93909+ return "<slob>";
93910+ }
93911+
93912+ /* some tricky double walking to find the chunk */
93913+ spin_lock_irqsave(&slob_lock, flags);
93914+ base = (void *)((unsigned long)ptr & PAGE_MASK);
93915+ free = page->freelist;
93916+
93917+ while (!slob_last(free) && (void *)free <= ptr) {
93918+ base = free + slob_units(free);
93919+ free = slob_next(free);
93920+ }
93921+
93922+ while (base < (void *)free) {
93923+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
93924+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
93925+ int offset;
93926+
93927+ if (ptr < base + align)
93928+ break;
93929+
93930+ offset = ptr - base - align;
93931+ if (offset >= m) {
93932+ base += size;
93933+ continue;
93934+ }
93935+
93936+ if (n > m - offset)
93937+ break;
93938+
93939+ spin_unlock_irqrestore(&slob_lock, flags);
93940+ return NULL;
93941+ }
93942+
93943+ spin_unlock_irqrestore(&slob_lock, flags);
93944+ return "<slob>";
93945+}
93946+#endif
93947+
93948 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
93949 size_t ksize(const void *block)
93950 {
93951 struct page *sp;
93952 int align;
93953- unsigned int *m;
93954+ slob_t *m;
93955
93956 BUG_ON(!block);
93957 if (unlikely(block == ZERO_SIZE_PTR))
93958 return 0;
93959
93960 sp = virt_to_page(block);
93961- if (unlikely(!PageSlab(sp)))
93962- return PAGE_SIZE << compound_order(sp);
93963+ VM_BUG_ON(!PageSlab(sp));
93964+ if (sp->private)
93965+ return sp->private;
93966
93967 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93968- m = (unsigned int *)(block - align);
93969- return SLOB_UNITS(*m) * SLOB_UNIT;
93970+ m = (slob_t *)(block - align);
93971+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
93972 }
93973 EXPORT_SYMBOL(ksize);
93974
93975@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
93976
93977 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
93978 {
93979- void *b;
93980+ void *b = NULL;
93981
93982 flags &= gfp_allowed_mask;
93983
93984 lockdep_trace_alloc(flags);
93985
93986+#ifdef CONFIG_PAX_USERCOPY_SLABS
93987+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
93988+#else
93989 if (c->size < PAGE_SIZE) {
93990 b = slob_alloc(c->size, flags, c->align, node);
93991 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
93992 SLOB_UNITS(c->size) * SLOB_UNIT,
93993 flags, node);
93994 } else {
93995- b = slob_new_pages(flags, get_order(c->size), node);
93996+ struct page *sp;
93997+
93998+ sp = slob_new_pages(flags, get_order(c->size), node);
93999+ if (sp) {
94000+ b = page_address(sp);
94001+ sp->private = c->size;
94002+ }
94003 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94004 PAGE_SIZE << get_order(c->size),
94005 flags, node);
94006 }
94007+#endif
94008
94009 if (b && c->ctor)
94010 c->ctor(b);
94011@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
94012
94013 static void __kmem_cache_free(void *b, int size)
94014 {
94015- if (size < PAGE_SIZE)
94016+ struct page *sp;
94017+
94018+ sp = virt_to_page(b);
94019+ BUG_ON(!PageSlab(sp));
94020+ if (!sp->private)
94021 slob_free(b, size);
94022 else
94023- slob_free_pages(b, get_order(size));
94024+ slob_free_pages(sp, get_order(size));
94025 }
94026
94027 static void kmem_rcu_free(struct rcu_head *head)
94028@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
94029
94030 void kmem_cache_free(struct kmem_cache *c, void *b)
94031 {
94032+ int size = c->size;
94033+
94034+#ifdef CONFIG_PAX_USERCOPY_SLABS
94035+ if (size + c->align < PAGE_SIZE) {
94036+ size += c->align;
94037+ b -= c->align;
94038+ }
94039+#endif
94040+
94041 kmemleak_free_recursive(b, c->flags);
94042 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
94043 struct slob_rcu *slob_rcu;
94044- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
94045- slob_rcu->size = c->size;
94046+ slob_rcu = b + (size - sizeof(struct slob_rcu));
94047+ slob_rcu->size = size;
94048 call_rcu(&slob_rcu->head, kmem_rcu_free);
94049 } else {
94050- __kmem_cache_free(b, c->size);
94051+ __kmem_cache_free(b, size);
94052 }
94053
94054+#ifdef CONFIG_PAX_USERCOPY_SLABS
94055+ trace_kfree(_RET_IP_, b);
94056+#else
94057 trace_kmem_cache_free(_RET_IP_, b);
94058+#endif
94059+
94060 }
94061 EXPORT_SYMBOL(kmem_cache_free);
94062
94063diff --git a/mm/slub.c b/mm/slub.c
94064index 545a170..a086226 100644
94065--- a/mm/slub.c
94066+++ b/mm/slub.c
94067@@ -207,7 +207,7 @@ struct track {
94068
94069 enum track_item { TRACK_ALLOC, TRACK_FREE };
94070
94071-#ifdef CONFIG_SYSFS
94072+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94073 static int sysfs_slab_add(struct kmem_cache *);
94074 static int sysfs_slab_alias(struct kmem_cache *, const char *);
94075 static void sysfs_slab_remove(struct kmem_cache *);
94076@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
94077 if (!t->addr)
94078 return;
94079
94080- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
94081+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
94082 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
94083 #ifdef CONFIG_STACKTRACE
94084 {
94085@@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
94086
94087 slab_free_hook(s, x);
94088
94089+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94090+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
94091+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
94092+ if (s->ctor)
94093+ s->ctor(x);
94094+ }
94095+#endif
94096+
94097 redo:
94098 /*
94099 * Determine the currently cpus per cpu slab.
94100@@ -2710,7 +2718,7 @@ static int slub_min_objects;
94101 * Merge control. If this is set then no merging of slab caches will occur.
94102 * (Could be removed. This was introduced to pacify the merge skeptics.)
94103 */
94104-static int slub_nomerge;
94105+static int slub_nomerge = 1;
94106
94107 /*
94108 * Calculate the order of allocation given an slab object size.
94109@@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
94110 s->inuse = size;
94111
94112 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
94113+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94114+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
94115+#endif
94116 s->ctor)) {
94117 /*
94118 * Relocate free pointer after the object if it is not
94119@@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
94120 EXPORT_SYMBOL(__kmalloc_node);
94121 #endif
94122
94123+bool is_usercopy_object(const void *ptr)
94124+{
94125+ struct page *page;
94126+ struct kmem_cache *s;
94127+
94128+ if (ZERO_OR_NULL_PTR(ptr))
94129+ return false;
94130+
94131+ if (!slab_is_available())
94132+ return false;
94133+
94134+ if (!virt_addr_valid(ptr))
94135+ return false;
94136+
94137+ page = virt_to_head_page(ptr);
94138+
94139+ if (!PageSlab(page))
94140+ return false;
94141+
94142+ s = page->slab_cache;
94143+ return s->flags & SLAB_USERCOPY;
94144+}
94145+
94146+#ifdef CONFIG_PAX_USERCOPY
94147+const char *check_heap_object(const void *ptr, unsigned long n)
94148+{
94149+ struct page *page;
94150+ struct kmem_cache *s;
94151+ unsigned long offset;
94152+
94153+ if (ZERO_OR_NULL_PTR(ptr))
94154+ return "<null>";
94155+
94156+ if (!virt_addr_valid(ptr))
94157+ return NULL;
94158+
94159+ page = virt_to_head_page(ptr);
94160+
94161+ if (!PageSlab(page))
94162+ return NULL;
94163+
94164+ s = page->slab_cache;
94165+ if (!(s->flags & SLAB_USERCOPY))
94166+ return s->name;
94167+
94168+ offset = (ptr - page_address(page)) % s->size;
94169+ if (offset <= s->object_size && n <= s->object_size - offset)
94170+ return NULL;
94171+
94172+ return s->name;
94173+}
94174+#endif
94175+
94176 size_t ksize(const void *object)
94177 {
94178 struct page *page;
94179@@ -3360,6 +3424,7 @@ void kfree(const void *x)
94180 if (unlikely(ZERO_OR_NULL_PTR(x)))
94181 return;
94182
94183+ VM_BUG_ON(!virt_addr_valid(x));
94184 page = virt_to_head_page(x);
94185 if (unlikely(!PageSlab(page))) {
94186 BUG_ON(!PageCompound(page));
94187@@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
94188 /*
94189 * We may have set a slab to be unmergeable during bootstrap.
94190 */
94191- if (s->refcount < 0)
94192+ if (atomic_read(&s->refcount) < 0)
94193 return 1;
94194
94195 return 0;
94196@@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94197
94198 s = find_mergeable(memcg, size, align, flags, name, ctor);
94199 if (s) {
94200- s->refcount++;
94201+ atomic_inc(&s->refcount);
94202 /*
94203 * Adjust the object sizes so that we clear
94204 * the complete object on kzalloc.
94205@@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94206 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
94207
94208 if (sysfs_slab_alias(s, name)) {
94209- s->refcount--;
94210+ atomic_dec(&s->refcount);
94211 s = NULL;
94212 }
94213 }
94214@@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
94215 }
94216 #endif
94217
94218-#ifdef CONFIG_SYSFS
94219+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94220 static int count_inuse(struct page *page)
94221 {
94222 return page->inuse;
94223@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
94224 validate_slab_cache(kmalloc_caches[9]);
94225 }
94226 #else
94227-#ifdef CONFIG_SYSFS
94228+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94229 static void resiliency_test(void) {};
94230 #endif
94231 #endif
94232
94233-#ifdef CONFIG_SYSFS
94234+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94235 enum slab_stat_type {
94236 SL_ALL, /* All slabs */
94237 SL_PARTIAL, /* Only partially allocated slabs */
94238@@ -4486,7 +4551,7 @@ SLAB_ATTR_RO(ctor);
94239
94240 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
94241 {
94242- return sprintf(buf, "%d\n", s->refcount - 1);
94243+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
94244 }
94245 SLAB_ATTR_RO(aliases);
94246
94247@@ -4574,6 +4639,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
94248 SLAB_ATTR_RO(cache_dma);
94249 #endif
94250
94251+#ifdef CONFIG_PAX_USERCOPY_SLABS
94252+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
94253+{
94254+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
94255+}
94256+SLAB_ATTR_RO(usercopy);
94257+#endif
94258+
94259 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
94260 {
94261 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
94262@@ -4908,6 +4981,9 @@ static struct attribute *slab_attrs[] = {
94263 #ifdef CONFIG_ZONE_DMA
94264 &cache_dma_attr.attr,
94265 #endif
94266+#ifdef CONFIG_PAX_USERCOPY_SLABS
94267+ &usercopy_attr.attr,
94268+#endif
94269 #ifdef CONFIG_NUMA
94270 &remote_node_defrag_ratio_attr.attr,
94271 #endif
94272@@ -5140,6 +5216,7 @@ static char *create_unique_id(struct kmem_cache *s)
94273 return name;
94274 }
94275
94276+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94277 static int sysfs_slab_add(struct kmem_cache *s)
94278 {
94279 int err;
94280@@ -5163,7 +5240,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
94281 }
94282
94283 s->kobj.kset = slab_kset;
94284- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
94285+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
94286 if (err) {
94287 kobject_put(&s->kobj);
94288 return err;
94289@@ -5197,6 +5274,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
94290 kobject_del(&s->kobj);
94291 kobject_put(&s->kobj);
94292 }
94293+#endif
94294
94295 /*
94296 * Need to buffer aliases during bootup until sysfs becomes
94297@@ -5210,6 +5288,7 @@ struct saved_alias {
94298
94299 static struct saved_alias *alias_list;
94300
94301+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94302 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94303 {
94304 struct saved_alias *al;
94305@@ -5232,6 +5311,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94306 alias_list = al;
94307 return 0;
94308 }
94309+#endif
94310
94311 static int __init slab_sysfs_init(void)
94312 {
94313diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
94314index 27eeab3..7c3f7f2 100644
94315--- a/mm/sparse-vmemmap.c
94316+++ b/mm/sparse-vmemmap.c
94317@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
94318 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94319 if (!p)
94320 return NULL;
94321- pud_populate(&init_mm, pud, p);
94322+ pud_populate_kernel(&init_mm, pud, p);
94323 }
94324 return pud;
94325 }
94326@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
94327 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94328 if (!p)
94329 return NULL;
94330- pgd_populate(&init_mm, pgd, p);
94331+ pgd_populate_kernel(&init_mm, pgd, p);
94332 }
94333 return pgd;
94334 }
94335diff --git a/mm/sparse.c b/mm/sparse.c
94336index 8cc7be0..d0f7d7a 100644
94337--- a/mm/sparse.c
94338+++ b/mm/sparse.c
94339@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
94340
94341 for (i = 0; i < PAGES_PER_SECTION; i++) {
94342 if (PageHWPoison(&memmap[i])) {
94343- atomic_long_sub(1, &num_poisoned_pages);
94344+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
94345 ClearPageHWPoison(&memmap[i]);
94346 }
94347 }
94348diff --git a/mm/swap.c b/mm/swap.c
94349index 84b26aa..ce39899 100644
94350--- a/mm/swap.c
94351+++ b/mm/swap.c
94352@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
94353
94354 __page_cache_release(page);
94355 dtor = get_compound_page_dtor(page);
94356+ if (!PageHuge(page))
94357+ BUG_ON(dtor != free_compound_page);
94358 (*dtor)(page);
94359 }
94360
94361diff --git a/mm/swapfile.c b/mm/swapfile.c
94362index 612a7c9..66b0f5a 100644
94363--- a/mm/swapfile.c
94364+++ b/mm/swapfile.c
94365@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
94366
94367 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
94368 /* Activity counter to indicate that a swapon or swapoff has occurred */
94369-static atomic_t proc_poll_event = ATOMIC_INIT(0);
94370+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
94371
94372 static inline unsigned char swap_count(unsigned char ent)
94373 {
94374@@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
94375 }
94376 filp_close(swap_file, NULL);
94377 err = 0;
94378- atomic_inc(&proc_poll_event);
94379+ atomic_inc_unchecked(&proc_poll_event);
94380 wake_up_interruptible(&proc_poll_wait);
94381
94382 out_dput:
94383@@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
94384
94385 poll_wait(file, &proc_poll_wait, wait);
94386
94387- if (seq->poll_event != atomic_read(&proc_poll_event)) {
94388- seq->poll_event = atomic_read(&proc_poll_event);
94389+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
94390+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94391 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
94392 }
94393
94394@@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
94395 return ret;
94396
94397 seq = file->private_data;
94398- seq->poll_event = atomic_read(&proc_poll_event);
94399+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94400 return 0;
94401 }
94402
94403@@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
94404 (frontswap_map) ? "FS" : "");
94405
94406 mutex_unlock(&swapon_mutex);
94407- atomic_inc(&proc_poll_event);
94408+ atomic_inc_unchecked(&proc_poll_event);
94409 wake_up_interruptible(&proc_poll_wait);
94410
94411 if (S_ISREG(inode->i_mode))
94412diff --git a/mm/util.c b/mm/util.c
94413index 808f375..e4764b5 100644
94414--- a/mm/util.c
94415+++ b/mm/util.c
94416@@ -297,6 +297,12 @@ done:
94417 void arch_pick_mmap_layout(struct mm_struct *mm)
94418 {
94419 mm->mmap_base = TASK_UNMAPPED_BASE;
94420+
94421+#ifdef CONFIG_PAX_RANDMMAP
94422+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94423+ mm->mmap_base += mm->delta_mmap;
94424+#endif
94425+
94426 mm->get_unmapped_area = arch_get_unmapped_area;
94427 }
94428 #endif
94429diff --git a/mm/vmalloc.c b/mm/vmalloc.c
94430index 0fdf968..d6686e8 100644
94431--- a/mm/vmalloc.c
94432+++ b/mm/vmalloc.c
94433@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
94434
94435 pte = pte_offset_kernel(pmd, addr);
94436 do {
94437- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94438- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94439+
94440+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94441+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
94442+ BUG_ON(!pte_exec(*pte));
94443+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
94444+ continue;
94445+ }
94446+#endif
94447+
94448+ {
94449+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94450+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94451+ }
94452 } while (pte++, addr += PAGE_SIZE, addr != end);
94453 }
94454
94455@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
94456 pte = pte_alloc_kernel(pmd, addr);
94457 if (!pte)
94458 return -ENOMEM;
94459+
94460+ pax_open_kernel();
94461 do {
94462 struct page *page = pages[*nr];
94463
94464- if (WARN_ON(!pte_none(*pte)))
94465+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94466+ if (pgprot_val(prot) & _PAGE_NX)
94467+#endif
94468+
94469+ if (!pte_none(*pte)) {
94470+ pax_close_kernel();
94471+ WARN_ON(1);
94472 return -EBUSY;
94473- if (WARN_ON(!page))
94474+ }
94475+ if (!page) {
94476+ pax_close_kernel();
94477+ WARN_ON(1);
94478 return -ENOMEM;
94479+ }
94480 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
94481 (*nr)++;
94482 } while (pte++, addr += PAGE_SIZE, addr != end);
94483+ pax_close_kernel();
94484 return 0;
94485 }
94486
94487@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
94488 pmd_t *pmd;
94489 unsigned long next;
94490
94491- pmd = pmd_alloc(&init_mm, pud, addr);
94492+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94493 if (!pmd)
94494 return -ENOMEM;
94495 do {
94496@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
94497 pud_t *pud;
94498 unsigned long next;
94499
94500- pud = pud_alloc(&init_mm, pgd, addr);
94501+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
94502 if (!pud)
94503 return -ENOMEM;
94504 do {
94505@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
94506 if (addr >= MODULES_VADDR && addr < MODULES_END)
94507 return 1;
94508 #endif
94509+
94510+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94511+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
94512+ return 1;
94513+#endif
94514+
94515 return is_vmalloc_addr(x);
94516 }
94517
94518@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
94519
94520 if (!pgd_none(*pgd)) {
94521 pud_t *pud = pud_offset(pgd, addr);
94522+#ifdef CONFIG_X86
94523+ if (!pud_large(*pud))
94524+#endif
94525 if (!pud_none(*pud)) {
94526 pmd_t *pmd = pmd_offset(pud, addr);
94527+#ifdef CONFIG_X86
94528+ if (!pmd_large(*pmd))
94529+#endif
94530 if (!pmd_none(*pmd)) {
94531 pte_t *ptep, pte;
94532
94533@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
94534 struct vm_struct *area;
94535
94536 BUG_ON(in_interrupt());
94537+
94538+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94539+ if (flags & VM_KERNEXEC) {
94540+ if (start != VMALLOC_START || end != VMALLOC_END)
94541+ return NULL;
94542+ start = (unsigned long)MODULES_EXEC_VADDR;
94543+ end = (unsigned long)MODULES_EXEC_END;
94544+ }
94545+#endif
94546+
94547 if (flags & VM_IOREMAP)
94548 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
94549
94550@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
94551 if (count > totalram_pages)
94552 return NULL;
94553
94554+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94555+ if (!(pgprot_val(prot) & _PAGE_NX))
94556+ flags |= VM_KERNEXEC;
94557+#endif
94558+
94559 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
94560 __builtin_return_address(0));
94561 if (!area)
94562@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
94563 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
94564 goto fail;
94565
94566+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94567+ if (!(pgprot_val(prot) & _PAGE_NX))
94568+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
94569+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
94570+ else
94571+#endif
94572+
94573 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
94574 start, end, node, gfp_mask, caller);
94575 if (!area)
94576@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
94577 * For tight control over page level allocator and protection flags
94578 * use __vmalloc() instead.
94579 */
94580-
94581 void *vmalloc_exec(unsigned long size)
94582 {
94583- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
94584+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
94585 NUMA_NO_NODE, __builtin_return_address(0));
94586 }
94587
94588@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
94589 {
94590 struct vm_struct *area;
94591
94592+ BUG_ON(vma->vm_mirror);
94593+
94594 size = PAGE_ALIGN(size);
94595
94596 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
94597@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
94598 v->addr, v->addr + v->size, v->size);
94599
94600 if (v->caller)
94601+#ifdef CONFIG_GRKERNSEC_HIDESYM
94602+ seq_printf(m, " %pK", v->caller);
94603+#else
94604 seq_printf(m, " %pS", v->caller);
94605+#endif
94606
94607 if (v->nr_pages)
94608 seq_printf(m, " pages=%d", v->nr_pages);
94609diff --git a/mm/vmstat.c b/mm/vmstat.c
94610index 7249614..2639fc7 100644
94611--- a/mm/vmstat.c
94612+++ b/mm/vmstat.c
94613@@ -20,6 +20,7 @@
94614 #include <linux/writeback.h>
94615 #include <linux/compaction.h>
94616 #include <linux/mm_inline.h>
94617+#include <linux/grsecurity.h>
94618
94619 #include "internal.h"
94620
94621@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
94622 *
94623 * vm_stat contains the global counters
94624 */
94625-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94626+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94627 EXPORT_SYMBOL(vm_stat);
94628
94629 #ifdef CONFIG_SMP
94630@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
94631
94632 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94633 if (diff[i])
94634- atomic_long_add(diff[i], &vm_stat[i]);
94635+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
94636 }
94637
94638 /*
94639@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
94640 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
94641 if (v) {
94642
94643- atomic_long_add(v, &zone->vm_stat[i]);
94644+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94645 global_diff[i] += v;
94646 #ifdef CONFIG_NUMA
94647 /* 3 seconds idle till flush */
94648@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
94649
94650 v = p->vm_stat_diff[i];
94651 p->vm_stat_diff[i] = 0;
94652- atomic_long_add(v, &zone->vm_stat[i]);
94653+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94654 global_diff[i] += v;
94655 }
94656 }
94657@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
94658 if (pset->vm_stat_diff[i]) {
94659 int v = pset->vm_stat_diff[i];
94660 pset->vm_stat_diff[i] = 0;
94661- atomic_long_add(v, &zone->vm_stat[i]);
94662- atomic_long_add(v, &vm_stat[i]);
94663+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94664+ atomic_long_add_unchecked(v, &vm_stat[i]);
94665 }
94666 }
94667 #endif
94668@@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
94669 stat_items_size += sizeof(struct vm_event_state);
94670 #endif
94671
94672- v = kmalloc(stat_items_size, GFP_KERNEL);
94673+ v = kzalloc(stat_items_size, GFP_KERNEL);
94674 m->private = v;
94675 if (!v)
94676 return ERR_PTR(-ENOMEM);
94677+
94678+#ifdef CONFIG_GRKERNSEC_PROC_ADD
94679+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94680+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
94681+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
94682+ && !in_group_p(grsec_proc_gid)
94683+#endif
94684+ )
94685+ return (unsigned long *)m->private + *pos;
94686+#endif
94687+#endif
94688+
94689 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94690 v[i] = global_page_state(i);
94691 v += NR_VM_ZONE_STAT_ITEMS;
94692@@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
94693 put_online_cpus();
94694 #endif
94695 #ifdef CONFIG_PROC_FS
94696- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
94697- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
94698- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94699- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
94700+ {
94701+ mode_t gr_mode = S_IRUGO;
94702+#ifdef CONFIG_GRKERNSEC_PROC_ADD
94703+ gr_mode = S_IRUSR;
94704+#endif
94705+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
94706+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
94707+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94708+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
94709+ }
94710 #endif
94711 return 0;
94712 }
94713diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
94714index b3d17d1..e8e4cdd 100644
94715--- a/net/8021q/vlan.c
94716+++ b/net/8021q/vlan.c
94717@@ -472,7 +472,7 @@ out:
94718 return NOTIFY_DONE;
94719 }
94720
94721-static struct notifier_block vlan_notifier_block __read_mostly = {
94722+static struct notifier_block vlan_notifier_block = {
94723 .notifier_call = vlan_device_event,
94724 };
94725
94726@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
94727 err = -EPERM;
94728 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
94729 break;
94730- if ((args.u.name_type >= 0) &&
94731- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
94732+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
94733 struct vlan_net *vn;
94734
94735 vn = net_generic(net, vlan_net_id);
94736diff --git a/net/9p/client.c b/net/9p/client.c
94737index ee8fd6b..0469d50 100644
94738--- a/net/9p/client.c
94739+++ b/net/9p/client.c
94740@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
94741 len - inline_len);
94742 } else {
94743 err = copy_from_user(ename + inline_len,
94744- uidata, len - inline_len);
94745+ (char __force_user *)uidata, len - inline_len);
94746 if (err) {
94747 err = -EFAULT;
94748 goto out_err;
94749@@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
94750 kernel_buf = 1;
94751 indata = data;
94752 } else
94753- indata = (__force char *)udata;
94754+ indata = (__force_kernel char *)udata;
94755 /*
94756 * response header len is 11
94757 * PDU Header(7) + IO Size (4)
94758@@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
94759 kernel_buf = 1;
94760 odata = data;
94761 } else
94762- odata = (char *)udata;
94763+ odata = (char __force_kernel *)udata;
94764 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
94765 P9_ZC_HDR_SZ, kernel_buf, "dqd",
94766 fid->fid, offset, rsize);
94767diff --git a/net/9p/mod.c b/net/9p/mod.c
94768index 6ab36ae..6f1841b 100644
94769--- a/net/9p/mod.c
94770+++ b/net/9p/mod.c
94771@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
94772 void v9fs_register_trans(struct p9_trans_module *m)
94773 {
94774 spin_lock(&v9fs_trans_lock);
94775- list_add_tail(&m->list, &v9fs_trans_list);
94776+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
94777 spin_unlock(&v9fs_trans_lock);
94778 }
94779 EXPORT_SYMBOL(v9fs_register_trans);
94780@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
94781 void v9fs_unregister_trans(struct p9_trans_module *m)
94782 {
94783 spin_lock(&v9fs_trans_lock);
94784- list_del_init(&m->list);
94785+ pax_list_del_init((struct list_head *)&m->list);
94786 spin_unlock(&v9fs_trans_lock);
94787 }
94788 EXPORT_SYMBOL(v9fs_unregister_trans);
94789diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
94790index 9321a77..ed2f256 100644
94791--- a/net/9p/trans_fd.c
94792+++ b/net/9p/trans_fd.c
94793@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
94794 oldfs = get_fs();
94795 set_fs(get_ds());
94796 /* The cast to a user pointer is valid due to the set_fs() */
94797- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
94798+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
94799 set_fs(oldfs);
94800
94801 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
94802diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
94803index 876fbe8..8bbea9f 100644
94804--- a/net/atm/atm_misc.c
94805+++ b/net/atm/atm_misc.c
94806@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
94807 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
94808 return 1;
94809 atm_return(vcc, truesize);
94810- atomic_inc(&vcc->stats->rx_drop);
94811+ atomic_inc_unchecked(&vcc->stats->rx_drop);
94812 return 0;
94813 }
94814 EXPORT_SYMBOL(atm_charge);
94815@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
94816 }
94817 }
94818 atm_return(vcc, guess);
94819- atomic_inc(&vcc->stats->rx_drop);
94820+ atomic_inc_unchecked(&vcc->stats->rx_drop);
94821 return NULL;
94822 }
94823 EXPORT_SYMBOL(atm_alloc_charge);
94824@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
94825
94826 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
94827 {
94828-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
94829+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
94830 __SONET_ITEMS
94831 #undef __HANDLE_ITEM
94832 }
94833@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
94834
94835 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
94836 {
94837-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
94838+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
94839 __SONET_ITEMS
94840 #undef __HANDLE_ITEM
94841 }
94842diff --git a/net/atm/lec.c b/net/atm/lec.c
94843index f23916b..dd4d26b 100644
94844--- a/net/atm/lec.c
94845+++ b/net/atm/lec.c
94846@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
94847 }
94848
94849 static struct lane2_ops lane2_ops = {
94850- lane2_resolve, /* resolve, spec 3.1.3 */
94851- lane2_associate_req, /* associate_req, spec 3.1.4 */
94852- NULL /* associate indicator, spec 3.1.5 */
94853+ .resolve = lane2_resolve,
94854+ .associate_req = lane2_associate_req,
94855+ .associate_indicator = NULL
94856 };
94857
94858 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
94859diff --git a/net/atm/lec.h b/net/atm/lec.h
94860index 4149db1..f2ab682 100644
94861--- a/net/atm/lec.h
94862+++ b/net/atm/lec.h
94863@@ -48,7 +48,7 @@ struct lane2_ops {
94864 const u8 *tlvs, u32 sizeoftlvs);
94865 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
94866 const u8 *tlvs, u32 sizeoftlvs);
94867-};
94868+} __no_const;
94869
94870 /*
94871 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
94872diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
94873index d1b2d9a..d549f7f 100644
94874--- a/net/atm/mpoa_caches.c
94875+++ b/net/atm/mpoa_caches.c
94876@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
94877
94878
94879 static struct in_cache_ops ingress_ops = {
94880- in_cache_add_entry, /* add_entry */
94881- in_cache_get, /* get */
94882- in_cache_get_with_mask, /* get_with_mask */
94883- in_cache_get_by_vcc, /* get_by_vcc */
94884- in_cache_put, /* put */
94885- in_cache_remove_entry, /* remove_entry */
94886- cache_hit, /* cache_hit */
94887- clear_count_and_expired, /* clear_count */
94888- check_resolving_entries, /* check_resolving */
94889- refresh_entries, /* refresh */
94890- in_destroy_cache /* destroy_cache */
94891+ .add_entry = in_cache_add_entry,
94892+ .get = in_cache_get,
94893+ .get_with_mask = in_cache_get_with_mask,
94894+ .get_by_vcc = in_cache_get_by_vcc,
94895+ .put = in_cache_put,
94896+ .remove_entry = in_cache_remove_entry,
94897+ .cache_hit = cache_hit,
94898+ .clear_count = clear_count_and_expired,
94899+ .check_resolving = check_resolving_entries,
94900+ .refresh = refresh_entries,
94901+ .destroy_cache = in_destroy_cache
94902 };
94903
94904 static struct eg_cache_ops egress_ops = {
94905- eg_cache_add_entry, /* add_entry */
94906- eg_cache_get_by_cache_id, /* get_by_cache_id */
94907- eg_cache_get_by_tag, /* get_by_tag */
94908- eg_cache_get_by_vcc, /* get_by_vcc */
94909- eg_cache_get_by_src_ip, /* get_by_src_ip */
94910- eg_cache_put, /* put */
94911- eg_cache_remove_entry, /* remove_entry */
94912- update_eg_cache_entry, /* update */
94913- clear_expired, /* clear_expired */
94914- eg_destroy_cache /* destroy_cache */
94915+ .add_entry = eg_cache_add_entry,
94916+ .get_by_cache_id = eg_cache_get_by_cache_id,
94917+ .get_by_tag = eg_cache_get_by_tag,
94918+ .get_by_vcc = eg_cache_get_by_vcc,
94919+ .get_by_src_ip = eg_cache_get_by_src_ip,
94920+ .put = eg_cache_put,
94921+ .remove_entry = eg_cache_remove_entry,
94922+ .update = update_eg_cache_entry,
94923+ .clear_expired = clear_expired,
94924+ .destroy_cache = eg_destroy_cache
94925 };
94926
94927
94928diff --git a/net/atm/proc.c b/net/atm/proc.c
94929index bbb6461..cf04016 100644
94930--- a/net/atm/proc.c
94931+++ b/net/atm/proc.c
94932@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
94933 const struct k_atm_aal_stats *stats)
94934 {
94935 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
94936- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
94937- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
94938- atomic_read(&stats->rx_drop));
94939+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
94940+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
94941+ atomic_read_unchecked(&stats->rx_drop));
94942 }
94943
94944 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
94945diff --git a/net/atm/resources.c b/net/atm/resources.c
94946index 0447d5d..3cf4728 100644
94947--- a/net/atm/resources.c
94948+++ b/net/atm/resources.c
94949@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
94950 static void copy_aal_stats(struct k_atm_aal_stats *from,
94951 struct atm_aal_stats *to)
94952 {
94953-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
94954+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
94955 __AAL_STAT_ITEMS
94956 #undef __HANDLE_ITEM
94957 }
94958@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
94959 static void subtract_aal_stats(struct k_atm_aal_stats *from,
94960 struct atm_aal_stats *to)
94961 {
94962-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
94963+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
94964 __AAL_STAT_ITEMS
94965 #undef __HANDLE_ITEM
94966 }
94967diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
94968index 919a5ce..cc6b444 100644
94969--- a/net/ax25/sysctl_net_ax25.c
94970+++ b/net/ax25/sysctl_net_ax25.c
94971@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
94972 {
94973 char path[sizeof("net/ax25/") + IFNAMSIZ];
94974 int k;
94975- struct ctl_table *table;
94976+ ctl_table_no_const *table;
94977
94978 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
94979 if (!table)
94980diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
94981index b9c8a6e..ed0f711 100644
94982--- a/net/batman-adv/bat_iv_ogm.c
94983+++ b/net/batman-adv/bat_iv_ogm.c
94984@@ -297,7 +297,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
94985
94986 /* randomize initial seqno to avoid collision */
94987 get_random_bytes(&random_seqno, sizeof(random_seqno));
94988- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
94989+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
94990
94991 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
94992 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
94993@@ -884,9 +884,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
94994 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
94995
94996 /* change sequence number to network order */
94997- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
94998+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
94999 batadv_ogm_packet->seqno = htonl(seqno);
95000- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
95001+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
95002
95003 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
95004 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
95005@@ -1251,7 +1251,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
95006 return;
95007
95008 /* could be changed by schedule_own_packet() */
95009- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
95010+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
95011
95012 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
95013 has_directlink_flag = 1;
95014diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
95015index 6ddb614..ca7e886 100644
95016--- a/net/batman-adv/fragmentation.c
95017+++ b/net/batman-adv/fragmentation.c
95018@@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
95019 frag_header.packet_type = BATADV_UNICAST_FRAG;
95020 frag_header.version = BATADV_COMPAT_VERSION;
95021 frag_header.ttl = BATADV_TTL;
95022- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
95023+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
95024 frag_header.reserved = 0;
95025 frag_header.no = 0;
95026 frag_header.total_size = htons(skb->len);
95027diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
95028index a8f99d1..11797ef 100644
95029--- a/net/batman-adv/soft-interface.c
95030+++ b/net/batman-adv/soft-interface.c
95031@@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
95032 primary_if->net_dev->dev_addr, ETH_ALEN);
95033
95034 /* set broadcast sequence number */
95035- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
95036+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
95037 bcast_packet->seqno = htonl(seqno);
95038
95039 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
95040@@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95041 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
95042
95043 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
95044- atomic_set(&bat_priv->bcast_seqno, 1);
95045+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
95046 atomic_set(&bat_priv->tt.vn, 0);
95047 atomic_set(&bat_priv->tt.local_changes, 0);
95048 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
95049@@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95050
95051 /* randomize initial seqno to avoid collision */
95052 get_random_bytes(&random_seqno, sizeof(random_seqno));
95053- atomic_set(&bat_priv->frag_seqno, random_seqno);
95054+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
95055
95056 bat_priv->primary_if = NULL;
95057 bat_priv->num_ifaces = 0;
95058diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
95059index 91dd369..9c25750 100644
95060--- a/net/batman-adv/types.h
95061+++ b/net/batman-adv/types.h
95062@@ -56,7 +56,7 @@
95063 struct batadv_hard_iface_bat_iv {
95064 unsigned char *ogm_buff;
95065 int ogm_buff_len;
95066- atomic_t ogm_seqno;
95067+ atomic_unchecked_t ogm_seqno;
95068 };
95069
95070 /**
95071@@ -673,7 +673,7 @@ struct batadv_priv {
95072 atomic_t bonding;
95073 atomic_t fragmentation;
95074 atomic_t packet_size_max;
95075- atomic_t frag_seqno;
95076+ atomic_unchecked_t frag_seqno;
95077 #ifdef CONFIG_BATMAN_ADV_BLA
95078 atomic_t bridge_loop_avoidance;
95079 #endif
95080@@ -687,7 +687,7 @@ struct batadv_priv {
95081 #ifdef CONFIG_BATMAN_ADV_DEBUG
95082 atomic_t log_level;
95083 #endif
95084- atomic_t bcast_seqno;
95085+ atomic_unchecked_t bcast_seqno;
95086 atomic_t bcast_queue_left;
95087 atomic_t batman_queue_left;
95088 char num_ifaces;
95089diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
95090index 7552f9e..074ce29 100644
95091--- a/net/bluetooth/hci_sock.c
95092+++ b/net/bluetooth/hci_sock.c
95093@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
95094 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
95095 }
95096
95097- len = min_t(unsigned int, len, sizeof(uf));
95098+ len = min((size_t)len, sizeof(uf));
95099 if (copy_from_user(&uf, optval, len)) {
95100 err = -EFAULT;
95101 break;
95102diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
95103index 4af3821..f2ba46c 100644
95104--- a/net/bluetooth/l2cap_core.c
95105+++ b/net/bluetooth/l2cap_core.c
95106@@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
95107 break;
95108
95109 case L2CAP_CONF_RFC:
95110- if (olen == sizeof(rfc))
95111- memcpy(&rfc, (void *)val, olen);
95112+ if (olen != sizeof(rfc))
95113+ break;
95114+
95115+ memcpy(&rfc, (void *)val, olen);
95116
95117 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
95118 rfc.mode != chan->mode)
95119diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
95120index 7cc24d2..e83f531 100644
95121--- a/net/bluetooth/l2cap_sock.c
95122+++ b/net/bluetooth/l2cap_sock.c
95123@@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95124 struct sock *sk = sock->sk;
95125 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
95126 struct l2cap_options opts;
95127- int len, err = 0;
95128+ int err = 0;
95129+ size_t len = optlen;
95130 u32 opt;
95131
95132 BT_DBG("sk %p", sk);
95133@@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95134 opts.max_tx = chan->max_tx;
95135 opts.txwin_size = chan->tx_win;
95136
95137- len = min_t(unsigned int, sizeof(opts), optlen);
95138+ len = min(sizeof(opts), len);
95139 if (copy_from_user((char *) &opts, optval, len)) {
95140 err = -EFAULT;
95141 break;
95142@@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95143 struct bt_security sec;
95144 struct bt_power pwr;
95145 struct l2cap_conn *conn;
95146- int len, err = 0;
95147+ int err = 0;
95148+ size_t len = optlen;
95149 u32 opt;
95150
95151 BT_DBG("sk %p", sk);
95152@@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95153
95154 sec.level = BT_SECURITY_LOW;
95155
95156- len = min_t(unsigned int, sizeof(sec), optlen);
95157+ len = min(sizeof(sec), len);
95158 if (copy_from_user((char *) &sec, optval, len)) {
95159 err = -EFAULT;
95160 break;
95161@@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95162
95163 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
95164
95165- len = min_t(unsigned int, sizeof(pwr), optlen);
95166+ len = min(sizeof(pwr), len);
95167 if (copy_from_user((char *) &pwr, optval, len)) {
95168 err = -EFAULT;
95169 break;
95170diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
95171index 3c2d3e4..884855a 100644
95172--- a/net/bluetooth/rfcomm/sock.c
95173+++ b/net/bluetooth/rfcomm/sock.c
95174@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95175 struct sock *sk = sock->sk;
95176 struct bt_security sec;
95177 int err = 0;
95178- size_t len;
95179+ size_t len = optlen;
95180 u32 opt;
95181
95182 BT_DBG("sk %p", sk);
95183@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95184
95185 sec.level = BT_SECURITY_LOW;
95186
95187- len = min_t(unsigned int, sizeof(sec), optlen);
95188+ len = min(sizeof(sec), len);
95189 if (copy_from_user((char *) &sec, optval, len)) {
95190 err = -EFAULT;
95191 break;
95192diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
95193index 84fcf9f..e389b27 100644
95194--- a/net/bluetooth/rfcomm/tty.c
95195+++ b/net/bluetooth/rfcomm/tty.c
95196@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
95197 BT_DBG("tty %p id %d", tty, tty->index);
95198
95199 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
95200- dev->channel, dev->port.count);
95201+ dev->channel, atomic_read(&dev->port.count));
95202
95203 err = tty_port_open(&dev->port, tty, filp);
95204 if (err)
95205@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
95206 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
95207
95208 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
95209- dev->port.count);
95210+ atomic_read(&dev->port.count));
95211
95212 tty_port_close(&dev->port, tty, filp);
95213 }
95214diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
95215index ac78024..161a80c 100644
95216--- a/net/bridge/netfilter/ebtables.c
95217+++ b/net/bridge/netfilter/ebtables.c
95218@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95219 tmp.valid_hooks = t->table->valid_hooks;
95220 }
95221 mutex_unlock(&ebt_mutex);
95222- if (copy_to_user(user, &tmp, *len) != 0){
95223+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
95224 BUGPRINT("c2u Didn't work\n");
95225 ret = -EFAULT;
95226 break;
95227@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95228 goto out;
95229 tmp.valid_hooks = t->valid_hooks;
95230
95231- if (copy_to_user(user, &tmp, *len) != 0) {
95232+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95233 ret = -EFAULT;
95234 break;
95235 }
95236@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95237 tmp.entries_size = t->table->entries_size;
95238 tmp.valid_hooks = t->table->valid_hooks;
95239
95240- if (copy_to_user(user, &tmp, *len) != 0) {
95241+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95242 ret = -EFAULT;
95243 break;
95244 }
95245diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
95246index 0f45522..dab651f 100644
95247--- a/net/caif/cfctrl.c
95248+++ b/net/caif/cfctrl.c
95249@@ -10,6 +10,7 @@
95250 #include <linux/spinlock.h>
95251 #include <linux/slab.h>
95252 #include <linux/pkt_sched.h>
95253+#include <linux/sched.h>
95254 #include <net/caif/caif_layer.h>
95255 #include <net/caif/cfpkt.h>
95256 #include <net/caif/cfctrl.h>
95257@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
95258 memset(&dev_info, 0, sizeof(dev_info));
95259 dev_info.id = 0xff;
95260 cfsrvl_init(&this->serv, 0, &dev_info, false);
95261- atomic_set(&this->req_seq_no, 1);
95262- atomic_set(&this->rsp_seq_no, 1);
95263+ atomic_set_unchecked(&this->req_seq_no, 1);
95264+ atomic_set_unchecked(&this->rsp_seq_no, 1);
95265 this->serv.layer.receive = cfctrl_recv;
95266 sprintf(this->serv.layer.name, "ctrl");
95267 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
95268@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
95269 struct cfctrl_request_info *req)
95270 {
95271 spin_lock_bh(&ctrl->info_list_lock);
95272- atomic_inc(&ctrl->req_seq_no);
95273- req->sequence_no = atomic_read(&ctrl->req_seq_no);
95274+ atomic_inc_unchecked(&ctrl->req_seq_no);
95275+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
95276 list_add_tail(&req->list, &ctrl->list);
95277 spin_unlock_bh(&ctrl->info_list_lock);
95278 }
95279@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
95280 if (p != first)
95281 pr_warn("Requests are not received in order\n");
95282
95283- atomic_set(&ctrl->rsp_seq_no,
95284+ atomic_set_unchecked(&ctrl->rsp_seq_no,
95285 p->sequence_no);
95286 list_del(&p->list);
95287 goto out;
95288diff --git a/net/can/af_can.c b/net/can/af_can.c
95289index d249874..99e197b 100644
95290--- a/net/can/af_can.c
95291+++ b/net/can/af_can.c
95292@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
95293 };
95294
95295 /* notifier block for netdevice event */
95296-static struct notifier_block can_netdev_notifier __read_mostly = {
95297+static struct notifier_block can_netdev_notifier = {
95298 .notifier_call = can_notifier,
95299 };
95300
95301diff --git a/net/can/gw.c b/net/can/gw.c
95302index 3f9b0f3..fc6d4fa 100644
95303--- a/net/can/gw.c
95304+++ b/net/can/gw.c
95305@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
95306 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
95307
95308 static HLIST_HEAD(cgw_list);
95309-static struct notifier_block notifier;
95310
95311 static struct kmem_cache *cgw_cache __read_mostly;
95312
95313@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
95314 return err;
95315 }
95316
95317+static struct notifier_block notifier = {
95318+ .notifier_call = cgw_notifier
95319+};
95320+
95321 static __init int cgw_module_init(void)
95322 {
95323 /* sanitize given module parameter */
95324@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
95325 return -ENOMEM;
95326
95327 /* set notifier */
95328- notifier.notifier_call = cgw_notifier;
95329 register_netdevice_notifier(&notifier);
95330
95331 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
95332diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
95333index 4a5df7b..9ad1f1d 100644
95334--- a/net/ceph/messenger.c
95335+++ b/net/ceph/messenger.c
95336@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
95337 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
95338
95339 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
95340-static atomic_t addr_str_seq = ATOMIC_INIT(0);
95341+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
95342
95343 static struct page *zero_page; /* used in certain error cases */
95344
95345@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
95346 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
95347 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
95348
95349- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95350+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95351 s = addr_str[i];
95352
95353 switch (ss->ss_family) {
95354diff --git a/net/compat.c b/net/compat.c
95355index dd32e34..0529c9c 100644
95356--- a/net/compat.c
95357+++ b/net/compat.c
95358@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
95359 return -EFAULT;
95360 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
95361 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
95362- kmsg->msg_name = compat_ptr(tmp1);
95363- kmsg->msg_iov = compat_ptr(tmp2);
95364- kmsg->msg_control = compat_ptr(tmp3);
95365+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
95366+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
95367+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
95368 return 0;
95369 }
95370
95371@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95372
95373 if (kern_msg->msg_namelen) {
95374 if (mode == VERIFY_READ) {
95375- int err = move_addr_to_kernel(kern_msg->msg_name,
95376+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
95377 kern_msg->msg_namelen,
95378 kern_address);
95379 if (err < 0)
95380@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95381 kern_msg->msg_name = NULL;
95382
95383 tot_len = iov_from_user_compat_to_kern(kern_iov,
95384- (struct compat_iovec __user *)kern_msg->msg_iov,
95385+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
95386 kern_msg->msg_iovlen);
95387 if (tot_len >= 0)
95388 kern_msg->msg_iov = kern_iov;
95389@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95390
95391 #define CMSG_COMPAT_FIRSTHDR(msg) \
95392 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
95393- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
95394+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
95395 (struct compat_cmsghdr __user *)NULL)
95396
95397 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
95398 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
95399 (ucmlen) <= (unsigned long) \
95400 ((mhdr)->msg_controllen - \
95401- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
95402+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
95403
95404 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
95405 struct compat_cmsghdr __user *cmsg, int cmsg_len)
95406 {
95407 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
95408- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
95409+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
95410 msg->msg_controllen)
95411 return NULL;
95412 return (struct compat_cmsghdr __user *)ptr;
95413@@ -222,7 +222,7 @@ Efault:
95414
95415 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
95416 {
95417- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95418+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95419 struct compat_cmsghdr cmhdr;
95420 struct compat_timeval ctv;
95421 struct compat_timespec cts[3];
95422@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
95423
95424 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
95425 {
95426- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95427+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95428 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
95429 int fdnum = scm->fp->count;
95430 struct file **fp = scm->fp->fp;
95431@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
95432 return -EFAULT;
95433 old_fs = get_fs();
95434 set_fs(KERNEL_DS);
95435- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
95436+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
95437 set_fs(old_fs);
95438
95439 return err;
95440@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
95441 len = sizeof(ktime);
95442 old_fs = get_fs();
95443 set_fs(KERNEL_DS);
95444- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
95445+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
95446 set_fs(old_fs);
95447
95448 if (!err) {
95449@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95450 case MCAST_JOIN_GROUP:
95451 case MCAST_LEAVE_GROUP:
95452 {
95453- struct compat_group_req __user *gr32 = (void *)optval;
95454+ struct compat_group_req __user *gr32 = (void __user *)optval;
95455 struct group_req __user *kgr =
95456 compat_alloc_user_space(sizeof(struct group_req));
95457 u32 interface;
95458@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95459 case MCAST_BLOCK_SOURCE:
95460 case MCAST_UNBLOCK_SOURCE:
95461 {
95462- struct compat_group_source_req __user *gsr32 = (void *)optval;
95463+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
95464 struct group_source_req __user *kgsr = compat_alloc_user_space(
95465 sizeof(struct group_source_req));
95466 u32 interface;
95467@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95468 }
95469 case MCAST_MSFILTER:
95470 {
95471- struct compat_group_filter __user *gf32 = (void *)optval;
95472+ struct compat_group_filter __user *gf32 = (void __user *)optval;
95473 struct group_filter __user *kgf;
95474 u32 interface, fmode, numsrc;
95475
95476@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
95477 char __user *optval, int __user *optlen,
95478 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
95479 {
95480- struct compat_group_filter __user *gf32 = (void *)optval;
95481+ struct compat_group_filter __user *gf32 = (void __user *)optval;
95482 struct group_filter __user *kgf;
95483 int __user *koptlen;
95484 u32 interface, fmode, numsrc;
95485@@ -783,7 +783,7 @@ asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
95486 if (COMPAT_USE_64BIT_TIME)
95487 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
95488 flags | MSG_CMSG_COMPAT,
95489- (struct timespec *) timeout);
95490+ (struct timespec __force_kernel *) timeout);
95491
95492 if (timeout == NULL)
95493 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
95494@@ -808,7 +808,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
95495
95496 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
95497 return -EINVAL;
95498- if (copy_from_user(a, args, nas[call]))
95499+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
95500 return -EFAULT;
95501 a0 = a[0];
95502 a1 = a[1];
95503diff --git a/net/core/datagram.c b/net/core/datagram.c
95504index a16ed7b..eb44d17 100644
95505--- a/net/core/datagram.c
95506+++ b/net/core/datagram.c
95507@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
95508 }
95509
95510 kfree_skb(skb);
95511- atomic_inc(&sk->sk_drops);
95512+ atomic_inc_unchecked(&sk->sk_drops);
95513 sk_mem_reclaim_partial(sk);
95514
95515 return err;
95516diff --git a/net/core/dev.c b/net/core/dev.c
95517index 0ce469e..dfb53d2 100644
95518--- a/net/core/dev.c
95519+++ b/net/core/dev.c
95520@@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
95521 {
95522 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
95523 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
95524- atomic_long_inc(&dev->rx_dropped);
95525+ atomic_long_inc_unchecked(&dev->rx_dropped);
95526 kfree_skb(skb);
95527 return NET_RX_DROP;
95528 }
95529 }
95530
95531 if (unlikely(!is_skb_forwardable(dev, skb))) {
95532- atomic_long_inc(&dev->rx_dropped);
95533+ atomic_long_inc_unchecked(&dev->rx_dropped);
95534 kfree_skb(skb);
95535 return NET_RX_DROP;
95536 }
95537@@ -2434,7 +2434,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
95538
95539 struct dev_gso_cb {
95540 void (*destructor)(struct sk_buff *skb);
95541-};
95542+} __no_const;
95543
95544 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
95545
95546@@ -3222,7 +3222,7 @@ enqueue:
95547
95548 local_irq_restore(flags);
95549
95550- atomic_long_inc(&skb->dev->rx_dropped);
95551+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95552 kfree_skb(skb);
95553 return NET_RX_DROP;
95554 }
95555@@ -3294,7 +3294,7 @@ int netif_rx_ni(struct sk_buff *skb)
95556 }
95557 EXPORT_SYMBOL(netif_rx_ni);
95558
95559-static void net_tx_action(struct softirq_action *h)
95560+static __latent_entropy void net_tx_action(void)
95561 {
95562 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95563
95564@@ -3628,7 +3628,7 @@ ncls:
95565 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
95566 } else {
95567 drop:
95568- atomic_long_inc(&skb->dev->rx_dropped);
95569+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95570 kfree_skb(skb);
95571 /* Jamal, now you will not able to escape explaining
95572 * me how you were going to use this. :-)
95573@@ -4288,7 +4288,7 @@ void netif_napi_del(struct napi_struct *napi)
95574 }
95575 EXPORT_SYMBOL(netif_napi_del);
95576
95577-static void net_rx_action(struct softirq_action *h)
95578+static __latent_entropy void net_rx_action(void)
95579 {
95580 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95581 unsigned long time_limit = jiffies + 2;
95582@@ -6177,7 +6177,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
95583 } else {
95584 netdev_stats_to_stats64(storage, &dev->stats);
95585 }
95586- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
95587+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
95588 return storage;
95589 }
95590 EXPORT_SYMBOL(dev_get_stats);
95591diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
95592index 5b7d0e1..cb960fc 100644
95593--- a/net/core/dev_ioctl.c
95594+++ b/net/core/dev_ioctl.c
95595@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
95596 if (no_module && capable(CAP_NET_ADMIN))
95597 no_module = request_module("netdev-%s", name);
95598 if (no_module && capable(CAP_SYS_MODULE)) {
95599+#ifdef CONFIG_GRKERNSEC_MODHARDEN
95600+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
95601+#else
95602 if (!request_module("%s", name))
95603 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
95604 name);
95605+#endif
95606 }
95607 }
95608 EXPORT_SYMBOL(dev_load);
95609diff --git a/net/core/filter.c b/net/core/filter.c
95610index ad30d62..c2757df 100644
95611--- a/net/core/filter.c
95612+++ b/net/core/filter.c
95613@@ -679,7 +679,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
95614 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
95615 if (!fp)
95616 return -ENOMEM;
95617- memcpy(fp->insns, fprog->filter, fsize);
95618+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
95619
95620 atomic_set(&fp->refcnt, 1);
95621 fp->len = fprog->len;
95622diff --git a/net/core/flow.c b/net/core/flow.c
95623index dfa602c..3103d88 100644
95624--- a/net/core/flow.c
95625+++ b/net/core/flow.c
95626@@ -61,7 +61,7 @@ struct flow_cache {
95627 struct timer_list rnd_timer;
95628 };
95629
95630-atomic_t flow_cache_genid = ATOMIC_INIT(0);
95631+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
95632 EXPORT_SYMBOL(flow_cache_genid);
95633 static struct flow_cache flow_cache_global;
95634 static struct kmem_cache *flow_cachep __read_mostly;
95635@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
95636
95637 static int flow_entry_valid(struct flow_cache_entry *fle)
95638 {
95639- if (atomic_read(&flow_cache_genid) != fle->genid)
95640+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
95641 return 0;
95642 if (fle->object && !fle->object->ops->check(fle->object))
95643 return 0;
95644@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
95645 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
95646 fcp->hash_count++;
95647 }
95648- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
95649+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
95650 flo = fle->object;
95651 if (!flo)
95652 goto ret_object;
95653@@ -279,7 +279,7 @@ nocache:
95654 }
95655 flo = resolver(net, key, family, dir, flo, ctx);
95656 if (fle) {
95657- fle->genid = atomic_read(&flow_cache_genid);
95658+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
95659 if (!IS_ERR(flo))
95660 fle->object = flo;
95661 else
95662diff --git a/net/core/iovec.c b/net/core/iovec.c
95663index b618694..192bbba 100644
95664--- a/net/core/iovec.c
95665+++ b/net/core/iovec.c
95666@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95667 if (m->msg_namelen) {
95668 if (mode == VERIFY_READ) {
95669 void __user *namep;
95670- namep = (void __user __force *) m->msg_name;
95671+ namep = (void __force_user *) m->msg_name;
95672 err = move_addr_to_kernel(namep, m->msg_namelen,
95673 address);
95674 if (err < 0)
95675@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95676 }
95677
95678 size = m->msg_iovlen * sizeof(struct iovec);
95679- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
95680+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
95681 return -EFAULT;
95682
95683 m->msg_iov = iov;
95684diff --git a/net/core/neighbour.c b/net/core/neighbour.c
95685index 932c6d7..7c7aa10 100644
95686--- a/net/core/neighbour.c
95687+++ b/net/core/neighbour.c
95688@@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
95689 void __user *buffer, size_t *lenp, loff_t *ppos)
95690 {
95691 int size, ret;
95692- struct ctl_table tmp = *ctl;
95693+ ctl_table_no_const tmp = *ctl;
95694
95695 tmp.extra1 = &zero;
95696 tmp.extra2 = &unres_qlen_max;
95697diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
95698index 2bf8329..7960607 100644
95699--- a/net/core/net-procfs.c
95700+++ b/net/core/net-procfs.c
95701@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
95702 else
95703 seq_printf(seq, "%04x", ntohs(pt->type));
95704
95705+#ifdef CONFIG_GRKERNSEC_HIDESYM
95706+ seq_printf(seq, " %-8s %pf\n",
95707+ pt->dev ? pt->dev->name : "", NULL);
95708+#else
95709 seq_printf(seq, " %-8s %pf\n",
95710 pt->dev ? pt->dev->name : "", pt->func);
95711+#endif
95712 }
95713
95714 return 0;
95715diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
95716index f3edf96..3cd8b40 100644
95717--- a/net/core/net-sysfs.c
95718+++ b/net/core/net-sysfs.c
95719@@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
95720 }
95721 EXPORT_SYMBOL(netdev_class_remove_file_ns);
95722
95723-int netdev_kobject_init(void)
95724+int __init netdev_kobject_init(void)
95725 {
95726 kobj_ns_type_register(&net_ns_type_operations);
95727 return class_register(&net_class);
95728diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
95729index 81d3a9a..a0bd7a8 100644
95730--- a/net/core/net_namespace.c
95731+++ b/net/core/net_namespace.c
95732@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
95733 int error;
95734 LIST_HEAD(net_exit_list);
95735
95736- list_add_tail(&ops->list, list);
95737+ pax_list_add_tail((struct list_head *)&ops->list, list);
95738 if (ops->init || (ops->id && ops->size)) {
95739 for_each_net(net) {
95740 error = ops_init(ops, net);
95741@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
95742
95743 out_undo:
95744 /* If I have an error cleanup all namespaces I initialized */
95745- list_del(&ops->list);
95746+ pax_list_del((struct list_head *)&ops->list);
95747 ops_exit_list(ops, &net_exit_list);
95748 ops_free_list(ops, &net_exit_list);
95749 return error;
95750@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
95751 struct net *net;
95752 LIST_HEAD(net_exit_list);
95753
95754- list_del(&ops->list);
95755+ pax_list_del((struct list_head *)&ops->list);
95756 for_each_net(net)
95757 list_add_tail(&net->exit_list, &net_exit_list);
95758 ops_exit_list(ops, &net_exit_list);
95759@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
95760 mutex_lock(&net_mutex);
95761 error = register_pernet_operations(&pernet_list, ops);
95762 if (!error && (first_device == &pernet_list))
95763- first_device = &ops->list;
95764+ first_device = (struct list_head *)&ops->list;
95765 mutex_unlock(&net_mutex);
95766 return error;
95767 }
95768diff --git a/net/core/netpoll.c b/net/core/netpoll.c
95769index 19fe9c7..b6bb620 100644
95770--- a/net/core/netpoll.c
95771+++ b/net/core/netpoll.c
95772@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
95773 struct udphdr *udph;
95774 struct iphdr *iph;
95775 struct ethhdr *eth;
95776- static atomic_t ip_ident;
95777+ static atomic_unchecked_t ip_ident;
95778 struct ipv6hdr *ip6h;
95779
95780 udp_len = len + sizeof(*udph);
95781@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
95782 put_unaligned(0x45, (unsigned char *)iph);
95783 iph->tos = 0;
95784 put_unaligned(htons(ip_len), &(iph->tot_len));
95785- iph->id = htons(atomic_inc_return(&ip_ident));
95786+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
95787 iph->frag_off = 0;
95788 iph->ttl = 64;
95789 iph->protocol = IPPROTO_UDP;
95790diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
95791index cf67144..12bf94c 100644
95792--- a/net/core/rtnetlink.c
95793+++ b/net/core/rtnetlink.c
95794@@ -58,7 +58,7 @@ struct rtnl_link {
95795 rtnl_doit_func doit;
95796 rtnl_dumpit_func dumpit;
95797 rtnl_calcit_func calcit;
95798-};
95799+} __no_const;
95800
95801 static DEFINE_MUTEX(rtnl_mutex);
95802
95803@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
95804 if (rtnl_link_ops_get(ops->kind))
95805 return -EEXIST;
95806
95807- if (!ops->dellink)
95808- ops->dellink = unregister_netdevice_queue;
95809+ if (!ops->dellink) {
95810+ pax_open_kernel();
95811+ *(void **)&ops->dellink = unregister_netdevice_queue;
95812+ pax_close_kernel();
95813+ }
95814
95815- list_add_tail(&ops->list, &link_ops);
95816+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
95817 return 0;
95818 }
95819 EXPORT_SYMBOL_GPL(__rtnl_link_register);
95820@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
95821 for_each_net(net) {
95822 __rtnl_kill_links(net, ops);
95823 }
95824- list_del(&ops->list);
95825+ pax_list_del((struct list_head *)&ops->list);
95826 }
95827 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
95828
95829diff --git a/net/core/scm.c b/net/core/scm.c
95830index b442e7e..6f5b5a2 100644
95831--- a/net/core/scm.c
95832+++ b/net/core/scm.c
95833@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
95834 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
95835 {
95836 struct cmsghdr __user *cm
95837- = (__force struct cmsghdr __user *)msg->msg_control;
95838+ = (struct cmsghdr __force_user *)msg->msg_control;
95839 struct cmsghdr cmhdr;
95840 int cmlen = CMSG_LEN(len);
95841 int err;
95842@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
95843 err = -EFAULT;
95844 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
95845 goto out;
95846- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
95847+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
95848 goto out;
95849 cmlen = CMSG_SPACE(len);
95850 if (msg->msg_controllen < cmlen)
95851@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
95852 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
95853 {
95854 struct cmsghdr __user *cm
95855- = (__force struct cmsghdr __user*)msg->msg_control;
95856+ = (struct cmsghdr __force_user *)msg->msg_control;
95857
95858 int fdmax = 0;
95859 int fdnum = scm->fp->count;
95860@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
95861 if (fdnum < fdmax)
95862 fdmax = fdnum;
95863
95864- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
95865+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
95866 i++, cmfptr++)
95867 {
95868 struct socket *sock;
95869diff --git a/net/core/skbuff.c b/net/core/skbuff.c
95870index 06e72d3..19dfa7b 100644
95871--- a/net/core/skbuff.c
95872+++ b/net/core/skbuff.c
95873@@ -2034,7 +2034,7 @@ EXPORT_SYMBOL(__skb_checksum);
95874 __wsum skb_checksum(const struct sk_buff *skb, int offset,
95875 int len, __wsum csum)
95876 {
95877- const struct skb_checksum_ops ops = {
95878+ static const struct skb_checksum_ops ops = {
95879 .update = csum_partial_ext,
95880 .combine = csum_block_add_ext,
95881 };
95882@@ -3147,13 +3147,15 @@ void __init skb_init(void)
95883 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
95884 sizeof(struct sk_buff),
95885 0,
95886- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
95887+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
95888+ SLAB_NO_SANITIZE,
95889 NULL);
95890 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
95891 (2*sizeof(struct sk_buff)) +
95892 sizeof(atomic_t),
95893 0,
95894- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
95895+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
95896+ SLAB_NO_SANITIZE,
95897 NULL);
95898 }
95899
95900diff --git a/net/core/sock.c b/net/core/sock.c
95901index 5393b4b..997c88b 100644
95902--- a/net/core/sock.c
95903+++ b/net/core/sock.c
95904@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
95905 struct sk_buff_head *list = &sk->sk_receive_queue;
95906
95907 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
95908- atomic_inc(&sk->sk_drops);
95909+ atomic_inc_unchecked(&sk->sk_drops);
95910 trace_sock_rcvqueue_full(sk, skb);
95911 return -ENOMEM;
95912 }
95913@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
95914 return err;
95915
95916 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
95917- atomic_inc(&sk->sk_drops);
95918+ atomic_inc_unchecked(&sk->sk_drops);
95919 return -ENOBUFS;
95920 }
95921
95922@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
95923 skb_dst_force(skb);
95924
95925 spin_lock_irqsave(&list->lock, flags);
95926- skb->dropcount = atomic_read(&sk->sk_drops);
95927+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
95928 __skb_queue_tail(list, skb);
95929 spin_unlock_irqrestore(&list->lock, flags);
95930
95931@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
95932 skb->dev = NULL;
95933
95934 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
95935- atomic_inc(&sk->sk_drops);
95936+ atomic_inc_unchecked(&sk->sk_drops);
95937 goto discard_and_relse;
95938 }
95939 if (nested)
95940@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
95941 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
95942 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
95943 bh_unlock_sock(sk);
95944- atomic_inc(&sk->sk_drops);
95945+ atomic_inc_unchecked(&sk->sk_drops);
95946 goto discard_and_relse;
95947 }
95948
95949@@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
95950 struct timeval tm;
95951 } v;
95952
95953- int lv = sizeof(int);
95954- int len;
95955+ unsigned int lv = sizeof(int);
95956+ unsigned int len;
95957
95958 if (get_user(len, optlen))
95959 return -EFAULT;
95960- if (len < 0)
95961+ if (len > INT_MAX)
95962 return -EINVAL;
95963
95964 memset(&v, 0, sizeof(v));
95965@@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
95966
95967 case SO_PEERNAME:
95968 {
95969- char address[128];
95970+ char address[_K_SS_MAXSIZE];
95971
95972 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
95973 return -ENOTCONN;
95974- if (lv < len)
95975+ if (lv < len || sizeof address < len)
95976 return -EINVAL;
95977 if (copy_to_user(optval, address, len))
95978 return -EFAULT;
95979@@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
95980
95981 if (len > lv)
95982 len = lv;
95983- if (copy_to_user(optval, &v, len))
95984+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
95985 return -EFAULT;
95986 lenout:
95987 if (put_user(len, optlen))
95988@@ -2351,7 +2351,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
95989 */
95990 smp_wmb();
95991 atomic_set(&sk->sk_refcnt, 1);
95992- atomic_set(&sk->sk_drops, 0);
95993+ atomic_set_unchecked(&sk->sk_drops, 0);
95994 }
95995 EXPORT_SYMBOL(sock_init_data);
95996
95997@@ -2476,6 +2476,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
95998 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
95999 int level, int type)
96000 {
96001+ struct sock_extended_err ee;
96002 struct sock_exterr_skb *serr;
96003 struct sk_buff *skb, *skb2;
96004 int copied, err;
96005@@ -2497,7 +2498,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96006 sock_recv_timestamp(msg, sk, skb);
96007
96008 serr = SKB_EXT_ERR(skb);
96009- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
96010+ ee = serr->ee;
96011+ put_cmsg(msg, level, type, sizeof ee, &ee);
96012
96013 msg->msg_flags |= MSG_ERRQUEUE;
96014 err = copied;
96015diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
96016index a0e9cf6..ef7f9ed 100644
96017--- a/net/core/sock_diag.c
96018+++ b/net/core/sock_diag.c
96019@@ -9,26 +9,33 @@
96020 #include <linux/inet_diag.h>
96021 #include <linux/sock_diag.h>
96022
96023-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
96024+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
96025 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
96026 static DEFINE_MUTEX(sock_diag_table_mutex);
96027
96028 int sock_diag_check_cookie(void *sk, __u32 *cookie)
96029 {
96030+#ifndef CONFIG_GRKERNSEC_HIDESYM
96031 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
96032 cookie[1] != INET_DIAG_NOCOOKIE) &&
96033 ((u32)(unsigned long)sk != cookie[0] ||
96034 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
96035 return -ESTALE;
96036 else
96037+#endif
96038 return 0;
96039 }
96040 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
96041
96042 void sock_diag_save_cookie(void *sk, __u32 *cookie)
96043 {
96044+#ifdef CONFIG_GRKERNSEC_HIDESYM
96045+ cookie[0] = 0;
96046+ cookie[1] = 0;
96047+#else
96048 cookie[0] = (u32)(unsigned long)sk;
96049 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
96050+#endif
96051 }
96052 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
96053
96054@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
96055 mutex_lock(&sock_diag_table_mutex);
96056 if (sock_diag_handlers[hndl->family])
96057 err = -EBUSY;
96058- else
96059+ else {
96060+ pax_open_kernel();
96061 sock_diag_handlers[hndl->family] = hndl;
96062+ pax_close_kernel();
96063+ }
96064 mutex_unlock(&sock_diag_table_mutex);
96065
96066 return err;
96067@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
96068
96069 mutex_lock(&sock_diag_table_mutex);
96070 BUG_ON(sock_diag_handlers[family] != hnld);
96071+ pax_open_kernel();
96072 sock_diag_handlers[family] = NULL;
96073+ pax_close_kernel();
96074 mutex_unlock(&sock_diag_table_mutex);
96075 }
96076 EXPORT_SYMBOL_GPL(sock_diag_unregister);
96077diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
96078index cca4441..5e616de 100644
96079--- a/net/core/sysctl_net_core.c
96080+++ b/net/core/sysctl_net_core.c
96081@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
96082 {
96083 unsigned int orig_size, size;
96084 int ret, i;
96085- struct ctl_table tmp = {
96086+ ctl_table_no_const tmp = {
96087 .data = &size,
96088 .maxlen = sizeof(size),
96089 .mode = table->mode
96090@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
96091 void __user *buffer, size_t *lenp, loff_t *ppos)
96092 {
96093 char id[IFNAMSIZ];
96094- struct ctl_table tbl = {
96095+ ctl_table_no_const tbl = {
96096 .data = id,
96097 .maxlen = IFNAMSIZ,
96098 };
96099@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
96100
96101 static __net_init int sysctl_core_net_init(struct net *net)
96102 {
96103- struct ctl_table *tbl;
96104+ ctl_table_no_const *tbl = NULL;
96105
96106 net->core.sysctl_somaxconn = SOMAXCONN;
96107
96108- tbl = netns_core_table;
96109 if (!net_eq(net, &init_net)) {
96110- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
96111+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
96112 if (tbl == NULL)
96113 goto err_dup;
96114
96115@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
96116 if (net->user_ns != &init_user_ns) {
96117 tbl[0].procname = NULL;
96118 }
96119- }
96120-
96121- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96122+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96123+ } else
96124+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
96125 if (net->core.sysctl_hdr == NULL)
96126 goto err_reg;
96127
96128 return 0;
96129
96130 err_reg:
96131- if (tbl != netns_core_table)
96132- kfree(tbl);
96133+ kfree(tbl);
96134 err_dup:
96135 return -ENOMEM;
96136 }
96137@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
96138 kfree(tbl);
96139 }
96140
96141-static __net_initdata struct pernet_operations sysctl_core_ops = {
96142+static __net_initconst struct pernet_operations sysctl_core_ops = {
96143 .init = sysctl_core_net_init,
96144 .exit = sysctl_core_net_exit,
96145 };
96146diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
96147index dd4d506..fb2fb87 100644
96148--- a/net/decnet/af_decnet.c
96149+++ b/net/decnet/af_decnet.c
96150@@ -465,6 +465,7 @@ static struct proto dn_proto = {
96151 .sysctl_rmem = sysctl_decnet_rmem,
96152 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
96153 .obj_size = sizeof(struct dn_sock),
96154+ .slab_flags = SLAB_USERCOPY,
96155 };
96156
96157 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
96158diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
96159index dd0dfb2..fdbc764 100644
96160--- a/net/decnet/dn_dev.c
96161+++ b/net/decnet/dn_dev.c
96162@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
96163 .extra1 = &min_t3,
96164 .extra2 = &max_t3
96165 },
96166- {0}
96167+ { }
96168 },
96169 };
96170
96171diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
96172index 5325b54..a0d4d69 100644
96173--- a/net/decnet/sysctl_net_decnet.c
96174+++ b/net/decnet/sysctl_net_decnet.c
96175@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
96176
96177 if (len > *lenp) len = *lenp;
96178
96179- if (copy_to_user(buffer, addr, len))
96180+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
96181 return -EFAULT;
96182
96183 *lenp = len;
96184@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
96185
96186 if (len > *lenp) len = *lenp;
96187
96188- if (copy_to_user(buffer, devname, len))
96189+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
96190 return -EFAULT;
96191
96192 *lenp = len;
96193diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
96194index 1865fdf..581a595 100644
96195--- a/net/ieee802154/dgram.c
96196+++ b/net/ieee802154/dgram.c
96197@@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
96198 if (saddr) {
96199 saddr->family = AF_IEEE802154;
96200 saddr->addr = mac_cb(skb)->sa;
96201+ }
96202+ if (addr_len)
96203 *addr_len = sizeof(*saddr);
96204- }
96205
96206 if (flags & MSG_TRUNC)
96207 copied = skb->len;
96208diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
96209index 70011e0..454ca6a 100644
96210--- a/net/ipv4/af_inet.c
96211+++ b/net/ipv4/af_inet.c
96212@@ -1683,13 +1683,9 @@ static int __init inet_init(void)
96213
96214 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
96215
96216- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
96217- if (!sysctl_local_reserved_ports)
96218- goto out;
96219-
96220 rc = proto_register(&tcp_prot, 1);
96221 if (rc)
96222- goto out_free_reserved_ports;
96223+ goto out;
96224
96225 rc = proto_register(&udp_prot, 1);
96226 if (rc)
96227@@ -1796,8 +1792,6 @@ out_unregister_udp_proto:
96228 proto_unregister(&udp_prot);
96229 out_unregister_tcp_proto:
96230 proto_unregister(&tcp_prot);
96231-out_free_reserved_ports:
96232- kfree(sysctl_local_reserved_ports);
96233 goto out;
96234 }
96235
96236diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
96237index a1b5bcb..62ec5c6 100644
96238--- a/net/ipv4/devinet.c
96239+++ b/net/ipv4/devinet.c
96240@@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
96241 idx = 0;
96242 head = &net->dev_index_head[h];
96243 rcu_read_lock();
96244- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96245+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96246 net->dev_base_seq;
96247 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96248 if (idx < s_idx)
96249@@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
96250 idx = 0;
96251 head = &net->dev_index_head[h];
96252 rcu_read_lock();
96253- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96254+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96255 net->dev_base_seq;
96256 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96257 if (idx < s_idx)
96258@@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
96259 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
96260 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
96261
96262-static struct devinet_sysctl_table {
96263+static const struct devinet_sysctl_table {
96264 struct ctl_table_header *sysctl_header;
96265 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
96266 } devinet_sysctl = {
96267@@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
96268 int err;
96269 struct ipv4_devconf *all, *dflt;
96270 #ifdef CONFIG_SYSCTL
96271- struct ctl_table *tbl = ctl_forward_entry;
96272+ ctl_table_no_const *tbl = NULL;
96273 struct ctl_table_header *forw_hdr;
96274 #endif
96275
96276@@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
96277 goto err_alloc_dflt;
96278
96279 #ifdef CONFIG_SYSCTL
96280- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
96281+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
96282 if (tbl == NULL)
96283 goto err_alloc_ctl;
96284
96285@@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
96286 goto err_reg_dflt;
96287
96288 err = -ENOMEM;
96289- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96290+ if (!net_eq(net, &init_net))
96291+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96292+ else
96293+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
96294 if (forw_hdr == NULL)
96295 goto err_reg_ctl;
96296 net->ipv4.forw_hdr = forw_hdr;
96297@@ -2245,8 +2248,7 @@ err_reg_ctl:
96298 err_reg_dflt:
96299 __devinet_sysctl_unregister(all);
96300 err_reg_all:
96301- if (tbl != ctl_forward_entry)
96302- kfree(tbl);
96303+ kfree(tbl);
96304 err_alloc_ctl:
96305 #endif
96306 if (dflt != &ipv4_devconf_dflt)
96307diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
96308index d846304..d0622bb 100644
96309--- a/net/ipv4/fib_frontend.c
96310+++ b/net/ipv4/fib_frontend.c
96311@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
96312 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96313 fib_sync_up(dev);
96314 #endif
96315- atomic_inc(&net->ipv4.dev_addr_genid);
96316+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96317 rt_cache_flush(dev_net(dev));
96318 break;
96319 case NETDEV_DOWN:
96320 fib_del_ifaddr(ifa, NULL);
96321- atomic_inc(&net->ipv4.dev_addr_genid);
96322+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96323 if (ifa->ifa_dev->ifa_list == NULL) {
96324 /* Last address was deleted from this interface.
96325 * Disable IP.
96326@@ -1056,7 +1056,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
96327 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96328 fib_sync_up(dev);
96329 #endif
96330- atomic_inc(&net->ipv4.dev_addr_genid);
96331+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96332 rt_cache_flush(net);
96333 break;
96334 case NETDEV_DOWN:
96335diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
96336index e63f47a..e5c531d 100644
96337--- a/net/ipv4/fib_semantics.c
96338+++ b/net/ipv4/fib_semantics.c
96339@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
96340 nh->nh_saddr = inet_select_addr(nh->nh_dev,
96341 nh->nh_gw,
96342 nh->nh_parent->fib_scope);
96343- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
96344+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
96345
96346 return nh->nh_saddr;
96347 }
96348diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
96349index fc0e649..febfa65 100644
96350--- a/net/ipv4/inet_connection_sock.c
96351+++ b/net/ipv4/inet_connection_sock.c
96352@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
96353 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
96354 #endif
96355
96356-unsigned long *sysctl_local_reserved_ports;
96357+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
96358 EXPORT_SYMBOL(sysctl_local_reserved_ports);
96359
96360 void inet_get_local_port_range(struct net *net, int *low, int *high)
96361diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
96362index 8b9cf27..0d8d592 100644
96363--- a/net/ipv4/inet_hashtables.c
96364+++ b/net/ipv4/inet_hashtables.c
96365@@ -18,6 +18,7 @@
96366 #include <linux/sched.h>
96367 #include <linux/slab.h>
96368 #include <linux/wait.h>
96369+#include <linux/security.h>
96370
96371 #include <net/inet_connection_sock.h>
96372 #include <net/inet_hashtables.h>
96373@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
96374 return inet_ehashfn(net, laddr, lport, faddr, fport);
96375 }
96376
96377+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
96378+
96379 /*
96380 * Allocate and initialize a new local port bind bucket.
96381 * The bindhash mutex for snum's hash chain must be held here.
96382@@ -554,6 +557,8 @@ ok:
96383 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
96384 spin_unlock(&head->lock);
96385
96386+ gr_update_task_in_ip_table(current, inet_sk(sk));
96387+
96388 if (tw) {
96389 inet_twsk_deschedule(tw, death_row);
96390 while (twrefcnt) {
96391diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
96392index 33d5537..da337a4 100644
96393--- a/net/ipv4/inetpeer.c
96394+++ b/net/ipv4/inetpeer.c
96395@@ -503,8 +503,8 @@ relookup:
96396 if (p) {
96397 p->daddr = *daddr;
96398 atomic_set(&p->refcnt, 1);
96399- atomic_set(&p->rid, 0);
96400- atomic_set(&p->ip_id_count,
96401+ atomic_set_unchecked(&p->rid, 0);
96402+ atomic_set_unchecked(&p->ip_id_count,
96403 (daddr->family == AF_INET) ?
96404 secure_ip_id(daddr->addr.a4) :
96405 secure_ipv6_id(daddr->addr.a6));
96406diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
96407index 2481993..2d9a7a7 100644
96408--- a/net/ipv4/ip_fragment.c
96409+++ b/net/ipv4/ip_fragment.c
96410@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
96411 return 0;
96412
96413 start = qp->rid;
96414- end = atomic_inc_return(&peer->rid);
96415+ end = atomic_inc_return_unchecked(&peer->rid);
96416 qp->rid = end;
96417
96418 rc = qp->q.fragments && (end - start) > max;
96419@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
96420
96421 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96422 {
96423- struct ctl_table *table;
96424+ ctl_table_no_const *table = NULL;
96425 struct ctl_table_header *hdr;
96426
96427- table = ip4_frags_ns_ctl_table;
96428 if (!net_eq(net, &init_net)) {
96429- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96430+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96431 if (table == NULL)
96432 goto err_alloc;
96433
96434@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96435 /* Don't export sysctls to unprivileged users */
96436 if (net->user_ns != &init_user_ns)
96437 table[0].procname = NULL;
96438- }
96439+ hdr = register_net_sysctl(net, "net/ipv4", table);
96440+ } else
96441+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
96442
96443- hdr = register_net_sysctl(net, "net/ipv4", table);
96444 if (hdr == NULL)
96445 goto err_reg;
96446
96447@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96448 return 0;
96449
96450 err_reg:
96451- if (!net_eq(net, &init_net))
96452- kfree(table);
96453+ kfree(table);
96454 err_alloc:
96455 return -ENOMEM;
96456 }
96457diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
96458index e560ef3..218c5c5 100644
96459--- a/net/ipv4/ip_gre.c
96460+++ b/net/ipv4/ip_gre.c
96461@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
96462 module_param(log_ecn_error, bool, 0644);
96463 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96464
96465-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
96466+static struct rtnl_link_ops ipgre_link_ops;
96467 static int ipgre_tunnel_init(struct net_device *dev);
96468
96469 static int ipgre_net_id __read_mostly;
96470@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
96471 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
96472 };
96473
96474-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96475+static struct rtnl_link_ops ipgre_link_ops = {
96476 .kind = "gre",
96477 .maxtype = IFLA_GRE_MAX,
96478 .policy = ipgre_policy,
96479@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96480 .fill_info = ipgre_fill_info,
96481 };
96482
96483-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
96484+static struct rtnl_link_ops ipgre_tap_ops = {
96485 .kind = "gretap",
96486 .maxtype = IFLA_GRE_MAX,
96487 .policy = ipgre_policy,
96488diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
96489index ddf32a6..3fdeea9 100644
96490--- a/net/ipv4/ip_sockglue.c
96491+++ b/net/ipv4/ip_sockglue.c
96492@@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96493 len = min_t(unsigned int, len, opt->optlen);
96494 if (put_user(len, optlen))
96495 return -EFAULT;
96496- if (copy_to_user(optval, opt->__data, len))
96497+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
96498+ copy_to_user(optval, opt->__data, len))
96499 return -EFAULT;
96500 return 0;
96501 }
96502@@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96503 if (sk->sk_type != SOCK_STREAM)
96504 return -ENOPROTOOPT;
96505
96506- msg.msg_control = optval;
96507+ msg.msg_control = (void __force_kernel *)optval;
96508 msg.msg_controllen = len;
96509 msg.msg_flags = flags;
96510
96511diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
96512index 52b802a..b725179 100644
96513--- a/net/ipv4/ip_vti.c
96514+++ b/net/ipv4/ip_vti.c
96515@@ -44,7 +44,7 @@
96516 #include <net/net_namespace.h>
96517 #include <net/netns/generic.h>
96518
96519-static struct rtnl_link_ops vti_link_ops __read_mostly;
96520+static struct rtnl_link_ops vti_link_ops;
96521
96522 static int vti_net_id __read_mostly;
96523 static int vti_tunnel_init(struct net_device *dev);
96524@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
96525 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
96526 };
96527
96528-static struct rtnl_link_ops vti_link_ops __read_mostly = {
96529+static struct rtnl_link_ops vti_link_ops = {
96530 .kind = "vti",
96531 .maxtype = IFLA_VTI_MAX,
96532 .policy = vti_policy,
96533diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
96534index efa1138..20dbba0 100644
96535--- a/net/ipv4/ipconfig.c
96536+++ b/net/ipv4/ipconfig.c
96537@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
96538
96539 mm_segment_t oldfs = get_fs();
96540 set_fs(get_ds());
96541- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96542+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96543 set_fs(oldfs);
96544 return res;
96545 }
96546@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
96547
96548 mm_segment_t oldfs = get_fs();
96549 set_fs(get_ds());
96550- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96551+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96552 set_fs(oldfs);
96553 return res;
96554 }
96555@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
96556
96557 mm_segment_t oldfs = get_fs();
96558 set_fs(get_ds());
96559- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
96560+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
96561 set_fs(oldfs);
96562 return res;
96563 }
96564diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
96565index fe3e9f7..4956990 100644
96566--- a/net/ipv4/ipip.c
96567+++ b/net/ipv4/ipip.c
96568@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96569 static int ipip_net_id __read_mostly;
96570
96571 static int ipip_tunnel_init(struct net_device *dev);
96572-static struct rtnl_link_ops ipip_link_ops __read_mostly;
96573+static struct rtnl_link_ops ipip_link_ops;
96574
96575 static int ipip_err(struct sk_buff *skb, u32 info)
96576 {
96577@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
96578 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
96579 };
96580
96581-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
96582+static struct rtnl_link_ops ipip_link_ops = {
96583 .kind = "ipip",
96584 .maxtype = IFLA_IPTUN_MAX,
96585 .policy = ipip_policy,
96586diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
96587index 59da7cd..e318de1 100644
96588--- a/net/ipv4/netfilter/arp_tables.c
96589+++ b/net/ipv4/netfilter/arp_tables.c
96590@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
96591 #endif
96592
96593 static int get_info(struct net *net, void __user *user,
96594- const int *len, int compat)
96595+ int len, int compat)
96596 {
96597 char name[XT_TABLE_MAXNAMELEN];
96598 struct xt_table *t;
96599 int ret;
96600
96601- if (*len != sizeof(struct arpt_getinfo)) {
96602- duprintf("length %u != %Zu\n", *len,
96603+ if (len != sizeof(struct arpt_getinfo)) {
96604+ duprintf("length %u != %Zu\n", len,
96605 sizeof(struct arpt_getinfo));
96606 return -EINVAL;
96607 }
96608@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
96609 info.size = private->size;
96610 strcpy(info.name, name);
96611
96612- if (copy_to_user(user, &info, *len) != 0)
96613+ if (copy_to_user(user, &info, len) != 0)
96614 ret = -EFAULT;
96615 else
96616 ret = 0;
96617@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
96618
96619 switch (cmd) {
96620 case ARPT_SO_GET_INFO:
96621- ret = get_info(sock_net(sk), user, len, 1);
96622+ ret = get_info(sock_net(sk), user, *len, 1);
96623 break;
96624 case ARPT_SO_GET_ENTRIES:
96625 ret = compat_get_entries(sock_net(sk), user, len);
96626@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
96627
96628 switch (cmd) {
96629 case ARPT_SO_GET_INFO:
96630- ret = get_info(sock_net(sk), user, len, 0);
96631+ ret = get_info(sock_net(sk), user, *len, 0);
96632 break;
96633
96634 case ARPT_SO_GET_ENTRIES:
96635diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
96636index 718dfbd..cef4152 100644
96637--- a/net/ipv4/netfilter/ip_tables.c
96638+++ b/net/ipv4/netfilter/ip_tables.c
96639@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
96640 #endif
96641
96642 static int get_info(struct net *net, void __user *user,
96643- const int *len, int compat)
96644+ int len, int compat)
96645 {
96646 char name[XT_TABLE_MAXNAMELEN];
96647 struct xt_table *t;
96648 int ret;
96649
96650- if (*len != sizeof(struct ipt_getinfo)) {
96651- duprintf("length %u != %zu\n", *len,
96652+ if (len != sizeof(struct ipt_getinfo)) {
96653+ duprintf("length %u != %zu\n", len,
96654 sizeof(struct ipt_getinfo));
96655 return -EINVAL;
96656 }
96657@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
96658 info.size = private->size;
96659 strcpy(info.name, name);
96660
96661- if (copy_to_user(user, &info, *len) != 0)
96662+ if (copy_to_user(user, &info, len) != 0)
96663 ret = -EFAULT;
96664 else
96665 ret = 0;
96666@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96667
96668 switch (cmd) {
96669 case IPT_SO_GET_INFO:
96670- ret = get_info(sock_net(sk), user, len, 1);
96671+ ret = get_info(sock_net(sk), user, *len, 1);
96672 break;
96673 case IPT_SO_GET_ENTRIES:
96674 ret = compat_get_entries(sock_net(sk), user, len);
96675@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96676
96677 switch (cmd) {
96678 case IPT_SO_GET_INFO:
96679- ret = get_info(sock_net(sk), user, len, 0);
96680+ ret = get_info(sock_net(sk), user, *len, 0);
96681 break;
96682
96683 case IPT_SO_GET_ENTRIES:
96684diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
96685index 242e7f4..a084e95 100644
96686--- a/net/ipv4/ping.c
96687+++ b/net/ipv4/ping.c
96688@@ -55,7 +55,7 @@
96689
96690
96691 struct ping_table ping_table;
96692-struct pingv6_ops pingv6_ops;
96693+struct pingv6_ops *pingv6_ops;
96694 EXPORT_SYMBOL_GPL(pingv6_ops);
96695
96696 static u16 ping_port_rover;
96697@@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
96698 return -ENODEV;
96699 }
96700 }
96701- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
96702+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
96703 scoped);
96704 rcu_read_unlock();
96705
96706@@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96707 }
96708 #if IS_ENABLED(CONFIG_IPV6)
96709 } else if (skb->protocol == htons(ETH_P_IPV6)) {
96710- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
96711+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
96712 #endif
96713 }
96714
96715@@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96716 info, (u8 *)icmph);
96717 #if IS_ENABLED(CONFIG_IPV6)
96718 } else if (family == AF_INET6) {
96719- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
96720+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
96721 info, (u8 *)icmph);
96722 #endif
96723 }
96724@@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96725 {
96726 struct inet_sock *isk = inet_sk(sk);
96727 int family = sk->sk_family;
96728+ struct sockaddr_in *sin;
96729+ struct sockaddr_in6 *sin6;
96730 struct sk_buff *skb;
96731 int copied, err;
96732
96733@@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96734 if (flags & MSG_OOB)
96735 goto out;
96736
96737+ if (addr_len) {
96738+ if (family == AF_INET)
96739+ *addr_len = sizeof(*sin);
96740+ else if (family == AF_INET6 && addr_len)
96741+ *addr_len = sizeof(*sin6);
96742+ }
96743+
96744 if (flags & MSG_ERRQUEUE) {
96745 if (family == AF_INET) {
96746 return ip_recv_error(sk, msg, len, addr_len);
96747 #if IS_ENABLED(CONFIG_IPV6)
96748 } else if (family == AF_INET6) {
96749- return pingv6_ops.ipv6_recv_error(sk, msg, len,
96750+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
96751 addr_len);
96752 #endif
96753 }
96754@@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96755 sin->sin_port = 0 /* skb->h.uh->source */;
96756 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
96757 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
96758- *addr_len = sizeof(*sin);
96759 }
96760
96761 if (isk->cmsg_flags)
96762@@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96763 sin6->sin6_scope_id =
96764 ipv6_iface_scope_id(&sin6->sin6_addr,
96765 IP6CB(skb)->iif);
96766- *addr_len = sizeof(*sin6);
96767 }
96768
96769 if (inet6_sk(sk)->rxopt.all)
96770- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
96771+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
96772 #endif
96773 } else {
96774 BUG();
96775@@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
96776 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
96777 0, sock_i_ino(sp),
96778 atomic_read(&sp->sk_refcnt), sp,
96779- atomic_read(&sp->sk_drops));
96780+ atomic_read_unchecked(&sp->sk_drops));
96781 }
96782
96783 static int ping_v4_seq_show(struct seq_file *seq, void *v)
96784diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
96785index 23c3e5b..cdb8b36 100644
96786--- a/net/ipv4/raw.c
96787+++ b/net/ipv4/raw.c
96788@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
96789 int raw_rcv(struct sock *sk, struct sk_buff *skb)
96790 {
96791 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
96792- atomic_inc(&sk->sk_drops);
96793+ atomic_inc_unchecked(&sk->sk_drops);
96794 kfree_skb(skb);
96795 return NET_RX_DROP;
96796 }
96797@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96798 if (flags & MSG_OOB)
96799 goto out;
96800
96801+ if (addr_len)
96802+ *addr_len = sizeof(*sin);
96803+
96804 if (flags & MSG_ERRQUEUE) {
96805 err = ip_recv_error(sk, msg, len, addr_len);
96806 goto out;
96807@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96808 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
96809 sin->sin_port = 0;
96810 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
96811- *addr_len = sizeof(*sin);
96812 }
96813 if (inet->cmsg_flags)
96814 ip_cmsg_recv(msg, skb);
96815@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
96816
96817 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
96818 {
96819+ struct icmp_filter filter;
96820+
96821 if (optlen > sizeof(struct icmp_filter))
96822 optlen = sizeof(struct icmp_filter);
96823- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
96824+ if (copy_from_user(&filter, optval, optlen))
96825 return -EFAULT;
96826+ raw_sk(sk)->filter = filter;
96827 return 0;
96828 }
96829
96830 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
96831 {
96832 int len, ret = -EFAULT;
96833+ struct icmp_filter filter;
96834
96835 if (get_user(len, optlen))
96836 goto out;
96837@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
96838 if (len > sizeof(struct icmp_filter))
96839 len = sizeof(struct icmp_filter);
96840 ret = -EFAULT;
96841- if (put_user(len, optlen) ||
96842- copy_to_user(optval, &raw_sk(sk)->filter, len))
96843+ filter = raw_sk(sk)->filter;
96844+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
96845 goto out;
96846 ret = 0;
96847 out: return ret;
96848@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
96849 0, 0L, 0,
96850 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
96851 0, sock_i_ino(sp),
96852- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
96853+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
96854 }
96855
96856 static int raw_seq_show(struct seq_file *seq, void *v)
96857diff --git a/net/ipv4/route.c b/net/ipv4/route.c
96858index f8da282..133a1c7 100644
96859--- a/net/ipv4/route.c
96860+++ b/net/ipv4/route.c
96861@@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
96862 .maxlen = sizeof(int),
96863 .mode = 0200,
96864 .proc_handler = ipv4_sysctl_rtcache_flush,
96865+ .extra1 = &init_net,
96866 },
96867 { },
96868 };
96869
96870 static __net_init int sysctl_route_net_init(struct net *net)
96871 {
96872- struct ctl_table *tbl;
96873+ ctl_table_no_const *tbl = NULL;
96874
96875- tbl = ipv4_route_flush_table;
96876 if (!net_eq(net, &init_net)) {
96877- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
96878+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
96879 if (tbl == NULL)
96880 goto err_dup;
96881
96882 /* Don't export sysctls to unprivileged users */
96883 if (net->user_ns != &init_user_ns)
96884 tbl[0].procname = NULL;
96885- }
96886- tbl[0].extra1 = net;
96887+ tbl[0].extra1 = net;
96888+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
96889+ } else
96890+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
96891
96892- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
96893 if (net->ipv4.route_hdr == NULL)
96894 goto err_reg;
96895 return 0;
96896
96897 err_reg:
96898- if (tbl != ipv4_route_flush_table)
96899- kfree(tbl);
96900+ kfree(tbl);
96901 err_dup:
96902 return -ENOMEM;
96903 }
96904@@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
96905
96906 static __net_init int rt_genid_init(struct net *net)
96907 {
96908- atomic_set(&net->ipv4.rt_genid, 0);
96909- atomic_set(&net->fnhe_genid, 0);
96910+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
96911+ atomic_set_unchecked(&net->fnhe_genid, 0);
96912 get_random_bytes(&net->ipv4.dev_addr_genid,
96913 sizeof(net->ipv4.dev_addr_genid));
96914 return 0;
96915diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
96916index 3d69ec8..57207b4 100644
96917--- a/net/ipv4/sysctl_net_ipv4.c
96918+++ b/net/ipv4/sysctl_net_ipv4.c
96919@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
96920 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
96921 int ret;
96922 int range[2];
96923- struct ctl_table tmp = {
96924+ ctl_table_no_const tmp = {
96925 .data = &range,
96926 .maxlen = sizeof(range),
96927 .mode = table->mode,
96928@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
96929 int ret;
96930 gid_t urange[2];
96931 kgid_t low, high;
96932- struct ctl_table tmp = {
96933+ ctl_table_no_const tmp = {
96934 .data = &urange,
96935 .maxlen = sizeof(urange),
96936 .mode = table->mode,
96937@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
96938 void __user *buffer, size_t *lenp, loff_t *ppos)
96939 {
96940 char val[TCP_CA_NAME_MAX];
96941- struct ctl_table tbl = {
96942+ ctl_table_no_const tbl = {
96943 .data = val,
96944 .maxlen = TCP_CA_NAME_MAX,
96945 };
96946@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
96947 void __user *buffer, size_t *lenp,
96948 loff_t *ppos)
96949 {
96950- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
96951+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
96952 int ret;
96953
96954 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
96955@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
96956 void __user *buffer, size_t *lenp,
96957 loff_t *ppos)
96958 {
96959- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
96960+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
96961 int ret;
96962
96963 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
96964@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
96965 void __user *buffer, size_t *lenp,
96966 loff_t *ppos)
96967 {
96968- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
96969+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
96970 struct tcp_fastopen_context *ctxt;
96971 int ret;
96972 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
96973@@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
96974 },
96975 {
96976 .procname = "ip_local_reserved_ports",
96977- .data = NULL, /* initialized in sysctl_ipv4_init */
96978+ .data = sysctl_local_reserved_ports,
96979 .maxlen = 65536,
96980 .mode = 0644,
96981 .proc_handler = proc_do_large_bitmap,
96982@@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
96983
96984 static __net_init int ipv4_sysctl_init_net(struct net *net)
96985 {
96986- struct ctl_table *table;
96987+ ctl_table_no_const *table = NULL;
96988
96989- table = ipv4_net_table;
96990 if (!net_eq(net, &init_net)) {
96991 int i;
96992
96993- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
96994+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
96995 if (table == NULL)
96996 goto err_alloc;
96997
96998@@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
96999 net->ipv4.sysctl_local_ports.range[0] = 32768;
97000 net->ipv4.sysctl_local_ports.range[1] = 61000;
97001
97002- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97003+ if (!net_eq(net, &init_net))
97004+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97005+ else
97006+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
97007 if (net->ipv4.ipv4_hdr == NULL)
97008 goto err_reg;
97009
97010 return 0;
97011
97012 err_reg:
97013- if (!net_eq(net, &init_net))
97014- kfree(table);
97015+ kfree(table);
97016 err_alloc:
97017 return -ENOMEM;
97018 }
97019@@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
97020 static __init int sysctl_ipv4_init(void)
97021 {
97022 struct ctl_table_header *hdr;
97023- struct ctl_table *i;
97024-
97025- for (i = ipv4_table; i->procname; i++) {
97026- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
97027- i->data = sysctl_local_reserved_ports;
97028- break;
97029- }
97030- }
97031- if (!i->procname)
97032- return -EINVAL;
97033
97034 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
97035 if (hdr == NULL)
97036diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
97037index c53b7f3..a89aadd 100644
97038--- a/net/ipv4/tcp_input.c
97039+++ b/net/ipv4/tcp_input.c
97040@@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
97041 * without any lock. We want to make sure compiler wont store
97042 * intermediate values in this location.
97043 */
97044- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
97045+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
97046 sk->sk_max_pacing_rate);
97047 }
97048
97049@@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
97050 * simplifies code)
97051 */
97052 static void
97053-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97054+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97055 struct sk_buff *head, struct sk_buff *tail,
97056 u32 start, u32 end)
97057 {
97058@@ -5559,6 +5559,7 @@ discard:
97059 tcp_paws_reject(&tp->rx_opt, 0))
97060 goto discard_and_undo;
97061
97062+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
97063 if (th->syn) {
97064 /* We see SYN without ACK. It is attempt of
97065 * simultaneous connect with crossed SYNs.
97066@@ -5609,6 +5610,7 @@ discard:
97067 goto discard;
97068 #endif
97069 }
97070+#endif
97071 /* "fifth, if neither of the SYN or RST bits is set then
97072 * drop the segment and return."
97073 */
97074@@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
97075 goto discard;
97076
97077 if (th->syn) {
97078- if (th->fin)
97079+ if (th->fin || th->urg || th->psh)
97080 goto discard;
97081 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
97082 return 1;
97083diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
97084index 0672139..cacc17d 100644
97085--- a/net/ipv4/tcp_ipv4.c
97086+++ b/net/ipv4/tcp_ipv4.c
97087@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
97088 EXPORT_SYMBOL(sysctl_tcp_low_latency);
97089
97090
97091+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97092+extern int grsec_enable_blackhole;
97093+#endif
97094+
97095 #ifdef CONFIG_TCP_MD5SIG
97096 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
97097 __be32 daddr, __be32 saddr, const struct tcphdr *th);
97098@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
97099 return 0;
97100
97101 reset:
97102+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97103+ if (!grsec_enable_blackhole)
97104+#endif
97105 tcp_v4_send_reset(rsk, skb);
97106 discard:
97107 kfree_skb(skb);
97108@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
97109 TCP_SKB_CB(skb)->sacked = 0;
97110
97111 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
97112- if (!sk)
97113+ if (!sk) {
97114+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97115+ ret = 1;
97116+#endif
97117 goto no_tcp_socket;
97118-
97119+ }
97120 process:
97121- if (sk->sk_state == TCP_TIME_WAIT)
97122+ if (sk->sk_state == TCP_TIME_WAIT) {
97123+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97124+ ret = 2;
97125+#endif
97126 goto do_time_wait;
97127+ }
97128
97129 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
97130 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
97131@@ -2034,6 +2048,10 @@ csum_error:
97132 bad_packet:
97133 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
97134 } else {
97135+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97136+ if (!grsec_enable_blackhole || (ret == 1 &&
97137+ (skb->dev->flags & IFF_LOOPBACK)))
97138+#endif
97139 tcp_v4_send_reset(NULL, skb);
97140 }
97141
97142diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
97143index 97b6841..0893357 100644
97144--- a/net/ipv4/tcp_minisocks.c
97145+++ b/net/ipv4/tcp_minisocks.c
97146@@ -27,6 +27,10 @@
97147 #include <net/inet_common.h>
97148 #include <net/xfrm.h>
97149
97150+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97151+extern int grsec_enable_blackhole;
97152+#endif
97153+
97154 int sysctl_tcp_syncookies __read_mostly = 1;
97155 EXPORT_SYMBOL(sysctl_tcp_syncookies);
97156
97157@@ -708,7 +712,10 @@ embryonic_reset:
97158 * avoid becoming vulnerable to outside attack aiming at
97159 * resetting legit local connections.
97160 */
97161- req->rsk_ops->send_reset(sk, skb);
97162+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97163+ if (!grsec_enable_blackhole)
97164+#endif
97165+ req->rsk_ops->send_reset(sk, skb);
97166 } else if (fastopen) { /* received a valid RST pkt */
97167 reqsk_fastopen_remove(sk, req, true);
97168 tcp_reset(sk);
97169diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
97170index 8b97d71..9d7ccf5 100644
97171--- a/net/ipv4/tcp_probe.c
97172+++ b/net/ipv4/tcp_probe.c
97173@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
97174 if (cnt + width >= len)
97175 break;
97176
97177- if (copy_to_user(buf + cnt, tbuf, width))
97178+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
97179 return -EFAULT;
97180 cnt += width;
97181 }
97182diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
97183index 64f0354..a81b39d 100644
97184--- a/net/ipv4/tcp_timer.c
97185+++ b/net/ipv4/tcp_timer.c
97186@@ -22,6 +22,10 @@
97187 #include <linux/gfp.h>
97188 #include <net/tcp.h>
97189
97190+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97191+extern int grsec_lastack_retries;
97192+#endif
97193+
97194 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
97195 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
97196 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
97197@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
97198 }
97199 }
97200
97201+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97202+ if ((sk->sk_state == TCP_LAST_ACK) &&
97203+ (grsec_lastack_retries > 0) &&
97204+ (grsec_lastack_retries < retry_until))
97205+ retry_until = grsec_lastack_retries;
97206+#endif
97207+
97208 if (retransmits_timed_out(sk, retry_until,
97209 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
97210 /* Has it gone just too far? */
97211diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
97212index a7e4729..2758946 100644
97213--- a/net/ipv4/udp.c
97214+++ b/net/ipv4/udp.c
97215@@ -87,6 +87,7 @@
97216 #include <linux/types.h>
97217 #include <linux/fcntl.h>
97218 #include <linux/module.h>
97219+#include <linux/security.h>
97220 #include <linux/socket.h>
97221 #include <linux/sockios.h>
97222 #include <linux/igmp.h>
97223@@ -113,6 +114,10 @@
97224 #include <net/busy_poll.h>
97225 #include "udp_impl.h"
97226
97227+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97228+extern int grsec_enable_blackhole;
97229+#endif
97230+
97231 struct udp_table udp_table __read_mostly;
97232 EXPORT_SYMBOL(udp_table);
97233
97234@@ -615,6 +620,9 @@ found:
97235 return s;
97236 }
97237
97238+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
97239+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
97240+
97241 /*
97242 * This routine is called by the ICMP module when it gets some
97243 * sort of error condition. If err < 0 then the socket should
97244@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97245 dport = usin->sin_port;
97246 if (dport == 0)
97247 return -EINVAL;
97248+
97249+ err = gr_search_udp_sendmsg(sk, usin);
97250+ if (err)
97251+ return err;
97252 } else {
97253 if (sk->sk_state != TCP_ESTABLISHED)
97254 return -EDESTADDRREQ;
97255+
97256+ err = gr_search_udp_sendmsg(sk, NULL);
97257+ if (err)
97258+ return err;
97259+
97260 daddr = inet->inet_daddr;
97261 dport = inet->inet_dport;
97262 /* Open fast path for connected socket.
97263@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
97264 IS_UDPLITE(sk));
97265 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97266 IS_UDPLITE(sk));
97267- atomic_inc(&sk->sk_drops);
97268+ atomic_inc_unchecked(&sk->sk_drops);
97269 __skb_unlink(skb, rcvq);
97270 __skb_queue_tail(&list_kill, skb);
97271 }
97272@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97273 int is_udplite = IS_UDPLITE(sk);
97274 bool slow;
97275
97276+ /*
97277+ * Check any passed addresses
97278+ */
97279+ if (addr_len)
97280+ *addr_len = sizeof(*sin);
97281+
97282 if (flags & MSG_ERRQUEUE)
97283 return ip_recv_error(sk, msg, len, addr_len);
97284
97285@@ -1243,6 +1266,10 @@ try_again:
97286 if (!skb)
97287 goto out;
97288
97289+ err = gr_search_udp_recvmsg(sk, skb);
97290+ if (err)
97291+ goto out_free;
97292+
97293 ulen = skb->len - sizeof(struct udphdr);
97294 copied = len;
97295 if (copied > ulen)
97296@@ -1276,7 +1303,7 @@ try_again:
97297 if (unlikely(err)) {
97298 trace_kfree_skb(skb, udp_recvmsg);
97299 if (!peeked) {
97300- atomic_inc(&sk->sk_drops);
97301+ atomic_inc_unchecked(&sk->sk_drops);
97302 UDP_INC_STATS_USER(sock_net(sk),
97303 UDP_MIB_INERRORS, is_udplite);
97304 }
97305@@ -1295,7 +1322,6 @@ try_again:
97306 sin->sin_port = udp_hdr(skb)->source;
97307 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97308 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97309- *addr_len = sizeof(*sin);
97310 }
97311 if (inet->cmsg_flags)
97312 ip_cmsg_recv(msg, skb);
97313@@ -1566,7 +1592,7 @@ csum_error:
97314 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
97315 drop:
97316 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
97317- atomic_inc(&sk->sk_drops);
97318+ atomic_inc_unchecked(&sk->sk_drops);
97319 kfree_skb(skb);
97320 return -1;
97321 }
97322@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
97323 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
97324
97325 if (!skb1) {
97326- atomic_inc(&sk->sk_drops);
97327+ atomic_inc_unchecked(&sk->sk_drops);
97328 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
97329 IS_UDPLITE(sk));
97330 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97331@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
97332 goto csum_error;
97333
97334 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
97335+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97336+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
97337+#endif
97338 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
97339
97340 /*
97341@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
97342 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97343 0, sock_i_ino(sp),
97344 atomic_read(&sp->sk_refcnt), sp,
97345- atomic_read(&sp->sk_drops));
97346+ atomic_read_unchecked(&sp->sk_drops));
97347 }
97348
97349 int udp4_seq_show(struct seq_file *seq, void *v)
97350diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
97351index e1a6393..f634ce5 100644
97352--- a/net/ipv4/xfrm4_policy.c
97353+++ b/net/ipv4/xfrm4_policy.c
97354@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
97355 fl4->flowi4_tos = iph->tos;
97356 }
97357
97358-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
97359+static int xfrm4_garbage_collect(struct dst_ops *ops)
97360 {
97361 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
97362
97363- xfrm4_policy_afinfo.garbage_collect(net);
97364+ xfrm_garbage_collect_deferred(net);
97365 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
97366 }
97367
97368@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
97369
97370 static int __net_init xfrm4_net_init(struct net *net)
97371 {
97372- struct ctl_table *table;
97373+ ctl_table_no_const *table = NULL;
97374 struct ctl_table_header *hdr;
97375
97376- table = xfrm4_policy_table;
97377 if (!net_eq(net, &init_net)) {
97378- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97379+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97380 if (!table)
97381 goto err_alloc;
97382
97383 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
97384- }
97385-
97386- hdr = register_net_sysctl(net, "net/ipv4", table);
97387+ hdr = register_net_sysctl(net, "net/ipv4", table);
97388+ } else
97389+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
97390 if (!hdr)
97391 goto err_reg;
97392
97393@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
97394 return 0;
97395
97396 err_reg:
97397- if (!net_eq(net, &init_net))
97398- kfree(table);
97399+ kfree(table);
97400 err_alloc:
97401 return -ENOMEM;
97402 }
97403diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
97404index 4b6b720..272c0c5 100644
97405--- a/net/ipv6/addrconf.c
97406+++ b/net/ipv6/addrconf.c
97407@@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
97408 idx = 0;
97409 head = &net->dev_index_head[h];
97410 rcu_read_lock();
97411- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
97412+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
97413 net->dev_base_seq;
97414 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97415 if (idx < s_idx)
97416@@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
97417 p.iph.ihl = 5;
97418 p.iph.protocol = IPPROTO_IPV6;
97419 p.iph.ttl = 64;
97420- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
97421+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
97422
97423 if (ops->ndo_do_ioctl) {
97424 mm_segment_t oldfs = get_fs();
97425@@ -3962,7 +3962,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
97426 s_ip_idx = ip_idx = cb->args[2];
97427
97428 rcu_read_lock();
97429- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97430+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97431 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
97432 idx = 0;
97433 head = &net->dev_index_head[h];
97434@@ -4569,7 +4569,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
97435 dst_free(&ifp->rt->dst);
97436 break;
97437 }
97438- atomic_inc(&net->ipv6.dev_addr_genid);
97439+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
97440 rt_genid_bump_ipv6(net);
97441 }
97442
97443@@ -4590,7 +4590,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
97444 int *valp = ctl->data;
97445 int val = *valp;
97446 loff_t pos = *ppos;
97447- struct ctl_table lctl;
97448+ ctl_table_no_const lctl;
97449 int ret;
97450
97451 /*
97452@@ -4675,7 +4675,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
97453 int *valp = ctl->data;
97454 int val = *valp;
97455 loff_t pos = *ppos;
97456- struct ctl_table lctl;
97457+ ctl_table_no_const lctl;
97458 int ret;
97459
97460 /*
97461diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
97462index 4fbdb70..f6411f2 100644
97463--- a/net/ipv6/af_inet6.c
97464+++ b/net/ipv6/af_inet6.c
97465@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
97466
97467 net->ipv6.sysctl.bindv6only = 0;
97468 net->ipv6.sysctl.icmpv6_time = 1*HZ;
97469- atomic_set(&net->ipv6.rt_genid, 0);
97470+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
97471
97472 err = ipv6_init_mibs(net);
97473 if (err)
97474diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
97475index 93b1aa3..e902855 100644
97476--- a/net/ipv6/datagram.c
97477+++ b/net/ipv6/datagram.c
97478@@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
97479 0,
97480 sock_i_ino(sp),
97481 atomic_read(&sp->sk_refcnt), sp,
97482- atomic_read(&sp->sk_drops));
97483+ atomic_read_unchecked(&sp->sk_drops));
97484 }
97485diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
97486index eef8d94..cfa1852 100644
97487--- a/net/ipv6/icmp.c
97488+++ b/net/ipv6/icmp.c
97489@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
97490
97491 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
97492 {
97493- struct ctl_table *table;
97494+ ctl_table_no_const *table;
97495
97496 table = kmemdup(ipv6_icmp_table_template,
97497 sizeof(ipv6_icmp_table_template),
97498diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
97499index 8acb286..840dd06 100644
97500--- a/net/ipv6/ip6_gre.c
97501+++ b/net/ipv6/ip6_gre.c
97502@@ -74,7 +74,7 @@ struct ip6gre_net {
97503 struct net_device *fb_tunnel_dev;
97504 };
97505
97506-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
97507+static struct rtnl_link_ops ip6gre_link_ops;
97508 static int ip6gre_tunnel_init(struct net_device *dev);
97509 static void ip6gre_tunnel_setup(struct net_device *dev);
97510 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
97511@@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
97512 }
97513
97514
97515-static struct inet6_protocol ip6gre_protocol __read_mostly = {
97516+static struct inet6_protocol ip6gre_protocol = {
97517 .handler = ip6gre_rcv,
97518 .err_handler = ip6gre_err,
97519 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
97520@@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
97521 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
97522 };
97523
97524-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97525+static struct rtnl_link_ops ip6gre_link_ops = {
97526 .kind = "ip6gre",
97527 .maxtype = IFLA_GRE_MAX,
97528 .policy = ip6gre_policy,
97529@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97530 .fill_info = ip6gre_fill_info,
97531 };
97532
97533-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
97534+static struct rtnl_link_ops ip6gre_tap_ops = {
97535 .kind = "ip6gretap",
97536 .maxtype = IFLA_GRE_MAX,
97537 .policy = ip6gre_policy,
97538diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
97539index 7881965..9cf62c4 100644
97540--- a/net/ipv6/ip6_tunnel.c
97541+++ b/net/ipv6/ip6_tunnel.c
97542@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97543
97544 static int ip6_tnl_dev_init(struct net_device *dev);
97545 static void ip6_tnl_dev_setup(struct net_device *dev);
97546-static struct rtnl_link_ops ip6_link_ops __read_mostly;
97547+static struct rtnl_link_ops ip6_link_ops;
97548
97549 static int ip6_tnl_net_id __read_mostly;
97550 struct ip6_tnl_net {
97551@@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
97552 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
97553 };
97554
97555-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
97556+static struct rtnl_link_ops ip6_link_ops = {
97557 .kind = "ip6tnl",
97558 .maxtype = IFLA_IPTUN_MAX,
97559 .policy = ip6_tnl_policy,
97560diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
97561index 7b42d5e..1eff693 100644
97562--- a/net/ipv6/ip6_vti.c
97563+++ b/net/ipv6/ip6_vti.c
97564@@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97565
97566 static int vti6_dev_init(struct net_device *dev);
97567 static void vti6_dev_setup(struct net_device *dev);
97568-static struct rtnl_link_ops vti6_link_ops __read_mostly;
97569+static struct rtnl_link_ops vti6_link_ops;
97570
97571 static int vti6_net_id __read_mostly;
97572 struct vti6_net {
97573@@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
97574 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
97575 };
97576
97577-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
97578+static struct rtnl_link_ops vti6_link_ops = {
97579 .kind = "vti6",
97580 .maxtype = IFLA_VTI_MAX,
97581 .policy = vti6_policy,
97582diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
97583index 1c6ce31..299e566 100644
97584--- a/net/ipv6/ipv6_sockglue.c
97585+++ b/net/ipv6/ipv6_sockglue.c
97586@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
97587 if (sk->sk_type != SOCK_STREAM)
97588 return -ENOPROTOOPT;
97589
97590- msg.msg_control = optval;
97591+ msg.msg_control = (void __force_kernel *)optval;
97592 msg.msg_controllen = len;
97593 msg.msg_flags = flags;
97594
97595diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
97596index 710238f..0fd1816 100644
97597--- a/net/ipv6/netfilter/ip6_tables.c
97598+++ b/net/ipv6/netfilter/ip6_tables.c
97599@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
97600 #endif
97601
97602 static int get_info(struct net *net, void __user *user,
97603- const int *len, int compat)
97604+ int len, int compat)
97605 {
97606 char name[XT_TABLE_MAXNAMELEN];
97607 struct xt_table *t;
97608 int ret;
97609
97610- if (*len != sizeof(struct ip6t_getinfo)) {
97611- duprintf("length %u != %zu\n", *len,
97612+ if (len != sizeof(struct ip6t_getinfo)) {
97613+ duprintf("length %u != %zu\n", len,
97614 sizeof(struct ip6t_getinfo));
97615 return -EINVAL;
97616 }
97617@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
97618 info.size = private->size;
97619 strcpy(info.name, name);
97620
97621- if (copy_to_user(user, &info, *len) != 0)
97622+ if (copy_to_user(user, &info, len) != 0)
97623 ret = -EFAULT;
97624 else
97625 ret = 0;
97626@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97627
97628 switch (cmd) {
97629 case IP6T_SO_GET_INFO:
97630- ret = get_info(sock_net(sk), user, len, 1);
97631+ ret = get_info(sock_net(sk), user, *len, 1);
97632 break;
97633 case IP6T_SO_GET_ENTRIES:
97634 ret = compat_get_entries(sock_net(sk), user, len);
97635@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97636
97637 switch (cmd) {
97638 case IP6T_SO_GET_INFO:
97639- ret = get_info(sock_net(sk), user, len, 0);
97640+ ret = get_info(sock_net(sk), user, *len, 0);
97641 break;
97642
97643 case IP6T_SO_GET_ENTRIES:
97644diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
97645index 767ab8d..c5ec70a 100644
97646--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
97647+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
97648@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
97649
97650 static int nf_ct_frag6_sysctl_register(struct net *net)
97651 {
97652- struct ctl_table *table;
97653+ ctl_table_no_const *table = NULL;
97654 struct ctl_table_header *hdr;
97655
97656- table = nf_ct_frag6_sysctl_table;
97657 if (!net_eq(net, &init_net)) {
97658- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
97659+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
97660 GFP_KERNEL);
97661 if (table == NULL)
97662 goto err_alloc;
97663@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97664 table[0].data = &net->nf_frag.frags.timeout;
97665 table[1].data = &net->nf_frag.frags.low_thresh;
97666 table[2].data = &net->nf_frag.frags.high_thresh;
97667- }
97668-
97669- hdr = register_net_sysctl(net, "net/netfilter", table);
97670+ hdr = register_net_sysctl(net, "net/netfilter", table);
97671+ } else
97672+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
97673 if (hdr == NULL)
97674 goto err_reg;
97675
97676@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97677 return 0;
97678
97679 err_reg:
97680- if (!net_eq(net, &init_net))
97681- kfree(table);
97682+ kfree(table);
97683 err_alloc:
97684 return -ENOMEM;
97685 }
97686diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
97687index 827f795..7e28e82 100644
97688--- a/net/ipv6/output_core.c
97689+++ b/net/ipv6/output_core.c
97690@@ -9,8 +9,8 @@
97691
97692 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97693 {
97694- static atomic_t ipv6_fragmentation_id;
97695- int old, new;
97696+ static atomic_unchecked_t ipv6_fragmentation_id;
97697+ int id;
97698
97699 #if IS_ENABLED(CONFIG_IPV6)
97700 if (rt && !(rt->dst.flags & DST_NOPEER)) {
97701@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97702 }
97703 }
97704 #endif
97705- do {
97706- old = atomic_read(&ipv6_fragmentation_id);
97707- new = old + 1;
97708- if (!new)
97709- new = 1;
97710- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
97711- fhdr->identification = htonl(new);
97712+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97713+ if (!id)
97714+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97715+ fhdr->identification = htonl(id);
97716 }
97717 EXPORT_SYMBOL(ipv6_select_ident);
97718
97719diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
97720index a83243c..a1ca589 100644
97721--- a/net/ipv6/ping.c
97722+++ b/net/ipv6/ping.c
97723@@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
97724 };
97725 #endif
97726
97727+static struct pingv6_ops real_pingv6_ops = {
97728+ .ipv6_recv_error = ipv6_recv_error,
97729+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
97730+ .icmpv6_err_convert = icmpv6_err_convert,
97731+ .ipv6_icmp_error = ipv6_icmp_error,
97732+ .ipv6_chk_addr = ipv6_chk_addr,
97733+};
97734+
97735+static struct pingv6_ops dummy_pingv6_ops = {
97736+ .ipv6_recv_error = dummy_ipv6_recv_error,
97737+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
97738+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
97739+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
97740+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
97741+};
97742+
97743 int __init pingv6_init(void)
97744 {
97745 #ifdef CONFIG_PROC_FS
97746@@ -253,11 +269,7 @@ int __init pingv6_init(void)
97747 if (ret)
97748 return ret;
97749 #endif
97750- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
97751- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
97752- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
97753- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
97754- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
97755+ pingv6_ops = &real_pingv6_ops;
97756 return inet6_register_protosw(&pingv6_protosw);
97757 }
97758
97759@@ -266,11 +278,7 @@ int __init pingv6_init(void)
97760 */
97761 void pingv6_exit(void)
97762 {
97763- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
97764- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
97765- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
97766- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
97767- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
97768+ pingv6_ops = &dummy_pingv6_ops;
97769 #ifdef CONFIG_PROC_FS
97770 unregister_pernet_subsys(&ping_v6_net_ops);
97771 #endif
97772diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
97773index b6bb87e..06cc9ed 100644
97774--- a/net/ipv6/raw.c
97775+++ b/net/ipv6/raw.c
97776@@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
97777 {
97778 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
97779 skb_checksum_complete(skb)) {
97780- atomic_inc(&sk->sk_drops);
97781+ atomic_inc_unchecked(&sk->sk_drops);
97782 kfree_skb(skb);
97783 return NET_RX_DROP;
97784 }
97785@@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
97786 struct raw6_sock *rp = raw6_sk(sk);
97787
97788 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
97789- atomic_inc(&sk->sk_drops);
97790+ atomic_inc_unchecked(&sk->sk_drops);
97791 kfree_skb(skb);
97792 return NET_RX_DROP;
97793 }
97794@@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
97795
97796 if (inet->hdrincl) {
97797 if (skb_checksum_complete(skb)) {
97798- atomic_inc(&sk->sk_drops);
97799+ atomic_inc_unchecked(&sk->sk_drops);
97800 kfree_skb(skb);
97801 return NET_RX_DROP;
97802 }
97803@@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
97804 if (flags & MSG_OOB)
97805 return -EOPNOTSUPP;
97806
97807+ if (addr_len)
97808+ *addr_len=sizeof(*sin6);
97809+
97810 if (flags & MSG_ERRQUEUE)
97811 return ipv6_recv_error(sk, msg, len, addr_len);
97812
97813@@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
97814 sin6->sin6_flowinfo = 0;
97815 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
97816 IP6CB(skb)->iif);
97817- *addr_len = sizeof(*sin6);
97818 }
97819
97820 sock_recv_ts_and_drops(msg, sk, skb);
97821@@ -606,7 +608,7 @@ out:
97822 return err;
97823 }
97824
97825-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
97826+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
97827 struct flowi6 *fl6, struct dst_entry **dstp,
97828 unsigned int flags)
97829 {
97830@@ -918,12 +920,15 @@ do_confirm:
97831 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
97832 char __user *optval, int optlen)
97833 {
97834+ struct icmp6_filter filter;
97835+
97836 switch (optname) {
97837 case ICMPV6_FILTER:
97838 if (optlen > sizeof(struct icmp6_filter))
97839 optlen = sizeof(struct icmp6_filter);
97840- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
97841+ if (copy_from_user(&filter, optval, optlen))
97842 return -EFAULT;
97843+ raw6_sk(sk)->filter = filter;
97844 return 0;
97845 default:
97846 return -ENOPROTOOPT;
97847@@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
97848 char __user *optval, int __user *optlen)
97849 {
97850 int len;
97851+ struct icmp6_filter filter;
97852
97853 switch (optname) {
97854 case ICMPV6_FILTER:
97855@@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
97856 len = sizeof(struct icmp6_filter);
97857 if (put_user(len, optlen))
97858 return -EFAULT;
97859- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
97860+ filter = raw6_sk(sk)->filter;
97861+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
97862 return -EFAULT;
97863 return 0;
97864 default:
97865diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
97866index cc85a9b..526a133 100644
97867--- a/net/ipv6/reassembly.c
97868+++ b/net/ipv6/reassembly.c
97869@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
97870
97871 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
97872 {
97873- struct ctl_table *table;
97874+ ctl_table_no_const *table = NULL;
97875 struct ctl_table_header *hdr;
97876
97877- table = ip6_frags_ns_ctl_table;
97878 if (!net_eq(net, &init_net)) {
97879- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
97880+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
97881 if (table == NULL)
97882 goto err_alloc;
97883
97884@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
97885 /* Don't export sysctls to unprivileged users */
97886 if (net->user_ns != &init_user_ns)
97887 table[0].procname = NULL;
97888- }
97889+ hdr = register_net_sysctl(net, "net/ipv6", table);
97890+ } else
97891+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
97892
97893- hdr = register_net_sysctl(net, "net/ipv6", table);
97894 if (hdr == NULL)
97895 goto err_reg;
97896
97897@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
97898 return 0;
97899
97900 err_reg:
97901- if (!net_eq(net, &init_net))
97902- kfree(table);
97903+ kfree(table);
97904 err_alloc:
97905 return -ENOMEM;
97906 }
97907diff --git a/net/ipv6/route.c b/net/ipv6/route.c
97908index 4b4944c..4580b91 100644
97909--- a/net/ipv6/route.c
97910+++ b/net/ipv6/route.c
97911@@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
97912
97913 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
97914 {
97915- struct ctl_table *table;
97916+ ctl_table_no_const *table;
97917
97918 table = kmemdup(ipv6_route_table_template,
97919 sizeof(ipv6_route_table_template),
97920diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
97921index d3005b3..b36df4a 100644
97922--- a/net/ipv6/sit.c
97923+++ b/net/ipv6/sit.c
97924@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
97925 static void ipip6_dev_free(struct net_device *dev);
97926 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
97927 __be32 *v4dst);
97928-static struct rtnl_link_ops sit_link_ops __read_mostly;
97929+static struct rtnl_link_ops sit_link_ops;
97930
97931 static int sit_net_id __read_mostly;
97932 struct sit_net {
97933@@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
97934 unregister_netdevice_queue(dev, head);
97935 }
97936
97937-static struct rtnl_link_ops sit_link_ops __read_mostly = {
97938+static struct rtnl_link_ops sit_link_ops = {
97939 .kind = "sit",
97940 .maxtype = IFLA_IPTUN_MAX,
97941 .policy = ipip6_policy,
97942diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
97943index 107b2f1..72741a9 100644
97944--- a/net/ipv6/sysctl_net_ipv6.c
97945+++ b/net/ipv6/sysctl_net_ipv6.c
97946@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
97947
97948 static int __net_init ipv6_sysctl_net_init(struct net *net)
97949 {
97950- struct ctl_table *ipv6_table;
97951+ ctl_table_no_const *ipv6_table;
97952 struct ctl_table *ipv6_route_table;
97953 struct ctl_table *ipv6_icmp_table;
97954 int err;
97955diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
97956index f67033b..6f974fc 100644
97957--- a/net/ipv6/tcp_ipv6.c
97958+++ b/net/ipv6/tcp_ipv6.c
97959@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
97960 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
97961 }
97962
97963+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97964+extern int grsec_enable_blackhole;
97965+#endif
97966+
97967 static void tcp_v6_hash(struct sock *sk)
97968 {
97969 if (sk->sk_state != TCP_CLOSE) {
97970@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
97971 return 0;
97972
97973 reset:
97974+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97975+ if (!grsec_enable_blackhole)
97976+#endif
97977 tcp_v6_send_reset(sk, skb);
97978 discard:
97979 if (opt_skb)
97980@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
97981 TCP_SKB_CB(skb)->sacked = 0;
97982
97983 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
97984- if (!sk)
97985+ if (!sk) {
97986+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97987+ ret = 1;
97988+#endif
97989 goto no_tcp_socket;
97990+ }
97991
97992 process:
97993- if (sk->sk_state == TCP_TIME_WAIT)
97994+ if (sk->sk_state == TCP_TIME_WAIT) {
97995+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97996+ ret = 2;
97997+#endif
97998 goto do_time_wait;
97999+ }
98000
98001 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
98002 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98003@@ -1536,6 +1551,10 @@ csum_error:
98004 bad_packet:
98005 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98006 } else {
98007+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98008+ if (!grsec_enable_blackhole || (ret == 1 &&
98009+ (skb->dev->flags & IFF_LOOPBACK)))
98010+#endif
98011 tcp_v6_send_reset(NULL, skb);
98012 }
98013
98014diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
98015index 089c741..cfee117 100644
98016--- a/net/ipv6/udp.c
98017+++ b/net/ipv6/udp.c
98018@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
98019 udp_ipv6_hash_secret + net_hash_mix(net));
98020 }
98021
98022+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98023+extern int grsec_enable_blackhole;
98024+#endif
98025+
98026 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
98027 {
98028 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
98029@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98030 int is_udp4;
98031 bool slow;
98032
98033+ if (addr_len)
98034+ *addr_len = sizeof(struct sockaddr_in6);
98035+
98036 if (flags & MSG_ERRQUEUE)
98037 return ipv6_recv_error(sk, msg, len, addr_len);
98038
98039@@ -435,7 +442,7 @@ try_again:
98040 if (unlikely(err)) {
98041 trace_kfree_skb(skb, udpv6_recvmsg);
98042 if (!peeked) {
98043- atomic_inc(&sk->sk_drops);
98044+ atomic_inc_unchecked(&sk->sk_drops);
98045 if (is_udp4)
98046 UDP_INC_STATS_USER(sock_net(sk),
98047 UDP_MIB_INERRORS,
98048@@ -477,7 +484,7 @@ try_again:
98049 ipv6_iface_scope_id(&sin6->sin6_addr,
98050 IP6CB(skb)->iif);
98051 }
98052- *addr_len = sizeof(*sin6);
98053+
98054 }
98055 if (is_udp4) {
98056 if (inet->cmsg_flags)
98057@@ -685,7 +692,7 @@ csum_error:
98058 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98059 drop:
98060 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98061- atomic_inc(&sk->sk_drops);
98062+ atomic_inc_unchecked(&sk->sk_drops);
98063 kfree_skb(skb);
98064 return -1;
98065 }
98066@@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98067 if (likely(skb1 == NULL))
98068 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98069 if (!skb1) {
98070- atomic_inc(&sk->sk_drops);
98071+ atomic_inc_unchecked(&sk->sk_drops);
98072 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98073 IS_UDPLITE(sk));
98074 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98075@@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98076 goto csum_error;
98077
98078 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98079+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98080+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98081+#endif
98082 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
98083
98084 kfree_skb(skb);
98085diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
98086index 5f8e128..865d38e 100644
98087--- a/net/ipv6/xfrm6_policy.c
98088+++ b/net/ipv6/xfrm6_policy.c
98089@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
98090 }
98091 }
98092
98093-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
98094+static int xfrm6_garbage_collect(struct dst_ops *ops)
98095 {
98096 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
98097
98098- xfrm6_policy_afinfo.garbage_collect(net);
98099+ xfrm_garbage_collect_deferred(net);
98100 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
98101 }
98102
98103@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
98104
98105 static int __net_init xfrm6_net_init(struct net *net)
98106 {
98107- struct ctl_table *table;
98108+ ctl_table_no_const *table = NULL;
98109 struct ctl_table_header *hdr;
98110
98111- table = xfrm6_policy_table;
98112 if (!net_eq(net, &init_net)) {
98113- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98114+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98115 if (!table)
98116 goto err_alloc;
98117
98118 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
98119- }
98120+ hdr = register_net_sysctl(net, "net/ipv6", table);
98121+ } else
98122+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
98123
98124- hdr = register_net_sysctl(net, "net/ipv6", table);
98125 if (!hdr)
98126 goto err_reg;
98127
98128@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
98129 return 0;
98130
98131 err_reg:
98132- if (!net_eq(net, &init_net))
98133- kfree(table);
98134+ kfree(table);
98135 err_alloc:
98136 return -ENOMEM;
98137 }
98138diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
98139index 41ac7938..75e3bb1 100644
98140--- a/net/irda/ircomm/ircomm_tty.c
98141+++ b/net/irda/ircomm/ircomm_tty.c
98142@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98143 add_wait_queue(&port->open_wait, &wait);
98144
98145 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
98146- __FILE__, __LINE__, tty->driver->name, port->count);
98147+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98148
98149 spin_lock_irqsave(&port->lock, flags);
98150 if (!tty_hung_up_p(filp))
98151- port->count--;
98152+ atomic_dec(&port->count);
98153 port->blocked_open++;
98154 spin_unlock_irqrestore(&port->lock, flags);
98155
98156@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98157 }
98158
98159 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
98160- __FILE__, __LINE__, tty->driver->name, port->count);
98161+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98162
98163 schedule();
98164 }
98165@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98166
98167 spin_lock_irqsave(&port->lock, flags);
98168 if (!tty_hung_up_p(filp))
98169- port->count++;
98170+ atomic_inc(&port->count);
98171 port->blocked_open--;
98172 spin_unlock_irqrestore(&port->lock, flags);
98173
98174 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
98175- __FILE__, __LINE__, tty->driver->name, port->count);
98176+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98177
98178 if (!retval)
98179 port->flags |= ASYNC_NORMAL_ACTIVE;
98180@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
98181
98182 /* ++ is not atomic, so this should be protected - Jean II */
98183 spin_lock_irqsave(&self->port.lock, flags);
98184- self->port.count++;
98185+ atomic_inc(&self->port.count);
98186 spin_unlock_irqrestore(&self->port.lock, flags);
98187 tty_port_tty_set(&self->port, tty);
98188
98189 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
98190- self->line, self->port.count);
98191+ self->line, atomic_read(&self->port.count));
98192
98193 /* Not really used by us, but lets do it anyway */
98194 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
98195@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
98196 tty_kref_put(port->tty);
98197 }
98198 port->tty = NULL;
98199- port->count = 0;
98200+ atomic_set(&port->count, 0);
98201 spin_unlock_irqrestore(&port->lock, flags);
98202
98203 wake_up_interruptible(&port->open_wait);
98204@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
98205 seq_putc(m, '\n');
98206
98207 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
98208- seq_printf(m, "Open count: %d\n", self->port.count);
98209+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
98210 seq_printf(m, "Max data size: %d\n", self->max_data_size);
98211 seq_printf(m, "Max header size: %d\n", self->max_header_size);
98212
98213diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
98214index c4b7218..3e83259 100644
98215--- a/net/iucv/af_iucv.c
98216+++ b/net/iucv/af_iucv.c
98217@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
98218
98219 write_lock_bh(&iucv_sk_list.lock);
98220
98221- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
98222+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98223 while (__iucv_get_sock_by_name(name)) {
98224 sprintf(name, "%08x",
98225- atomic_inc_return(&iucv_sk_list.autobind_name));
98226+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98227 }
98228
98229 write_unlock_bh(&iucv_sk_list.lock);
98230diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
98231index cd5b8ec..f205e6b 100644
98232--- a/net/iucv/iucv.c
98233+++ b/net/iucv/iucv.c
98234@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
98235 return NOTIFY_OK;
98236 }
98237
98238-static struct notifier_block __refdata iucv_cpu_notifier = {
98239+static struct notifier_block iucv_cpu_notifier = {
98240 .notifier_call = iucv_cpu_notify,
98241 };
98242
98243diff --git a/net/key/af_key.c b/net/key/af_key.c
98244index 545f047..9757a9d 100644
98245--- a/net/key/af_key.c
98246+++ b/net/key/af_key.c
98247@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
98248 static u32 get_acqseq(void)
98249 {
98250 u32 res;
98251- static atomic_t acqseq;
98252+ static atomic_unchecked_t acqseq;
98253
98254 do {
98255- res = atomic_inc_return(&acqseq);
98256+ res = atomic_inc_return_unchecked(&acqseq);
98257 } while (!res);
98258 return res;
98259 }
98260diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
98261index da1a1ce..571db8d 100644
98262--- a/net/l2tp/l2tp_ip.c
98263+++ b/net/l2tp/l2tp_ip.c
98264@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98265 if (flags & MSG_OOB)
98266 goto out;
98267
98268+ if (addr_len)
98269+ *addr_len = sizeof(*sin);
98270+
98271 skb = skb_recv_datagram(sk, flags, noblock, &err);
98272 if (!skb)
98273 goto out;
98274@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98275 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98276 sin->sin_port = 0;
98277 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98278- *addr_len = sizeof(*sin);
98279 }
98280 if (inet->cmsg_flags)
98281 ip_cmsg_recv(msg, skb);
98282diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
98283index 364ce0c..3ebb5a4 100644
98284--- a/net/mac80211/cfg.c
98285+++ b/net/mac80211/cfg.c
98286@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
98287 ret = ieee80211_vif_use_channel(sdata, chandef,
98288 IEEE80211_CHANCTX_EXCLUSIVE);
98289 }
98290- } else if (local->open_count == local->monitors) {
98291+ } else if (local_read(&local->open_count) == local->monitors) {
98292 local->_oper_chandef = *chandef;
98293 ieee80211_hw_config(local, 0);
98294 }
98295@@ -3308,7 +3308,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
98296 else
98297 local->probe_req_reg--;
98298
98299- if (!local->open_count)
98300+ if (!local_read(&local->open_count))
98301 break;
98302
98303 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
98304@@ -3771,8 +3771,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
98305 if (chanctx_conf) {
98306 *chandef = chanctx_conf->def;
98307 ret = 0;
98308- } else if (local->open_count > 0 &&
98309- local->open_count == local->monitors &&
98310+ } else if (local_read(&local->open_count) > 0 &&
98311+ local_read(&local->open_count) == local->monitors &&
98312 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
98313 if (local->use_chanctx)
98314 *chandef = local->monitor_chandef;
98315diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
98316index 4aea4e7..9e698d1 100644
98317--- a/net/mac80211/ieee80211_i.h
98318+++ b/net/mac80211/ieee80211_i.h
98319@@ -28,6 +28,7 @@
98320 #include <net/ieee80211_radiotap.h>
98321 #include <net/cfg80211.h>
98322 #include <net/mac80211.h>
98323+#include <asm/local.h>
98324 #include "key.h"
98325 #include "sta_info.h"
98326 #include "debug.h"
98327@@ -961,7 +962,7 @@ struct ieee80211_local {
98328 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
98329 spinlock_t queue_stop_reason_lock;
98330
98331- int open_count;
98332+ local_t open_count;
98333 int monitors, cooked_mntrs;
98334 /* number of interfaces with corresponding FIF_ flags */
98335 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
98336diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
98337index a075791..1d0027f 100644
98338--- a/net/mac80211/iface.c
98339+++ b/net/mac80211/iface.c
98340@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98341 break;
98342 }
98343
98344- if (local->open_count == 0) {
98345+ if (local_read(&local->open_count) == 0) {
98346 res = drv_start(local);
98347 if (res)
98348 goto err_del_bss;
98349@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98350 res = drv_add_interface(local, sdata);
98351 if (res)
98352 goto err_stop;
98353- } else if (local->monitors == 0 && local->open_count == 0) {
98354+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
98355 res = ieee80211_add_virtual_monitor(local);
98356 if (res)
98357 goto err_stop;
98358@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98359 atomic_inc(&local->iff_promiscs);
98360
98361 if (coming_up)
98362- local->open_count++;
98363+ local_inc(&local->open_count);
98364
98365 if (hw_reconf_flags)
98366 ieee80211_hw_config(local, hw_reconf_flags);
98367@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98368 err_del_interface:
98369 drv_remove_interface(local, sdata);
98370 err_stop:
98371- if (!local->open_count)
98372+ if (!local_read(&local->open_count))
98373 drv_stop(local);
98374 err_del_bss:
98375 sdata->bss = NULL;
98376@@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98377 }
98378
98379 if (going_down)
98380- local->open_count--;
98381+ local_dec(&local->open_count);
98382
98383 switch (sdata->vif.type) {
98384 case NL80211_IFTYPE_AP_VLAN:
98385@@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98386 }
98387 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
98388
98389- if (local->open_count == 0)
98390+ if (local_read(&local->open_count) == 0)
98391 ieee80211_clear_tx_pending(local);
98392
98393 /*
98394@@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98395
98396 ieee80211_recalc_ps(local, -1);
98397
98398- if (local->open_count == 0) {
98399+ if (local_read(&local->open_count) == 0) {
98400 ieee80211_stop_device(local);
98401
98402 /* no reconfiguring after stop! */
98403@@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98404 ieee80211_configure_filter(local);
98405 ieee80211_hw_config(local, hw_reconf_flags);
98406
98407- if (local->monitors == local->open_count)
98408+ if (local->monitors == local_read(&local->open_count))
98409 ieee80211_add_virtual_monitor(local);
98410 }
98411
98412diff --git a/net/mac80211/main.c b/net/mac80211/main.c
98413index 7d1c3ac..b62dd29 100644
98414--- a/net/mac80211/main.c
98415+++ b/net/mac80211/main.c
98416@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
98417 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
98418 IEEE80211_CONF_CHANGE_POWER);
98419
98420- if (changed && local->open_count) {
98421+ if (changed && local_read(&local->open_count)) {
98422 ret = drv_config(local, changed);
98423 /*
98424 * Goal:
98425diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
98426index 3401262..d5cd68d 100644
98427--- a/net/mac80211/pm.c
98428+++ b/net/mac80211/pm.c
98429@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98430 struct ieee80211_sub_if_data *sdata;
98431 struct sta_info *sta;
98432
98433- if (!local->open_count)
98434+ if (!local_read(&local->open_count))
98435 goto suspend;
98436
98437 ieee80211_scan_cancel(local);
98438@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98439 cancel_work_sync(&local->dynamic_ps_enable_work);
98440 del_timer_sync(&local->dynamic_ps_timer);
98441
98442- local->wowlan = wowlan && local->open_count;
98443+ local->wowlan = wowlan && local_read(&local->open_count);
98444 if (local->wowlan) {
98445 int err = drv_suspend(local, wowlan);
98446 if (err < 0) {
98447@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98448 WARN_ON(!list_empty(&local->chanctx_list));
98449
98450 /* stop hardware - this must stop RX */
98451- if (local->open_count)
98452+ if (local_read(&local->open_count))
98453 ieee80211_stop_device(local);
98454
98455 suspend:
98456diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
98457index 22b223f..ab70070 100644
98458--- a/net/mac80211/rate.c
98459+++ b/net/mac80211/rate.c
98460@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
98461
98462 ASSERT_RTNL();
98463
98464- if (local->open_count)
98465+ if (local_read(&local->open_count))
98466 return -EBUSY;
98467
98468 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
98469diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
98470index 6ff1346..936ca9a 100644
98471--- a/net/mac80211/rc80211_pid_debugfs.c
98472+++ b/net/mac80211/rc80211_pid_debugfs.c
98473@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
98474
98475 spin_unlock_irqrestore(&events->lock, status);
98476
98477- if (copy_to_user(buf, pb, p))
98478+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
98479 return -EFAULT;
98480
98481 return p;
98482diff --git a/net/mac80211/util.c b/net/mac80211/util.c
98483index 9f9b9bd..d6fcf59 100644
98484--- a/net/mac80211/util.c
98485+++ b/net/mac80211/util.c
98486@@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98487 }
98488 #endif
98489 /* everything else happens only if HW was up & running */
98490- if (!local->open_count)
98491+ if (!local_read(&local->open_count))
98492 goto wake_up;
98493
98494 /*
98495@@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98496 local->in_reconfig = false;
98497 barrier();
98498
98499- if (local->monitors == local->open_count && local->monitors > 0)
98500+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
98501 ieee80211_add_virtual_monitor(local);
98502
98503 /*
98504diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
98505index c3398cd..98ad3b4 100644
98506--- a/net/netfilter/Kconfig
98507+++ b/net/netfilter/Kconfig
98508@@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
98509
98510 To compile it as a module, choose M here. If unsure, say N.
98511
98512+config NETFILTER_XT_MATCH_GRADM
98513+ tristate '"gradm" match support'
98514+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
98515+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
98516+ ---help---
98517+ The gradm match allows to match on grsecurity RBAC being enabled.
98518+ It is useful when iptables rules are applied early on bootup to
98519+ prevent connections to the machine (except from a trusted host)
98520+ while the RBAC system is disabled.
98521+
98522 config NETFILTER_XT_MATCH_HASHLIMIT
98523 tristate '"hashlimit" match support'
98524 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
98525diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
98526index 394483b..ed51f2d 100644
98527--- a/net/netfilter/Makefile
98528+++ b/net/netfilter/Makefile
98529@@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
98530 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
98531 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
98532 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
98533+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
98534 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
98535 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
98536 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
98537diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
98538index bac7e01..1d7a31a 100644
98539--- a/net/netfilter/ipset/ip_set_core.c
98540+++ b/net/netfilter/ipset/ip_set_core.c
98541@@ -1950,7 +1950,7 @@ done:
98542 return ret;
98543 }
98544
98545-static struct nf_sockopt_ops so_set __read_mostly = {
98546+static struct nf_sockopt_ops so_set = {
98547 .pf = PF_INET,
98548 .get_optmin = SO_IP_SET,
98549 .get_optmax = SO_IP_SET + 1,
98550diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
98551index 4c8e5c0..5a79b4d 100644
98552--- a/net/netfilter/ipvs/ip_vs_conn.c
98553+++ b/net/netfilter/ipvs/ip_vs_conn.c
98554@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
98555 /* Increase the refcnt counter of the dest */
98556 ip_vs_dest_hold(dest);
98557
98558- conn_flags = atomic_read(&dest->conn_flags);
98559+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
98560 if (cp->protocol != IPPROTO_UDP)
98561 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
98562 flags = cp->flags;
98563@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
98564
98565 cp->control = NULL;
98566 atomic_set(&cp->n_control, 0);
98567- atomic_set(&cp->in_pkts, 0);
98568+ atomic_set_unchecked(&cp->in_pkts, 0);
98569
98570 cp->packet_xmit = NULL;
98571 cp->app = NULL;
98572@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
98573
98574 /* Don't drop the entry if its number of incoming packets is not
98575 located in [0, 8] */
98576- i = atomic_read(&cp->in_pkts);
98577+ i = atomic_read_unchecked(&cp->in_pkts);
98578 if (i > 8 || i < 0) return 0;
98579
98580 if (!todrop_rate[i]) return 0;
98581diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
98582index 4f26ee4..6a9d7c3 100644
98583--- a/net/netfilter/ipvs/ip_vs_core.c
98584+++ b/net/netfilter/ipvs/ip_vs_core.c
98585@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
98586 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
98587 /* do not touch skb anymore */
98588
98589- atomic_inc(&cp->in_pkts);
98590+ atomic_inc_unchecked(&cp->in_pkts);
98591 ip_vs_conn_put(cp);
98592 return ret;
98593 }
98594@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
98595 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
98596 pkts = sysctl_sync_threshold(ipvs);
98597 else
98598- pkts = atomic_add_return(1, &cp->in_pkts);
98599+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98600
98601 if (ipvs->sync_state & IP_VS_STATE_MASTER)
98602 ip_vs_sync_conn(net, cp, pkts);
98603diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
98604index 35be035..dad174b 100644
98605--- a/net/netfilter/ipvs/ip_vs_ctl.c
98606+++ b/net/netfilter/ipvs/ip_vs_ctl.c
98607@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
98608 */
98609 ip_vs_rs_hash(ipvs, dest);
98610 }
98611- atomic_set(&dest->conn_flags, conn_flags);
98612+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
98613
98614 /* bind the service */
98615 old_svc = rcu_dereference_protected(dest->svc, 1);
98616@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
98617 * align with netns init in ip_vs_control_net_init()
98618 */
98619
98620-static struct ctl_table vs_vars[] = {
98621+static ctl_table_no_const vs_vars[] __read_only = {
98622 {
98623 .procname = "amemthresh",
98624 .maxlen = sizeof(int),
98625@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98626 " %-7s %-6d %-10d %-10d\n",
98627 &dest->addr.in6,
98628 ntohs(dest->port),
98629- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98630+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98631 atomic_read(&dest->weight),
98632 atomic_read(&dest->activeconns),
98633 atomic_read(&dest->inactconns));
98634@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98635 "%-7s %-6d %-10d %-10d\n",
98636 ntohl(dest->addr.ip),
98637 ntohs(dest->port),
98638- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98639+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98640 atomic_read(&dest->weight),
98641 atomic_read(&dest->activeconns),
98642 atomic_read(&dest->inactconns));
98643@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
98644
98645 entry.addr = dest->addr.ip;
98646 entry.port = dest->port;
98647- entry.conn_flags = atomic_read(&dest->conn_flags);
98648+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
98649 entry.weight = atomic_read(&dest->weight);
98650 entry.u_threshold = dest->u_threshold;
98651 entry.l_threshold = dest->l_threshold;
98652@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
98653 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
98654 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
98655 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
98656- (atomic_read(&dest->conn_flags) &
98657+ (atomic_read_unchecked(&dest->conn_flags) &
98658 IP_VS_CONN_F_FWD_MASK)) ||
98659 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
98660 atomic_read(&dest->weight)) ||
98661@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
98662 {
98663 int idx;
98664 struct netns_ipvs *ipvs = net_ipvs(net);
98665- struct ctl_table *tbl;
98666+ ctl_table_no_const *tbl;
98667
98668 atomic_set(&ipvs->dropentry, 0);
98669 spin_lock_init(&ipvs->dropentry_lock);
98670diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
98671index ca056a3..9cf01ef 100644
98672--- a/net/netfilter/ipvs/ip_vs_lblc.c
98673+++ b/net/netfilter/ipvs/ip_vs_lblc.c
98674@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
98675 * IPVS LBLC sysctl table
98676 */
98677 #ifdef CONFIG_SYSCTL
98678-static struct ctl_table vs_vars_table[] = {
98679+static ctl_table_no_const vs_vars_table[] __read_only = {
98680 {
98681 .procname = "lblc_expiration",
98682 .data = NULL,
98683diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
98684index 3f21a2f..a112e85 100644
98685--- a/net/netfilter/ipvs/ip_vs_lblcr.c
98686+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
98687@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
98688 * IPVS LBLCR sysctl table
98689 */
98690
98691-static struct ctl_table vs_vars_table[] = {
98692+static ctl_table_no_const vs_vars_table[] __read_only = {
98693 {
98694 .procname = "lblcr_expiration",
98695 .data = NULL,
98696diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
98697index f63c238..1b87f8a 100644
98698--- a/net/netfilter/ipvs/ip_vs_sync.c
98699+++ b/net/netfilter/ipvs/ip_vs_sync.c
98700@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
98701 cp = cp->control;
98702 if (cp) {
98703 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98704- pkts = atomic_add_return(1, &cp->in_pkts);
98705+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98706 else
98707 pkts = sysctl_sync_threshold(ipvs);
98708 ip_vs_sync_conn(net, cp->control, pkts);
98709@@ -771,7 +771,7 @@ control:
98710 if (!cp)
98711 return;
98712 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98713- pkts = atomic_add_return(1, &cp->in_pkts);
98714+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98715 else
98716 pkts = sysctl_sync_threshold(ipvs);
98717 goto sloop;
98718@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
98719
98720 if (opt)
98721 memcpy(&cp->in_seq, opt, sizeof(*opt));
98722- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98723+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98724 cp->state = state;
98725 cp->old_state = cp->state;
98726 /*
98727diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
98728index c47444e..b0961c6 100644
98729--- a/net/netfilter/ipvs/ip_vs_xmit.c
98730+++ b/net/netfilter/ipvs/ip_vs_xmit.c
98731@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
98732 else
98733 rc = NF_ACCEPT;
98734 /* do not touch skb anymore */
98735- atomic_inc(&cp->in_pkts);
98736+ atomic_inc_unchecked(&cp->in_pkts);
98737 goto out;
98738 }
98739
98740@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
98741 else
98742 rc = NF_ACCEPT;
98743 /* do not touch skb anymore */
98744- atomic_inc(&cp->in_pkts);
98745+ atomic_inc_unchecked(&cp->in_pkts);
98746 goto out;
98747 }
98748
98749diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
98750index a4b5e2a..13b1de3 100644
98751--- a/net/netfilter/nf_conntrack_acct.c
98752+++ b/net/netfilter/nf_conntrack_acct.c
98753@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
98754 #ifdef CONFIG_SYSCTL
98755 static int nf_conntrack_acct_init_sysctl(struct net *net)
98756 {
98757- struct ctl_table *table;
98758+ ctl_table_no_const *table;
98759
98760 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
98761 GFP_KERNEL);
98762diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
98763index 43549eb..0bbeace 100644
98764--- a/net/netfilter/nf_conntrack_core.c
98765+++ b/net/netfilter/nf_conntrack_core.c
98766@@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
98767 #define DYING_NULLS_VAL ((1<<30)+1)
98768 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
98769
98770+#ifdef CONFIG_GRKERNSEC_HIDESYM
98771+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
98772+#endif
98773+
98774 int nf_conntrack_init_net(struct net *net)
98775 {
98776 int ret;
98777@@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
98778 goto err_stat;
98779 }
98780
98781+#ifdef CONFIG_GRKERNSEC_HIDESYM
98782+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
98783+#else
98784 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
98785+#endif
98786 if (!net->ct.slabname) {
98787 ret = -ENOMEM;
98788 goto err_slabname;
98789diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
98790index 1df1761..ce8b88a 100644
98791--- a/net/netfilter/nf_conntrack_ecache.c
98792+++ b/net/netfilter/nf_conntrack_ecache.c
98793@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
98794 #ifdef CONFIG_SYSCTL
98795 static int nf_conntrack_event_init_sysctl(struct net *net)
98796 {
98797- struct ctl_table *table;
98798+ ctl_table_no_const *table;
98799
98800 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
98801 GFP_KERNEL);
98802diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
98803index 974a2a4..52cc6ff 100644
98804--- a/net/netfilter/nf_conntrack_helper.c
98805+++ b/net/netfilter/nf_conntrack_helper.c
98806@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
98807
98808 static int nf_conntrack_helper_init_sysctl(struct net *net)
98809 {
98810- struct ctl_table *table;
98811+ ctl_table_no_const *table;
98812
98813 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
98814 GFP_KERNEL);
98815diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
98816index ce30041..3861b5d 100644
98817--- a/net/netfilter/nf_conntrack_proto.c
98818+++ b/net/netfilter/nf_conntrack_proto.c
98819@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
98820
98821 static void
98822 nf_ct_unregister_sysctl(struct ctl_table_header **header,
98823- struct ctl_table **table,
98824+ ctl_table_no_const **table,
98825 unsigned int users)
98826 {
98827 if (users > 0)
98828diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
98829index a99b6c3..cb372f9 100644
98830--- a/net/netfilter/nf_conntrack_proto_dccp.c
98831+++ b/net/netfilter/nf_conntrack_proto_dccp.c
98832@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
98833 const char *msg;
98834 u_int8_t state;
98835
98836- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98837+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98838 BUG_ON(dh == NULL);
98839
98840 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
98841@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
98842 out_invalid:
98843 if (LOG_INVALID(net, IPPROTO_DCCP))
98844 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
98845- NULL, msg);
98846+ NULL, "%s", msg);
98847 return false;
98848 }
98849
98850@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
98851 u_int8_t type, old_state, new_state;
98852 enum ct_dccp_roles role;
98853
98854- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98855+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98856 BUG_ON(dh == NULL);
98857 type = dh->dccph_type;
98858
98859@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
98860 unsigned int cscov;
98861 const char *msg;
98862
98863- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98864+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98865 if (dh == NULL) {
98866 msg = "nf_ct_dccp: short packet ";
98867 goto out_invalid;
98868@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
98869
98870 out_invalid:
98871 if (LOG_INVALID(net, IPPROTO_DCCP))
98872- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
98873+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
98874 return -NF_ACCEPT;
98875 }
98876
98877diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
98878index f641751..d3c5b51 100644
98879--- a/net/netfilter/nf_conntrack_standalone.c
98880+++ b/net/netfilter/nf_conntrack_standalone.c
98881@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
98882
98883 static int nf_conntrack_standalone_init_sysctl(struct net *net)
98884 {
98885- struct ctl_table *table;
98886+ ctl_table_no_const *table;
98887
98888 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
98889 GFP_KERNEL);
98890diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
98891index 7a394df..bd91a8a 100644
98892--- a/net/netfilter/nf_conntrack_timestamp.c
98893+++ b/net/netfilter/nf_conntrack_timestamp.c
98894@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
98895 #ifdef CONFIG_SYSCTL
98896 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
98897 {
98898- struct ctl_table *table;
98899+ ctl_table_no_const *table;
98900
98901 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
98902 GFP_KERNEL);
98903diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
98904index 85296d4..8becdec 100644
98905--- a/net/netfilter/nf_log.c
98906+++ b/net/netfilter/nf_log.c
98907@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
98908
98909 #ifdef CONFIG_SYSCTL
98910 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
98911-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
98912+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
98913
98914 static int nf_log_proc_dostring(struct ctl_table *table, int write,
98915 void __user *buffer, size_t *lenp, loff_t *ppos)
98916@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
98917 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
98918 mutex_unlock(&nf_log_mutex);
98919 } else {
98920+ ctl_table_no_const nf_log_table = *table;
98921+
98922 mutex_lock(&nf_log_mutex);
98923 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
98924 lockdep_is_held(&nf_log_mutex));
98925 if (!logger)
98926- table->data = "NONE";
98927+ nf_log_table.data = "NONE";
98928 else
98929- table->data = logger->name;
98930- r = proc_dostring(table, write, buffer, lenp, ppos);
98931+ nf_log_table.data = logger->name;
98932+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
98933 mutex_unlock(&nf_log_mutex);
98934 }
98935
98936diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
98937index f042ae5..30ea486 100644
98938--- a/net/netfilter/nf_sockopt.c
98939+++ b/net/netfilter/nf_sockopt.c
98940@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
98941 }
98942 }
98943
98944- list_add(&reg->list, &nf_sockopts);
98945+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
98946 out:
98947 mutex_unlock(&nf_sockopt_mutex);
98948 return ret;
98949@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
98950 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
98951 {
98952 mutex_lock(&nf_sockopt_mutex);
98953- list_del(&reg->list);
98954+ pax_list_del((struct list_head *)&reg->list);
98955 mutex_unlock(&nf_sockopt_mutex);
98956 }
98957 EXPORT_SYMBOL(nf_unregister_sockopt);
98958diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
98959index a155d19..726b0f2 100644
98960--- a/net/netfilter/nfnetlink_log.c
98961+++ b/net/netfilter/nfnetlink_log.c
98962@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
98963 struct nfnl_log_net {
98964 spinlock_t instances_lock;
98965 struct hlist_head instance_table[INSTANCE_BUCKETS];
98966- atomic_t global_seq;
98967+ atomic_unchecked_t global_seq;
98968 };
98969
98970 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
98971@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
98972 /* global sequence number */
98973 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
98974 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
98975- htonl(atomic_inc_return(&log->global_seq))))
98976+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
98977 goto nla_put_failure;
98978
98979 if (data_len) {
98980diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
98981index da0c1f4..f79737a 100644
98982--- a/net/netfilter/nft_compat.c
98983+++ b/net/netfilter/nft_compat.c
98984@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
98985 /* We want to reuse existing compat_to_user */
98986 old_fs = get_fs();
98987 set_fs(KERNEL_DS);
98988- t->compat_to_user(out, in);
98989+ t->compat_to_user((void __force_user *)out, in);
98990 set_fs(old_fs);
98991 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
98992 kfree(out);
98993@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
98994 /* We want to reuse existing compat_to_user */
98995 old_fs = get_fs();
98996 set_fs(KERNEL_DS);
98997- m->compat_to_user(out, in);
98998+ m->compat_to_user((void __force_user *)out, in);
98999 set_fs(old_fs);
99000 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
99001 kfree(out);
99002diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
99003new file mode 100644
99004index 0000000..c566332
99005--- /dev/null
99006+++ b/net/netfilter/xt_gradm.c
99007@@ -0,0 +1,51 @@
99008+/*
99009+ * gradm match for netfilter
99010